LoginSignup
0
0

More than 3 years have passed since last update.

kintone REST API client for Ruby を使ってみる

Last updated at Posted at 2019-11-18

kintoneのSDKを使って、コマンドラインからkintoneにアクセスしてレコードを取ってきたりする時のメモです。

はじめに

kintoneのAPIにアクセスする Ruby用のSDK [kintone REST API client for Ruby]https://github.com/jue58/kintone を使ってみたときのメモです。

動作環境

  • mac OS10.14.6
  • Ruby 2.6.3
  • Homebrew 2.1.16
  • rbenv 1.1.2
  • Pry version 0.12.2 on Ruby 2.6.3

環境設定メモ

上記環境を構築する際のメモです。

rbenv チートシート

  • rbenv --help 全体ヘルプ表示
  • rbenv versions rbenvでinstall済みのRubyバージョンの一覧
  • rbenv install --help installコマンドのヘルプ
  • rbenv install -list rbenvでinstallできるRubyの一覧
  • rbenv rehash インストールしたRubyやGemの反映

[kintone REST API client for Ruby]インストール

Bundlerインストール

gem install bundler

bundle init

Gemfileの作成

bundle init

Gemfile 編集

gem 'kintone' 追記

インストール

bundle install

gem & bundler チートシート

  • gem --help ヘルプ
  • gem list --local ローカルにインストールされたGem一覧
  • gem help install インストールコマンドのヘルプ
  • bundle init
  • bundle install
  • rbenv rehash

pry 対話シェルで実行

pry インストール

  • gem 'pry', '~> 0.12.2' Gemfileに追記
  • bundle install
  • rbenv rehash
  • pry -v

pryチートシート

  • pry pry実行
  • .ls シェルのlsコマンド実行
  • ls 現在のスコープ内の変数とメソッドの一覧

SDK実行

Application information

$ pry
[1] pry(main)> require 'kintone'
=> true
[2] pry(main)> domain = '<domain>.cybozu.com'
=> "<domain>.cybozu.com"
[3] pry(main)> uid = '<user id>'
=> "<user id>"
[4] pry(main)> pass = '<password>'
=> "<password>"
[5] pry(main)> api = Kintone::Api.new(domain, uid, pass)
=> #<Kintone::Api:0x00007fce67a24d78
 @connection=
  #<Faraday::Connection:0x00007fce67a24be8
   @builder=
    #<Faraday::RackBuilder:0x00007fce67a24738
     @handlers=
      [Faraday::Request::UrlEncoded, 
()
[6] pry(main)> api.app.get(1)
=> {"appId"=>"1",
 "code"=>"",
 "name"=>"顧客管理ハンズオン",
 "description"=>"<div><br /></div>",
 "createdAt"=>"2017-06-24T08:36:29.000Z",
 "creator"=>{"code"=>"<user>", "name"=>"<name>"},
 "modifiedAt"=>"2019-11-13T16:36:33.000Z",
 "modifier"=>{"code"=>"<user>", "name"=>"<name>"},
 "spaceId"=>nil,
 "threadId"=>nil}

Basic認証を通す方法

2019-11-22現在の最新版のリリースv0.1.5
https://github.com/jue58/kintone/releases/tag/v0.1.5
では、Basic認証に対応していませんが、#11 https://github.com/jue58/kintone/pull/11 のプルリクでマージされています。(リリースはされていない)
#11のパッチを当てた上で、#15 https://github.com/jue58/kintone/pull/15 のコードによりBasic認証に対応できます。


関連リンク

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0