Class: Shipvine::Item

Inherits:
Base
  • Object
show all
Defined in:
lib/shipvine/item.rb

Constant Summary

Constants inherited from Base

Base::WAREHOUSE_XSD_FILE

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

client, xml_to_hash

Constructor Details

#initialize(attributes) ⇒ Item

Returns a new instance of Item.



22
23
24
# File 'lib/shipvine/item.rb', line 22

def initialize(attributes)
  @attributes = attributes
end

Class Method Details

.get(item_group_merchant_identifier, item_merchant_identifier) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/shipvine/item.rb', line 3

def self.get(item_group_merchant_identifier, item_merchant_identifier)
  request = self.client.request(
    :get,
    # escape SKU?

    '/item-groups/' +
      Shipvine.merchant_code + '/' +
      item_group_merchant_identifier + '/' +
      'items/' +
      item_merchant_identifier,
    {},
    exclude_merchant_code: true
  )

  self.new(self.xml_to_hash(request.body))
rescue Shipvine::Error => e
  nil
end

Instance Method Details

#createObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/shipvine/item.rb', line 26

def create
  translated_payload = @attributes.deep_dup

  merchant_identifier = translated_payload.delete(:merchant_identifier)
  group_merchant_identifier = translated_payload.delete(:group_merchant_identifier)

  (translated_payload)
  preprocess_variations(translated_payload)

  client.request(
    :put,
    '/item-groups/' +
      Shipvine.merchant_code + '/' +
      group_merchant_identifier + '/' +
      'items/' +
      merchant_identifier,
    request_body('Item', translated_payload),
    exclude_merchant_code: true
  )
end