Class: BestBuy::BaseAPI

Inherits:
Object
  • Object
show all
Defined in:
lib/best_buy/base_api.rb

Direct Known Subclasses

Categories, Products, Stores

Constant Summary collapse

BASE_URL =

All subclasses must implement: :model_class :collection_name :api_url

'https://api.bestbuy.com'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key = BestBuy.config.api_key) ⇒ BaseAPI

Returns a new instance of BaseAPI.



14
15
16
17
18
# 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

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



12
13
14
# File 'lib/best_buy/base_api.rb', line 12

def api_key
  @api_key
end

Instance Method Details

#get_all(search_query: '', pagination: {}) ⇒ Object Also known as: index



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 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