Class: AmazonSchema

Inherits:
ApplicationRecord show all
Includes:
Models::Auditable
Defined in:
app/models/amazon_schema.rb

Overview

== Schema Information

Table name: amazon_schemas
Database name: primary

id :bigint not null, primary key
amazon_channel :string not null
locale :string not null
product_type :string not null
schema :jsonb not null
created_at :datetime not null
updated_at :datetime not null
amazon_marketplace_id :integer not null

Indexes

index_amazon_schemas_on_amazon_marketplace_id (amazon_marketplace_id)

Foreign Keys

fk_rails_... (amazon_marketplace_id => amazon_marketplaces.id)

Constant Summary

Constants included from Models::Auditable

Models::Auditable::ALWAYS_IGNORED

Instance Attribute Summary collapse

Belongs to collapse

Methods included from Models::Auditable

#creator, #updater

Delegated Instance Attributes collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Models::Auditable

#all_skipped_columns, #audit_reference_data, #should_not_save_version, #stamp_record

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#product_typeObject (readonly)



29
# File 'app/models/amazon_schema.rb', line 29

validates :product_type, presence: true

#schemaObject (readonly)



30
# File 'app/models/amazon_schema.rb', line 30

validates :schema, presence: true

Class Method Details

.valid_localesObject



84
85
86
# File 'app/models/amazon_schema.rb', line 84

def self.valid_locales
  Edi::Amazon::Orchestrator.orchestrators.flat_map(&:locales).uniq
end

Instance Method Details

#amazon_marketplaceAmazonMarketplace



28
# File 'app/models/amazon_schema.rb', line 28

belongs_to :amazon_marketplace, inverse_of: :amazon_schemas

#keysObject

Alias for Properties#keys

Returns:

  • (Object)

    Properties#keys

See Also:



39
# File 'app/models/amazon_schema.rb', line 39

delegate :keys, to: :properties

#orchestratorObject



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
# File 'app/models/amazon_schema.rb', line 55

def orchestrator
  raise "Not implemented yet Amazon Channel: #{amazon_channel}" unless amazon_channel_seller?

  case amazon_marketplace.country.iso
  when 'US'
    Edi::Amazon::Orchestrator.new(:amazon_seller_central_us)
  when 'CA'
    Edi::Amazon::Orchestrator.new(:amazon_seller_central_ca)
  when 'DE'
    Edi::Amazon::Orchestrator.new(:amazon_seller_central_de)
  when 'FR'
    Edi::Amazon::Orchestrator.new(:amazon_seller_central_fr)
  when 'ES'
    Edi::Amazon::Orchestrator.new(:amazon_seller_central_es)
  when 'IT'
    Edi::Amazon::Orchestrator.new(:amazon_seller_central_it)
  when 'NL'
    Edi::Amazon::Orchestrator.new(:amazon_seller_central_nl)
  when 'BE'
    Edi::Amazon::Orchestrator.new(:amazon_seller_central_be)
  when 'PL'
    Edi::Amazon::Orchestrator.new(:amazon_seller_central_pl)
  when 'SE'
    Edi::Amazon::Orchestrator.new(:amazon_seller_central_se)
  else
    raise "Not implemented yet Marketplace ID: #{amazon_marketplace_id}"
  end
end

#propertiesObject



35
36
37
# File 'app/models/amazon_schema.rb', line 35

def properties
  schema.fetch('properties', {}).symbolize_keys
end

#property_definition(property_name) ⇒ Object



41
42
43
# File 'app/models/amazon_schema.rb', line 41

def property_definition(property_name)
  properties[property_name.to_sym]
end

#refresh_schemaObject



51
52
53
# File 'app/models/amazon_schema.rb', line 51

def refresh_schema
  orchestrator.pull_schema_for_locale(product_type, locale, amazon_schema: self)
end

#schema_as_jsonObject



45
46
47
48
49
# File 'app/models/amazon_schema.rb', line 45

def schema_as_json
  return unless schema.present?

  JSON.pretty_generate(JSON.parse(schema.to_json))
end