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 :enum 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

Constants included from Models::Schedulable

Models::Schedulable::SIMPLE_FORM_OPTIONS

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::Schedulable

config

Methods included from Models::AfterCommittable

#after_commit

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#product_typeString (readonly)

Returns:

  • (String)


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

validates :product_type, presence: true

#schemaHash (readonly)

Returns:

  • (Hash)


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

validates :schema, presence: true

Class Method Details

.valid_localesArray<String>

Returns:

  • (Array<String>)


96
97
98
# File 'app/models/amazon_schema.rb', line 96

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

Instance Method Details

#amazon_marketplaceAmazonMarketplace

Returns:



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

belongs_to :amazon_marketplace, inverse_of: :amazon_schemas

#keysObject

Alias for Properties#keys

Returns:

  • (Object)

    Properties#keys

See Also:



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

delegate :keys, to: :properties

#orchestratorEdi::Amazon::Orchestrator



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'app/models/amazon_schema.rb', line 66

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

#propertiesHash

Returns:

  • (Hash)


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

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

#property_definition(property_name) ⇒ Hash?

Parameters:

  • property_name (Symbol, String)

Returns:

  • (Hash, nil)


49
50
51
# File 'app/models/amazon_schema.rb', line 49

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

#refresh_schemavoid

This method returns an undefined value.



61
62
63
# File 'app/models/amazon_schema.rb', line 61

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

#schema_as_jsonString?

Returns:

  • (String, nil)


54
55
56
57
58
# File 'app/models/amazon_schema.rb', line 54

def schema_as_json
  return if schema.blank?

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