Class: Gemgento::Adapter::ShopifyAdapter

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/gemgento/adapter/shopify_adapter.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.api_urlObject



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.

Parameters:

  • gemgento_model (Object)
  • shopify_model (Object)

Returns:

  • (Void)


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.

Parameters:

  • shopify_model (Object)
  • (Object, nil)


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

.import_allObject



14
15
16
17
18
19
# File 'app/models/gemgento/adapter/shopify_adapter.rb', line 14

def self.import_all
  Shopify::Category.import
  Shopify::Product.import
  Shopify::Customer.import
  Shopify::Order.import
end

Instance Method Details

#shopify_modelObject

Return the associated shopify model

Returns:

  • (Object)


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

Parameters:

  • model (Object)

Returns:

  • (Void)


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