class Kokkai::Client

Public Class Methods

new() click to toggle source
# File lib/kokkai/client.rb, line 9
def initialize
end

Public Instance Methods

kokkai_connection() click to toggle source
# File lib/kokkai/client.rb, line 21
def kokkai_connection
  @kokkai_connection ||= Faraday.new(faraday_options) do |c|
    c.request  :url_encoded
    c.response :xml,  :content_type => /\bxml$/
    c.adapter Faraday.default_adapter
    c.options.params_encoder = ParamsEncoder
  end
end
send_get(path, params = nil) click to toggle source
# File lib/kokkai/client.rb, line 12
def send_get(path, params = nil)
  send_request(:get, path, params)
end
send_request(method, path, params = nil) click to toggle source
# File lib/kokkai/client.rb, line 16
def send_request(method, path, params = nil)
  response = kokkai_connection.send(method, path, params)
  Kokkai::Response.new(response)
end

Private Instance Methods

default_headers() click to toggle source
# File lib/kokkai/client.rb, line 39
def default_headers
  {
    'Accept' => 'application/xml',
    'User-Agent' => "Kokkai Ruby Gem #{Kokkai::VERSION}"
  }
end
faraday_headers() click to toggle source
# File lib/kokkai/client.rb, line 46
def faraday_headers
  default_headers
end
faraday_options() click to toggle source
# File lib/kokkai/client.rb, line 32
def faraday_options
  {
    url: faraday_url,
    headers: faraday_headers
  }
end
faraday_url() click to toggle source
# File lib/kokkai/client.rb, line 50
def faraday_url
  'http://kokkai.ndl.go.jp'
end