Class: MuffinMan::RequestHelpers::OutboundFulfillment::FulfillmentPreviewRequest

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

Constant Summary collapse

OPTIONAL_FULFILLMENT_PREVIEW_PARAMS =
%w[
  marketplaceId
  shippingSpeedCategories
  includeCODFulfillmentPreview
  includeDeliveryWindows
  featureConstraints
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

json_body, #json_body

Constructor Details

#initialize(address, items, optional_params = {}) ⇒ FulfillmentPreviewRequest

Initializes the object @param items in the form of list of items objects

Parameters:



21
22
23
24
25
26
# File 'lib/muffin_man/request_helpers/outbound_fulfillment/fulfillment_preview_request.rb', line 21

def initialize(address, items, optional_params = {})
  super
  @address = address
  @items = items
  @optional_params = optional_params
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



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

def address
  @address
end

#itemsObject

Returns the value of attribute items.



7
8
9
# File 'lib/muffin_man/request_helpers/outbound_fulfillment/fulfillment_preview_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_preview_request.rb', line 7

def optional_params
  @optional_params
end

Instance Method Details

#errorsObject

Show invalid properties with the reasons.

Returns:

  • Array for invalid properties with the reasons



42
43
44
45
46
47
48
49
50
# File 'lib/muffin_man/request_helpers/outbound_fulfillment/fulfillment_preview_request.rb', line 42

def errors
  errors = []
  errors.push('"address" cannot be nil.') if address.blank?
  errors.push('"items" cannot be nil.') if items.blank?
  errors.push("invalid value for \"address\",#{address.errors}") if address.present? && !address.valid?
  errors.push('invalid value for "items"') if items.present? && items.map(&:valid?).include?(false)

  errors
end

#to_camelizeObject

Format request object in sp-api request format

Returns:

  • hash for sp-api request format



55
56
57
58
59
60
# File 'lib/muffin_man/request_helpers/outbound_fulfillment/fulfillment_preview_request.rb', line 55

def to_camelize
  {
    "address" => address.to_camelize,
    "items" => items.map(&:to_camelize)
  }.merge!(optional_params.slice(*OPTIONAL_FULFILLMENT_PREVIEW_PARAMS))
end

#valid?Boolean

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

Returns:

  • (Boolean)

    true if the model is valid



31
32
33
34
35
36
37
38
# File 'lib/muffin_man/request_helpers/outbound_fulfillment/fulfillment_preview_request.rb', line 31

def valid?
  return false if address.blank? || !address.is_a?(MuffinMan::RequestHelpers::OutboundFulfillment::Address)
  return false if items.blank? || !items.is_a?(Array)

  return false if !address.valid? || items.map(&:valid?).include?(false)

  true
end