Skip to content

Commit

Permalink
Add Marketplace.all
Browse files Browse the repository at this point in the history
  • Loading branch information
hakanensari committed Oct 11, 2024
1 parent 1bcc290 commit d7cbbf3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/peddler/marketplace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ module Peddler

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
Expand All @@ -40,17 +42,30 @@ def find(country_code)
new(**values.merge(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.merge(country_code: country_code))
end
end
end

# @return [Peddler::Endpoint]
Expand Down
4 changes: 4 additions & 0 deletions test/peddler/marketplace_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def test_ids
assert(Marketplace.ids(*MARKETPLACE_IDS.keys))
end

def test_all
assert(Marketplace.all)
end

private

def country_code
Expand Down

0 comments on commit d7cbbf3

Please sign in to comment.