Class: AmazonSchema
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- AmazonSchema
- 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
- #product_type ⇒ Object readonly
- #schema ⇒ Object readonly
Belongs to collapse
Methods included from Models::Auditable
Delegated Instance Attributes collapse
-
#keys ⇒ Object
Alias for Properties#keys.
Class Method Summary collapse
Instance Method Summary collapse
- #orchestrator ⇒ Object
- #properties ⇒ Object
- #property_definition(property_name) ⇒ Object
- #refresh_schema ⇒ Object
- #schema_as_json ⇒ Object
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
Instance Attribute Details
#product_type ⇒ Object (readonly)
29 |
# File 'app/models/amazon_schema.rb', line 29 validates :product_type, presence: true |
#schema ⇒ Object (readonly)
30 |
# File 'app/models/amazon_schema.rb', line 30 validates :schema, presence: true |
Class Method Details
.valid_locales ⇒ Object
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_marketplace ⇒ AmazonMarketplace
28 |
# File 'app/models/amazon_schema.rb', line 28 belongs_to :amazon_marketplace, inverse_of: :amazon_schemas |
#keys ⇒ Object
Alias for Properties#keys
39 |
# File 'app/models/amazon_schema.rb', line 39 delegate :keys, to: :properties |
#orchestrator ⇒ Object
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 |
#properties ⇒ Object
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_schema ⇒ Object
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_json ⇒ Object
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 |