Class: Gemgento::Adapter::ShopifyAdapter
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Gemgento::Adapter::ShopifyAdapter
- Defined in:
- app/models/gemgento/adapter/shopify_adapter.rb
Class Method Summary collapse
- .api_url ⇒ Object
-
.create_association(gemgento_model, shopify_model) ⇒ Void
Create a ShopifyAdapter for a given Gemgento model and Shopify model.
-
.find_by_shopify_model(shopify_model) ⇒ Object
Find a record by the shopify model.
- .import_all ⇒ Object
Instance Method Summary collapse
-
#shopify_model ⇒ Object
Return the associated shopify model.
-
#shopify_model=(model) ⇒ Void
Create a polymorphic association on shopify_model attributes.
Class Method Details
.api_url ⇒ Object
10 11 12 |
# File 'app/models/gemgento/adapter/shopify_adapter.rb', line 10 def self.api_url "https://#{Gemgento::Config[:adapter][:shopify][:api_key]}:#{Gemgento::Config[:adapter][:shopify][:password]}@#{Gemgento::Config[:adapter][:shopify][:shop_name]}.myshopify.com/admin" end |
.create_association(gemgento_model, shopify_model) ⇒ Void
Create a ShopifyAdapter for a given Gemgento model and Shopify model.
47 48 49 50 51 52 |
# File 'app/models/gemgento/adapter/shopify_adapter.rb', line 47 def self.create_association(gemgento_model, shopify_model) shopify_adapter = Gemgento::Adapter::ShopifyAdapter.new shopify_adapter.gemgento_model = gemgento_model shopify_adapter.shopify_model = shopify_model shopify_adapter.save end |
.find_by_shopify_model(shopify_model) ⇒ Object
Find a record by the shopify model.
58 59 60 |
# File 'app/models/gemgento/adapter/shopify_adapter.rb', line 58 def self.find_by_shopify_model(shopify_model) Gemgento::Adapter::ShopifyAdapter.find_by(shopify_model_type: shopify_model.class, shopify_model_id: shopify_model.id) end |
Instance Method Details
#shopify_model ⇒ Object
Return the associated shopify model
24 25 26 27 28 29 30 31 |
# File 'app/models/gemgento/adapter/shopify_adapter.rb', line 24 def shopify_model if self.shopify_model_type.blank? || self.shopify_model_id.blank? return nil else ShopifyAPI::Base.site = Gemgento::Adapter::ShopifyAdapter.api_url return self.shopify_model_type.constantize.find(self.shopify_model_id) end end |
#shopify_model=(model) ⇒ Void
Create a polymorphic association on shopify_model attributes
37 38 39 40 |
# File 'app/models/gemgento/adapter/shopify_adapter.rb', line 37 def shopify_model=(model) self.shopify_model_type = model.class self.shopify_model_id = model.id end |