class DMM::Client

Constants

API_MAP
BASE_URL
DEFAULT_USER_AGENT

Public Class Methods

new(options = {}) click to toggle source
# File lib/ruby-dmm/client.rb, line 14
def initialize(options = {})
  @api_id       = (ENV['DMM_API_ID']       || options[:api_id])
  @affiliate_id = (ENV['DMM_AFFILIATE_ID'] || options[:affiliate_id])
  @user_agent   = (ENV['DMM_USER_AGENT']   || options[:user_agent] || DEFAULT_USER_AGENT)
end

Private Instance Methods

connection() click to toggle source
# File lib/ruby-dmm/client.rb, line 49
def connection
  @connection ||= Faraday.new(faraday_options) do |faraday|
    faraday.adapter  Faraday.default_adapter
    faraday.request  :url_encoded
    faraday.response :json
  end
end
credentials() click to toggle source
# File lib/ruby-dmm/client.rb, line 38
def credentials
  {
    api_id:       @api_id,
    affiliate_id: @affiliate_id,
  }
end
faraday_options() click to toggle source
# File lib/ruby-dmm/client.rb, line 57
def faraday_options
  {
    url: BASE_URL,
    headers: {
      user_agent: @user_agent,
    },
  }
end
get(path, options = {}) click to toggle source
# File lib/ruby-dmm/client.rb, line 45
def get(path, options = {})
  Response.new(connection.get(path, options))
end