Class: CatalogAPI::Catalog
- Inherits:
-
Object
- Object
- CatalogAPI::Catalog
- Defined in:
- lib/catalogapi/catalog.rb
Instance Attribute Summary collapse
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
-
#export_uri ⇒ Object
readonly
Returns the value of attribute export_uri.
-
#language ⇒ Object
readonly
Returns the value of attribute language.
-
#point_to_currency_ratio ⇒ Object
readonly
Returns the value of attribute point_to_currency_ratio.
-
#region ⇒ Object
readonly
Returns the value of attribute region.
-
#socket_id ⇒ Object
readonly
Returns the value of attribute socket_id.
-
#socket_name ⇒ Object
readonly
Returns the value of attribute socket_name.
Class Method Summary collapse
-
.list_available ⇒ Array[CatalogAPI::Catalog]
Returns a list of the catalog sockets you have available on your account.
Instance Method Summary collapse
-
#breakdown(is_flat: 0) ⇒ Array[CatalogAPI::Category]
Returns a list of item categories available in a catalog.
-
#initialize(opts) ⇒ Catalog
constructor
A new instance of Catalog.
-
#search(options = {}, request = nil) ⇒ Array[CatalogAPI::Item]
Searches a catalog by keyword, category, or price range.
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
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
18 19 20 |
# File 'lib/catalogapi/catalog.rb', line 18 def currency @currency end |
#export_uri ⇒ Object (readonly)
Returns the value of attribute export_uri.
18 19 20 |
# File 'lib/catalogapi/catalog.rb', line 18 def export_uri @export_uri end |
#language ⇒ Object (readonly)
Returns the value of attribute language.
18 19 20 |
# File 'lib/catalogapi/catalog.rb', line 18 def language @language end |
#point_to_currency_ratio ⇒ Object (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 |
#region ⇒ Object (readonly)
Returns the value of attribute region.
18 19 20 |
# File 'lib/catalogapi/catalog.rb', line 18 def region @region end |
#socket_id ⇒ Object (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_name ⇒ Object (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_available ⇒ 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
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.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/catalogapi/catalog.rb', line 58 def search( = {}, request = nil) raise CatalogAPI::Error, 'No Socket ID' if socket_id.nil? request ||= CatalogAPI.request.new(:search_catalog) request = request.get(.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 = [:paginated] ? request.next_page : nil request = search(.merge(page: next_page), request) if next_page request end |