Class: SpreePluggto::Api::Product

Inherits:
Object
  • Object
show all
Defined in:
app/services/spree_pluggto/api/product.rb

Class Method Summary collapse

Class Method Details

.find(pluggto_id) ⇒ Object



4
5
6
7
# File 'app/services/spree_pluggto/api/product.rb', line 4

def find(pluggto_id)
  response = ::SpreePluggto::Api::Request.new.get("/products/#{pluggto_id}")
  response["Product"]
end

.upsert(spree_product) ⇒ Object

UPSERT => Updates the record if it exists, inserts if it is a new record



10
11
12
13
# File 'app/services/spree_pluggto/api/product.rb', line 10

def upsert(spree_product)
  response = ::SpreePluggto::Api::Request.new.put("/skus/#{spree_product.sku}", params(spree_product).to_json)
  spree_product.update_columns(pluggto_id: response.dig("Product","id"))
end