Class: Peddler::Marketplace
- Inherits:
-
Data
- Object
- Data
- Peddler::Marketplace
- Defined in:
- lib/peddler/marketplace.rb,
lib/peddler/marketplace.rb,
sig/peddler/marketplace.rbs
Instance Attribute Summary collapse
-
#country_code ⇒ String
readonly
Wraps an Amazon marketplace.
-
#country_name ⇒ String
readonly
Wraps an Amazon marketplace.
-
#id ⇒ String
readonly
Wraps an Amazon marketplace.
-
#selling_region ⇒ String
readonly
Wraps an Amazon marketplace.
Class Method Summary collapse
-
.all ⇒ Array<Peddler::Marketplace>
Returns all marketplaces.
-
.find(country_code) ⇒ Marketplace
Finds the marketplace for the given country code.
-
.gb ⇒ Marketplace
-
.id(country_code) ⇒ String
Returns the marketplace ID for the given country code.
-
.ids(*country_codes) ⇒ Array<String>
Returns the marketplace IDs for the given country codes.
-
.new ⇒ Marketplace
-
.us ⇒ Marketplace
Dynamically defined country methods.
Instance Method Summary collapse
Instance Attribute Details
#country_code ⇒ String (readonly)
Wraps an Amazon marketplace
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/peddler/marketplace.rb', line 41 class Marketplace < Data.define(:id, :country_code, :country_name, :selling_region) class << self # Finds the marketplace for the given country code # # @param [String] country_code def find(country_code) values = MARKETPLACE_IDS.fetch(country_code == "GB" ? "UK" : country_code) do raise ArgumentError, "#{country_code} not found" end new(**values, country_code: country_code) end # Returns the marketplace ID for the given country code # # @param [String] country_code # @return [String] def id(country_code) find(country_code).id end # Returns the marketplace IDs for the given country codes # # @param [Array<String>] country_codes # @return [Array<String>] def ids(*country_codes) country_codes.map { |country_code| id(country_code) } end # Returns all marketplaces # # @return [Array<Peddler::Marketplace>] def all MARKETPLACE_IDS.map do |country_code, values| new(**values, country_code: country_code) end end # Dynamically generate shorthand methods for each country code # e.g., Marketplace.us returns the US marketplace MARKETPLACE_IDS.each_key do |country_code| method_name = country_code.downcase define_method(method_name) do # @type self: singleton(Marketplace) find(country_code) end end # Special alias for GB (Great Britain) -> UK define_method(:gb) do # @type self: singleton(Marketplace) find("GB") end end # @return [Peddler::Endpoint] def endpoint Endpoint.find_by_selling_region(selling_region) end # @note So HTTP can encode # @return [String] def to_str id end end |
#country_name ⇒ String (readonly)
Wraps an Amazon marketplace
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/peddler/marketplace.rb', line 41 class Marketplace < Data.define(:id, :country_code, :country_name, :selling_region) class << self # Finds the marketplace for the given country code # # @param [String] country_code def find(country_code) values = MARKETPLACE_IDS.fetch(country_code == "GB" ? "UK" : country_code) do raise ArgumentError, "#{country_code} not found" end new(**values, country_code: country_code) end # Returns the marketplace ID for the given country code # # @param [String] country_code # @return [String] def id(country_code) find(country_code).id end # Returns the marketplace IDs for the given country codes # # @param [Array<String>] country_codes # @return [Array<String>] def ids(*country_codes) country_codes.map { |country_code| id(country_code) } end # Returns all marketplaces # # @return [Array<Peddler::Marketplace>] def all MARKETPLACE_IDS.map do |country_code, values| new(**values, country_code: country_code) end end # Dynamically generate shorthand methods for each country code # e.g., Marketplace.us returns the US marketplace MARKETPLACE_IDS.each_key do |country_code| method_name = country_code.downcase define_method(method_name) do # @type self: singleton(Marketplace) find(country_code) end end # Special alias for GB (Great Britain) -> UK define_method(:gb) do # @type self: singleton(Marketplace) find("GB") end end # @return [Peddler::Endpoint] def endpoint Endpoint.find_by_selling_region(selling_region) end # @note So HTTP can encode # @return [String] def to_str id end end |
#id ⇒ String (readonly)
Wraps an Amazon marketplace
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/peddler/marketplace.rb', line 41 class Marketplace < Data.define(:id, :country_code, :country_name, :selling_region) class << self # Finds the marketplace for the given country code # # @param [String] country_code def find(country_code) values = MARKETPLACE_IDS.fetch(country_code == "GB" ? "UK" : country_code) do raise ArgumentError, "#{country_code} not found" end new(**values, country_code: country_code) end # Returns the marketplace ID for the given country code # # @param [String] country_code # @return [String] def id(country_code) find(country_code).id end # Returns the marketplace IDs for the given country codes # # @param [Array<String>] country_codes # @return [Array<String>] def ids(*country_codes) country_codes.map { |country_code| id(country_code) } end # Returns all marketplaces # # @return [Array<Peddler::Marketplace>] def all MARKETPLACE_IDS.map do |country_code, values| new(**values, country_code: country_code) end end # Dynamically generate shorthand methods for each country code # e.g., Marketplace.us returns the US marketplace MARKETPLACE_IDS.each_key do |country_code| method_name = country_code.downcase define_method(method_name) do # @type self: singleton(Marketplace) find(country_code) end end # Special alias for GB (Great Britain) -> UK define_method(:gb) do # @type self: singleton(Marketplace) find("GB") end end # @return [Peddler::Endpoint] def endpoint Endpoint.find_by_selling_region(selling_region) end # @note So HTTP can encode # @return [String] def to_str id end end |
#selling_region ⇒ String (readonly)
Wraps an Amazon marketplace
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/peddler/marketplace.rb', line 41 class Marketplace < Data.define(:id, :country_code, :country_name, :selling_region) class << self # Finds the marketplace for the given country code # # @param [String] country_code def find(country_code) values = MARKETPLACE_IDS.fetch(country_code == "GB" ? "UK" : country_code) do raise ArgumentError, "#{country_code} not found" end new(**values, country_code: country_code) end # Returns the marketplace ID for the given country code # # @param [String] country_code # @return [String] def id(country_code) find(country_code).id end # Returns the marketplace IDs for the given country codes # # @param [Array<String>] country_codes # @return [Array<String>] def ids(*country_codes) country_codes.map { |country_code| id(country_code) } end # Returns all marketplaces # # @return [Array<Peddler::Marketplace>] def all MARKETPLACE_IDS.map do |country_code, values| new(**values, country_code: country_code) end end # Dynamically generate shorthand methods for each country code # e.g., Marketplace.us returns the US marketplace MARKETPLACE_IDS.each_key do |country_code| method_name = country_code.downcase define_method(method_name) do # @type self: singleton(Marketplace) find(country_code) end end # Special alias for GB (Great Britain) -> UK define_method(:gb) do # @type self: singleton(Marketplace) find("GB") end end # @return [Peddler::Endpoint] def endpoint Endpoint.find_by_selling_region(selling_region) end # @note So HTTP can encode # @return [String] def to_str id end end |
Class Method Details
.all ⇒ Array<Peddler::Marketplace>
Returns all marketplaces
73 74 75 76 77 |
# File 'lib/peddler/marketplace.rb', line 73 def all MARKETPLACE_IDS.map do |country_code, values| new(**values, country_code: country_code) end end |
.find(country_code) ⇒ Marketplace
Finds the marketplace for the given country code
46 47 48 49 50 51 52 |
# File 'lib/peddler/marketplace.rb', line 46 def find(country_code) values = MARKETPLACE_IDS.fetch(country_code == "GB" ? "UK" : country_code) do raise ArgumentError, "#{country_code} not found" end new(**values, country_code: country_code) end |
.id(country_code) ⇒ String
Returns the marketplace ID for the given country code
58 59 60 |
# File 'lib/peddler/marketplace.rb', line 58 def id(country_code) find(country_code).id end |
.ids(*country_codes) ⇒ Array<String>
Returns the marketplace IDs for the given country codes
66 67 68 |
# File 'lib/peddler/marketplace.rb', line 66 def ids(*country_codes) country_codes.map { |country_code| id(country_code) } end |
.new ⇒ Marketplace
5 |
# File 'sig/peddler/marketplace.rbs', line 5
def self.new: (?id: String?, ?country_code: String?, ?country_name: String?, ?selling_region: String?) -> Marketplace
|
.us ⇒ Marketplace
Dynamically defined country methods
15 |
# File 'sig/peddler/marketplace.rbs', line 15
def self.us: () -> Marketplace
|
Instance Method Details
#endpoint ⇒ Peddler::Endpoint
97 98 99 |
# File 'lib/peddler/marketplace.rb', line 97 def endpoint Endpoint.find_by_selling_region(selling_region) end |
#to_str ⇒ String
Note:
So HTTP can encode
103 104 105 |
# File 'lib/peddler/marketplace.rb', line 103 def to_str id end |