Class: MuffinMan::RequestHelpers::OutboundFulfillment::Item

Inherits:
Base
  • Object
show all
Defined in:
lib/muffin_man/request_helpers/outbound_fulfillment/item.rb

Constant Summary collapse

OPTIONAL_ITEM_PARAMS =
%w[
  perUnitDeclaredValue
  giftMessage
  displayableComment
  fulfillmentNetworkSku
  perUnitDeclaredValue
  perUnitPrice
  perUnitTax
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

json_body, #json_body

Constructor Details

#initialize(attributes = {}) ⇒ Item

Initializes the object

Parameters:

  • attributes (Hash) (defaults to: {})

    Model attributes in the form of hash



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/muffin_man/request_helpers/outbound_fulfillment/item.rb', line 21

def initialize(attributes = {})
  super
  return unless attributes.is_a?(Hash)

  attributes = attributes.with_indifferent_access

  @seller_sku = attributes["seller_sku"] if attributes.key?("seller_sku")

  if attributes.key?("seller_fulfillment_order_item_id")
    @seller_fulfillment_order_item_id = attributes["seller_fulfillment_order_item_id"]
  end

  @quantity = attributes["quantity"] if attributes.key?("quantity")

  @optional_params = attributes.slice(*OPTIONAL_ITEM_PARAMS)
end

Instance Attribute Details

#optional_paramsObject

Returns the value of attribute optional_params.



7
8
9
# File 'lib/muffin_man/request_helpers/outbound_fulfillment/item.rb', line 7

def optional_params
  @optional_params
end

#quantityObject

Returns the value of attribute quantity.



7
8
9
# File 'lib/muffin_man/request_helpers/outbound_fulfillment/item.rb', line 7

def quantity
  @quantity
end

#seller_fulfillment_order_item_idObject

Returns the value of attribute seller_fulfillment_order_item_id.



7
8
9
# File 'lib/muffin_man/request_helpers/outbound_fulfillment/item.rb', line 7

def seller_fulfillment_order_item_id
  @seller_fulfillment_order_item_id
end

#seller_skuObject

Returns the value of attribute seller_sku.



7
8
9
# File 'lib/muffin_man/request_helpers/outbound_fulfillment/item.rb', line 7

def seller_sku
  @seller_sku
end

Instance Method Details

#errorsObject

Show invalid properties with the reasons.

Returns:

  • Array for invalid properties with the reasons



50
51
52
53
54
55
56
57
# File 'lib/muffin_man/request_helpers/outbound_fulfillment/item.rb', line 50

def errors
  errors = []
  errors.push('"seller_sku" cannot be nil.') if seller_sku.blank?
  errors.push('"seller_fulfillment_order_item_id" cannot be nil.') if seller_fulfillment_order_item_id.blank?
  errors.push('"quantity" cannot be nil.') if quantity.blank?

  errors
end

#to_camelizeObject



59
60
61
62
63
64
65
# File 'lib/muffin_man/request_helpers/outbound_fulfillment/item.rb', line 59

def to_camelize
  {
    "sellerSku" => seller_sku,
    "sellerFulfillmentOrderItemId" => seller_fulfillment_order_item_id,
    "quantity" => quantity
  }.merge!(optional_params.slice(*OPTIONAL_ITEM_PARAMS))
end

#valid?Boolean

Check to see if the all the properties in the model are valid

Returns:

  • (Boolean)

    true if the model is valid



40
41
42
43
44
45
46
# File 'lib/muffin_man/request_helpers/outbound_fulfillment/item.rb', line 40

def valid?
  return false if seller_sku.blank?
  return false if seller_fulfillment_order_item_id.blank?
  return false if quantity.blank?

  true
end