class BestBuy::BaseAPI
Constants
- BASE_URL
All subclasses must implement: :model_class :collection_name :api_url
Attributes
api_key[R]
Public Class Methods
new(api_key = BestBuy.config.api_key)
click to toggle source
# File lib/best_buy/base_api.rb, line 14 def initialize(api_key = BestBuy.config.api_key) raise Exceptions::ApiKeyNotFound unless api_key @api_key = api_key end
Public Instance Methods
get_all(search_query: '', pagination: {})
click to toggle source
# File lib/best_buy/base_api.rb, line 20 def get_all(search_query: '', pagination: {}) request_params = { apiKey: api_key, format: 'json', show: 'all' }.merge(pagination) response = APIHelper.new.parse_response(get_response(search_query, request_params)) CollectionsResponse.new( response: response, collection_name: collection_name, collection_type: model_class ) end
Also aliased as: index
Protected Instance Methods
connection()
click to toggle source
# File lib/best_buy/base_api.rb, line 39 def connection @connection ||= Faraday.new(url: BaseAPI::BASE_URL) end
get_response(search_query, params)
click to toggle source
# File lib/best_buy/base_api.rb, line 43 def get_response(search_query, params) url = URI.escape(api_url + search_query) # rubocop:disable Lint/UriEscapeUnescape connection.get(url, params).body end