class Bookdepository::Client

Constants

AVAILABLE_CURRENCIES
BASE_URL

Public Class Methods

configure() { |Config| ... } click to toggle source
# File lib/bookdepository/client.rb, line 16
def self.configure
  yield Config
end

Private Instance Methods

build_params(options) click to toggle source
# File lib/bookdepository/client.rb, line 45
def build_params(options)
  options
    .merge(
      'clientId' => client_id,
      'authenticationKey' => auth_key
    )
    .tap { |params|
      if params.key?('countryCode')
        params['IP'] ||= '127.0.0.1'
        params['currencies'] ||= find_currency(params['countryCode'])
      end
    }
end
build_path(api_request) click to toggle source
# File lib/bookdepository/client.rb, line 41
def build_path(api_request)
  "/search/#{api_request}"
end
find_currency(country_code) click to toggle source
# File lib/bookdepository/client.rb, line 59
def find_currency(country_code)
  currency = ISO3166::Country[country_code].currency_code
  currency if AVAILABLE_CURRENCIES.include?(currency)
end
get(api_request, options = {}) click to toggle source
# File lib/bookdepository/client.rb, line 28
def get(api_request, options = {})
  res = http.get(
    path: build_path(api_request),
    query: build_params(options)
  )

  Parser.new(res)
end
http() click to toggle source
# File lib/bookdepository/client.rb, line 37
def http
  Excon.new(BASE_URL, expects: 200)
end