Class: Peddler::Marketplace

Inherits:
Data
  • Object
show all
Defined in:
lib/peddler/marketplace.rb,
lib/peddler/marketplace.rb,
sig/peddler/marketplace.rbs

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#country_codeString (readonly)

Wraps an Amazon marketplace

Returns:

  • (String)


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_nameString (readonly)

Wraps an Amazon marketplace

Returns:

  • (String)


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

#idString (readonly)

Wraps an Amazon marketplace

Returns:

  • (String)


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_regionString (readonly)

Wraps an Amazon marketplace

Returns:

  • (String)


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

.allArray<Peddler::Marketplace>

Returns all marketplaces

Returns:



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

Parameters:

  • country_code (String)

Returns:



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

.gbMarketplace

Returns:



10
# File 'sig/peddler/marketplace.rbs', line 10

def self.gb: () -> Marketplace

.id(country_code) ⇒ String

Returns the marketplace ID for the given country code

Parameters:

  • country_code (String)

Returns:

  • (String)


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

Parameters:

  • country_codes (Array<String>)

Returns:

  • (Array<String>)


66
67
68
# File 'lib/peddler/marketplace.rb', line 66

def ids(*country_codes)
  country_codes.map { |country_code| id(country_code) }
end

.newMarketplace

Parameters:

  • id: (String, nil)
  • country_code: (String, nil)
  • country_name: (String, nil)
  • selling_region: (String, nil)

Returns:



5
# File 'sig/peddler/marketplace.rbs', line 5

def self.new: (?id: String?, ?country_code: String?, ?country_name: String?, ?selling_region: String?) -> Marketplace

.usMarketplace

Dynamically defined country methods

Returns:



15
# File 'sig/peddler/marketplace.rbs', line 15

def self.us: () -> Marketplace

Instance Method Details

#endpointPeddler::Endpoint

steep:ignore:start

Returns:



96
97
98
# File 'lib/peddler/marketplace.rb', line 96

def endpoint
  Endpoint.find_by_selling_region(selling_region)
end

#to_strString

Note:

So HTTP can encode

steep:ignore:start

Returns:

  • (String)


104
105
106
# File 'lib/peddler/marketplace.rb', line 104

def to_str
  id
end