class Cyby::Kintone::RestApi

Constants

AUTH

Attributes

app[R]

Public Class Methods

new(app) click to toggle source
# File lib/cyby/kintone/rest_api.rb, line 10
def initialize(app)
  config = YAML.load_file("#{ENV['HOME']}/.cyby.yml")
  self.class.base_uri "https://#{config['subdomain']}.cybozu.com/k/v1"
  @auth = Base64.encode64("#{config['login']}:#{config['password']}").chomp
  @app = app
end

Public Instance Methods

delete(path, body = {}) click to toggle source
# File lib/cyby/kintone/rest_api.rb, line 54
def delete(path, body = {})
  body.merge!(app: @app)
  options = { headers: headers, body: body.to_json }
  resp = self.class.delete(path, options)
  if resp.code == 200
    resp
  else
    raise Cyby::Kintone::InvalidRecord.new(resp)
  end
end
get(path, body = {}) click to toggle source
# File lib/cyby/kintone/rest_api.rb, line 21
def get(path, body = {})
  body.merge!(app: @app)
  options = { headers: headers, body: body.to_json }
  resp = self.class.get(path, options)
  if resp.code == 200
    resp
  else
    raise Cyby::Kintone::InvalidRecord.new(resp)
  end
end
headers() click to toggle source
# File lib/cyby/kintone/rest_api.rb, line 17
def headers
  { AUTH => @auth, 'Content-Type' => 'application/json' }
end
post(path, body = {}) click to toggle source
# File lib/cyby/kintone/rest_api.rb, line 32
def post(path, body = {})
  body.merge!(app: @app)
  options = { headers: headers, body: body.to_json }
  resp = self.class.post(path, options)
  if resp.code == 200
    resp
  else
    raise Cyby::Kintone::InvalidRecord.new(resp)
  end
end
put(path, body = {}) click to toggle source
# File lib/cyby/kintone/rest_api.rb, line 43
def put(path, body = {})
  body.merge!(app: @app)
  options = { headers: headers, body: body.to_json }
  resp = self.class.put(path, options)
  if resp.code == 200
    resp
  else
    raise Cyby::Kintone::InvalidRecord.new(resp)
  end
end