Class: CatalogAPI::Catalog

Inherits:
Object
  • Object
show all
Defined in:
lib/catalogapi/catalog.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Catalog

Returns a new instance of Catalog.



20
21
22
23
24
25
26
27
28
# File 'lib/catalogapi/catalog.rb', line 20

def initialize(opts)
  @currency = opts[:currency]
  @export_uri = opts[:export_uri]
  @language = opts[:language]
  @point_to_currency_ratio = opts[:point_to_currency_ratio]
  @region = opts[:region]
  @socket_id = opts[:socket_id]
  @socket_name = opts[:socket_name]
end

Instance Attribute Details

#currencyObject (readonly)

Returns the value of attribute currency.



18
19
20
# File 'lib/catalogapi/catalog.rb', line 18

def currency
  @currency
end

#export_uriObject (readonly)

Returns the value of attribute export_uri.



18
19
20
# File 'lib/catalogapi/catalog.rb', line 18

def export_uri
  @export_uri
end

#languageObject (readonly)

Returns the value of attribute language.



18
19
20
# File 'lib/catalogapi/catalog.rb', line 18

def language
  @language
end

#point_to_currency_ratioObject (readonly)

Returns the value of attribute point_to_currency_ratio.



18
19
20
# File 'lib/catalogapi/catalog.rb', line 18

def point_to_currency_ratio
  @point_to_currency_ratio
end

#regionObject (readonly)

Returns the value of attribute region.



18
19
20
# File 'lib/catalogapi/catalog.rb', line 18

def region
  @region
end

#socket_idObject (readonly)

Returns the value of attribute socket_id.



18
19
20
# File 'lib/catalogapi/catalog.rb', line 18

def socket_id
  @socket_id
end

#socket_nameObject (readonly)

Returns the value of attribute socket_name.



18
19
20
# File 'lib/catalogapi/catalog.rb', line 18

def socket_name
  @socket_name
end

Class Method Details

.list_availableArray[CatalogAPI::Catalog]

Returns a list of the catalog sockets you have available on your account.

Returns:

  • (Array[CatalogAPI::Catalog])

    Returns a list of the catalog sockets you have available on your account.



7
8
9
10
11
12
13
14
15
# File 'lib/catalogapi/catalog.rb', line 7

def list_available
  request = CatalogAPI.request.new(:list_available_catalogs).get
  sockets = request.json.dig(
    :list_available_catalogs_response, :list_available_catalogs_result,
    :domain, :sockets, :Socket
  ).to_a
  request.data = sockets.map { |socket| new(socket) }
  request
end

Instance Method Details

#breakdown(is_flat: 0) ⇒ Array[CatalogAPI::Category]

Returns a list of item categories available in a catalog

Returns:

Raises:



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/catalogapi/catalog.rb', line 31

def breakdown(is_flat: 0)
  raise CatalogAPI::Error, 'No Socket ID' if socket_id.nil?

  request = CatalogAPI.request.new(:catalog_breakdown).get(socket_id: socket_id, is_flat: is_flat)
  catgories = request.json.dig(
    :catalog_breakdown_response, :catalog_breakdown_result, :categories,
    :Category
  ).to_a
  request.data = catgories.map { |cateogry| CatalogAPI::Category.new(cateogry) }
  request
end

#search(options = {}, request = nil) ⇒ Array[CatalogAPI::Item]

Returns Searches a catalog by keyword, category, or price range.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :name (String)

    Searches the names of items.

  • :search (String)

    Search the name, description and model of items.

  • :category_id (String)

    Returns only items within this category_id. (This includes any child categories of the category_id.) The category_id comes from the catalog_breakdown method.

  • :min_points (String)

    Return only items that have a point value of at least this value.

  • :max_points (String)

    Return only items that have a point value of no more than this value.

  • :min_price (String)

    Return only items that have a price of at least this value.

  • :max_price (String)

    Return only items that have a price of no more than this value.

  • :max_rank (String)

    Do not return items with a rank higher than this value.

  • :tag (String)

    We have the ability to “tag” certain items based on custom criteria that is unique to our clients. If we setup these tags on your catalog, you can pass a tag name with your search.

  • :page (String)

    The page number. Defaults to 1.

  • :paginated (String)

    Whether to paginate the call or return the first page result default: nil

  • :per_page (String)

    The number of items to return, per page. Can be from 1 to 50. Defaults to 10.

  • :sort (String)

    The following sort values are supported: ‘points desc’, ‘points asc’, ‘rank asc’, ‘score desc’, ‘random asc’

  • :catalog_item_ids (String)

    Return only items in the given list.

Returns:

  • (Array[CatalogAPI::Item])

    Searches a catalog by keyword, category, or price range.

Raises:



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/catalogapi/catalog.rb', line 58

def search(options = {}, request = nil)
  raise CatalogAPI::Error, 'No Socket ID' if socket_id.nil?

  request ||= CatalogAPI.request.new(:search_catalog)
  request = request.get(options.to_h.merge(socket_id: socket_id))
  items = request.json.dig(
    :search_catalog_response, :search_catalog_result, :items, :CatalogItem
  ).to_a
  request.data += items.map { |item| CatalogAPI::Item.new(item.merge(socket_id: socket_id)) }
  # Pagination
  next_page = options[:paginated] ? request.next_page : nil
  request = search(options.merge(page: next_page), request) if next_page
  request
end