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_namesArray<String>

Returns:

  • (Array<String>)


38
39
40
# File 'app/models/amazon_product_type_schema.rb', line 38

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

.available_product_typesArray<String>

Returns:

  • (Array<String>)


18
19
20
# File 'app/models/amazon_product_type_schema.rb', line 18

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

.available_schemas_pathArray<String>

Returns:

  • (Array<String>)


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

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

.load_product_type_schema_as_json(schema_name) ⇒ Hash

Parameters:

  • schema_name (String)

Returns:

  • (Hash)


24
25
26
27
# File 'app/models/amazon_product_type_schema.rb', line 24

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_hashHash

Returns:

  • (Hash)


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

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