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
-
#endpoint ⇒ Peddler::Endpoint
steep:ignore:start.
-
#to_str ⇒ String
steep:ignore:start.
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 107 108 |
# File 'lib/peddler/marketplace.rb', line 41 Marketplace = Data.define(:id, :country_code, :country_name, :selling_region) do 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 find(country_code) # steep:ignore end end # Special alias for GB (Great Britain) -> UK define_method(:gb) do find("GB") # steep:ignore end end # @return [Peddler::Endpoint] # steep:ignore:start def endpoint Endpoint.find_by_selling_region(selling_region) end # steep:ignore:end # @note So HTTP can encode # @return [String] # steep:ignore:start def to_str id end # steep:ignore: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 107 108 |
# File 'lib/peddler/marketplace.rb', line 41 Marketplace = Data.define(:id, :country_code, :country_name, :selling_region) do 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 find(country_code) # steep:ignore end end # Special alias for GB (Great Britain) -> UK define_method(:gb) do find("GB") # steep:ignore end end # @return [Peddler::Endpoint] # steep:ignore:start def endpoint Endpoint.find_by_selling_region(selling_region) end # steep:ignore:end # @note So HTTP can encode # @return [String] # steep:ignore:start def to_str id end # steep:ignore: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 107 108 |
# File 'lib/peddler/marketplace.rb', line 41 Marketplace = Data.define(:id, :country_code, :country_name, :selling_region) do 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 find(country_code) # steep:ignore end end # Special alias for GB (Great Britain) -> UK define_method(:gb) do find("GB") # steep:ignore end end # @return [Peddler::Endpoint] # steep:ignore:start def endpoint Endpoint.find_by_selling_region(selling_region) end # steep:ignore:end # @note So HTTP can encode # @return [String] # steep:ignore:start def to_str id end # steep:ignore: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 107 108 |
# File 'lib/peddler/marketplace.rb', line 41 Marketplace = Data.define(:id, :country_code, :country_name, :selling_region) do 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 find(country_code) # steep:ignore end end # Special alias for GB (Great Britain) -> UK define_method(:gb) do find("GB") # steep:ignore end end # @return [Peddler::Endpoint] # steep:ignore:start def endpoint Endpoint.find_by_selling_region(selling_region) end # steep:ignore:end # @note So HTTP can encode # @return [String] # steep:ignore:start def to_str id end # steep:ignore: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
steep:ignore:start
96 97 98 |
# File 'lib/peddler/marketplace.rb', line 96 def endpoint Endpoint.find_by_selling_region(selling_region) end |
#to_str ⇒ String
Note:
So HTTP can encode
steep:ignore:start
104 105 106 |
# File 'lib/peddler/marketplace.rb', line 104 def to_str id end |