Class: Crm::Wayfair::SchemasController
- Inherits:
-
CrmController
- Object
- CrmController
- Crm::Wayfair::SchemasController
- Defined in:
- app/controllers/crm/wayfair/schemas_controller.rb
Overview
CRUD and taxonomy-schema refresh for WayfairSchema records, which
cache the attribute schema Wayfair's Catalog API returns per taxonomy
category.
Instance Method Summary collapse
-
#create ⇒ void
Creates a schema record flagged for its first refresh.
-
#destroy ⇒ void
Deletes the schema loaded by #load_schema.
-
#index ⇒ void
Lists cached Wayfair schemas, Ransack-searchable.
-
#new ⇒ void
Builds a new schema record.
-
#refresh_schema ⇒ void
Pulls the current taxonomy schema for this category from Wayfair's Catalog API and caches it on the record.
-
#show ⇒ void
Shows the schema loaded by #load_schema.
Instance Method Details
#create ⇒ void
This method returns an undefined value.
Creates a schema record flagged for its first refresh.
34 35 36 37 38 39 40 41 42 43 |
# File 'app/controllers/crm/wayfair/schemas_controller.rb', line 34 def create @wayfair_schema = WayfairSchema.new(wayfair_schema_params) @wayfair_schema.schema = { status: :must_refresh } if @wayfair_schema.save flash[:info] = 'Schema created, now refresh to pull schema' redirect_to url_for(action: :show, id: @wayfair_schema.id) else render :new, status: :unprocessable_content end end |
#destroy ⇒ void
This method returns an undefined value.
Deletes the schema loaded by #load_schema.
69 70 71 72 73 |
# File 'app/controllers/crm/wayfair/schemas_controller.rb', line 69 def destroy @wayfair_schema.destroy flash[:info] = 'Schema deleted' redirect_to url_for(action: :index) end |
#index ⇒ void
This method returns an undefined value.
Lists cached Wayfair schemas, Ransack-searchable.
12 13 14 15 16 17 |
# File 'app/controllers/crm/wayfair/schemas_controller.rb', line 12 def index :manage, WayfairSchema @q = WayfairSchema.ransack(params[:q]) @q.sorts = 'taxonomy_category_id asc' if @q.sorts.empty? @pagy, @wayfair_schemas = pagy(@q.result) end |
#new ⇒ void
This method returns an undefined value.
Builds a new schema record.
27 28 29 |
# File 'app/controllers/crm/wayfair/schemas_controller.rb', line 27 def new @wayfair_schema = WayfairSchema.new end |
#refresh_schema ⇒ void
This method returns an undefined value.
Pulls the current taxonomy schema for this category from Wayfair's
Catalog API and caches it on the record.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/controllers/crm/wayfair/schemas_controller.rb', line 49 def refresh_schema orchestrator = Edi::Wayfair::Orchestrator.build(:wayfair_us) result = orchestrator.pull_taxonomy_schema_for_category( @wayfair_schema.taxonomy_category_id, wayfair_schema: @wayfair_schema, brand: @wayfair_schema.brand, country: @wayfair_schema.country, locale: @wayfair_schema.locale ) if result flash[:notice] = "Schema refreshed (#{result.attributes_list.size} attributes)" else flash[:error] = 'Failed to refresh schema' end redirect_to url_for(action: :show, id: @wayfair_schema.id) end |
#show ⇒ void
This method returns an undefined value.
Shows the schema loaded by #load_schema.
22 |
# File 'app/controllers/crm/wayfair/schemas_controller.rb', line 22 def show; end |