Class: MuffinMan::RequestHelpers::OutboundFulfillment::FulfillmentOrderRequest

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

Constant Summary collapse

OPTIONAL_CREATE_FULFILLMENT_ORDER_PARAMS =
%w[
  marketplaceId
  deliveryWindow
  fulfillmentAction
  fulfillmentPolicy
  codSettings
  shipFromCountryCode
  notificationEmails
  featureConstraints
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

json_body, #json_body

Constructor Details

#initialize(seller_fulfillment_order_id, displayable_order_id, displayable_order_date_time, displayable_order_comment, shipping_speed_category, destination_address, items, optional_params = {}) ⇒ FulfillmentOrderRequest

Initializes the object

Parameters:



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/muffin_man/request_helpers/outbound_fulfillment/fulfillment_order_request.rb', line 31

def initialize(seller_fulfillment_order_id, displayable_order_id, displayable_order_date_time,
               displayable_order_comment, shipping_speed_category, destination_address, items,
               optional_params = {})
  super
  @seller_fulfillment_order_id = seller_fulfillment_order_id
  @displayable_order_id = displayable_order_id
  @displayable_order_date_time = displayable_order_date_time
  @displayable_order_comment = displayable_order_comment
  @shipping_speed_category = shipping_speed_category
  @destination_address = destination_address
  @items = items
  @optional_params = optional_params
end

Instance Attribute Details

#destination_addressObject

Returns the value of attribute destination_address.



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

def destination_address
  @destination_address
end

#displayable_order_commentObject

Returns the value of attribute displayable_order_comment.



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

def displayable_order_comment
  @displayable_order_comment
end

#displayable_order_date_timeObject

Returns the value of attribute displayable_order_date_time.



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

def displayable_order_date_time
  @displayable_order_date_time
end

#displayable_order_idObject

Returns the value of attribute displayable_order_id.



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

def displayable_order_id
  @displayable_order_id
end

#itemsObject

Returns the value of attribute items.



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

def items
  @items
end

#optional_paramsObject

Returns the value of attribute optional_params.



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

def optional_params
  @optional_params
end

#seller_fulfillment_order_idObject

Returns the value of attribute seller_fulfillment_order_id.



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

def seller_fulfillment_order_id
  @seller_fulfillment_order_id
end

#shipping_speed_categoryObject

Returns the value of attribute shipping_speed_category.



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

def shipping_speed_category
  @shipping_speed_category
end

Instance Method Details

#errorsObject

Show invalid properties with the reasons.

Returns:

  • Array for invalid properties with the



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/muffin_man/request_helpers/outbound_fulfillment/fulfillment_order_request.rb', line 65

def errors
  errors = []
  errors.push('"seller_fulfillment_order_id" cannot be nil.') if seller_fulfillment_order_id.blank?
  errors.push('"displayable_order_id" cannot be nil.') if displayable_order_id.blank?
  errors.push('"displayable_order_date_time" cannot be nil.') if displayable_order_date_time.blank?
  errors.push('"displayable_order_comment" cannot be nil.') if displayable_order_comment.blank?
  errors.push('"shipping_speed_category" cannot be nil.') if shipping_speed_category.blank?
  errors.push('"destination_address" cannot be nil.') if destination_address.blank?
  errors.push('"items" cannot be nil.') if items.blank?

  if !destination_address.nil? && !destination_address.valid?
    errors.push("invalid value for \"destination_address\", #{destination_address.errors}")
  end

  errors.push('invalid value for "items"') if !items.nil? && items.map(&:valid?).include?(false)

  errors
end

#to_camelizeObject

Format request object in sp-api request format

Returns:

  • hash for sp-api request format



88
89
90
91
92
93
94
95
96
97
98
# File 'lib/muffin_man/request_helpers/outbound_fulfillment/fulfillment_order_request.rb', line 88

def to_camelize
  {
    "sellerFulfillmentOrderId" => seller_fulfillment_order_id,
    "displayableOrderId" => displayable_order_id,
    "displayableOrderDate" => displayable_order_date_time,
    "displayableOrderComment" => displayable_order_comment,
    "shippingSpeedCategory" => shipping_speed_category,
    "destinationAddress" => destination_address.to_camelize,
    "items" => items.map(&:to_camelize)
  }.merge!(optional_params.slice(*OPTIONAL_CREATE_FULFILLMENT_ORDER_PARAMS))
end

#valid?Boolean

Check to see if the all the properties in the model are valid rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity

Returns:

  • (Boolean)

    true if the model is valid



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/muffin_man/request_helpers/outbound_fulfillment/fulfillment_order_request.rb', line 49

def valid?
  return false if seller_fulfillment_order_id.blank?
  return false if displayable_order_id.blank?
  return false if displayable_order_date_time.blank?
  return false if displayable_order_comment.blank?
  return false if shipping_speed_category.blank?
  return false if destination_address.blank?
  return false if items.blank?
  return false if destination_address.present? && !destination_address.valid?
  return false if items.present? && items.map(&:valid?).include?(false)

  true
end