class Base
Attributes
access_token[R]
Public Class Methods
new(access_token: '')
click to toggle source
# File lib/wordsapi/base.rb, line 11 def initialize(access_token: '') @access_token = access_token end
Public Instance Methods
service_url()
click to toggle source
# File lib/wordsapi/base.rb, line 15 def service_url raise NotImplementedError end
Private Instance Methods
connection()
click to toggle source
# File lib/wordsapi/base.rb, line 21 def connection @connection ||= Faraday.new(service_url) do |config| config.request :json config.response :raise_error config.response :json, content_type: /\bjson$/ config.use :instrumentation config.options[:timeout] = 10 config.use Faraday::RequestId config.adapter Faraday.default_adapter config.headers['X-RapidAPI-Key'] = access_token end end
process_response(response)
click to toggle source
# File lib/wordsapi/base.rb, line 34 def process_response(response) if response.success? body = response.body if body.empty? {} elsif body.is_a?(Array) body.map(&:deep_symbolize_keys) else body.deep_symbolize_keys end end end