Class: AmazonProductTypeSchema

Inherits:
Object
  • Object
show all
Defined in:
app/models/amazon_product_type_schema.rb

Overview

Reads Amazon Selling Partner product-type schema JSON definitions shipped
under data/json/schemas/amazon_sc/product_type/.

Used by the Amazon listing pipeline (Edi::Amazon::JsonListingGenerator) to
look up which product types are available for a given marketplace and to
resolve the schema theme name an item should use when generating listings.

Constant Summary collapse

BASE_PATH =

Filesystem/URL path for base.

File.join('data', 'json', 'schemas', 'amazon_sc', 'product_type').to_s.freeze

Class Method Summary collapse

Class Method Details

.all_product_type_theme_namesObject



32
33
34
# File 'app/models/amazon_product_type_schema.rb', line 32

def all_product_type_theme_names
  product_type_theme_names_hash.values.flatten.uniq.compact.sort
end

.available_product_typesObject



16
17
18
# File 'app/models/amazon_product_type_schema.rb', line 16

def available_product_types
  available_schemas_path.map { |fp| File.basename(fp, '.json').upcase }
end

.available_schemas_pathObject



12
13
14
# File 'app/models/amazon_product_type_schema.rb', line 12

def available_schemas_path
  Dir.glob(File.join(BASE_PATH, '*.json'))
end

.load_product_type_schema_as_json(schema_name) ⇒ Object



20
21
22
23
# File 'app/models/amazon_product_type_schema.rb', line 20

def load_product_type_schema_as_json(schema_name)
  schema_path = File.join(BASE_PATH, "#{schema_name.downcase}.json")
  JSON.parse(File.read(schema_path))
end

.product_type_theme_names_hashObject



25
26
27
28
29
30
# File 'app/models/amazon_product_type_schema.rb', line 25

def product_type_theme_names_hash
  available_product_types.each_with_object({}) do |product_type, hsh|
    theme_names = load_product_type_schema_as_json(product_type).dig('properties', 'variation_theme', 'items', 'properties', 'name', 'enum')
    hsh[product_type] = theme_names
  end
end