Class: Kintone::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/kintone/client/client.rb,
lib/kintone/client/version.rb

Defined Under Namespace

Modules: Middleware Classes: Path

Constant Summary collapse

ENDPOINT =
'https://%s.cybozu.com'
VERSION =
'0.1.6'

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Client

Returns a new instance of Client.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/kintone/client/client.rb', line 4

def initialize(options)
  @auth = {}

  if options[:api_token]
    @auth[:api_token] = options.delete(:api_token)
  else
    [:login_name, :password].each do |k|
      @auth[k] = options.fetch(k)
      options.delete(k)
    end
  end

  unless options[:url]
    options[:url] = ENDPOINT % options.fetch(:subdomain)
    options.delete(:subdomain)
  end

  @conn = Faraday.new(options) do |faraday|
    faraday.request  :url_encoded
    faraday.request  :record, :content_type => /\bjson\b/
    faraday.response :form,   :content_type => /\bjson\b/ # must set before :json
    faraday.response :json,   :content_type => /\bjson\b/

    yield(faraday) if block_given?

    required_adapters = [Faraday::Adapter::NetHttp, Faraday::Adapter::Test]

    unless required_adapters.any? {|i| faraday.builder.handlers.include?(i) }
      faraday.adapter Faraday.default_adapter
    end
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object (private)



39
40
41
42
43
44
45
# File 'lib/kintone/client/client.rb', line 39

def method_missing(method_name, *args)
  unless args.length.zero?
    raise ArgumentError, "wrong number of arguments (#{args.length} for 0)"
  end

  Path.new(@conn, @auth, method_name.to_s)
end