Class: CDEKApiClient::Entities::OrderData

Inherits:
Object
  • Object
show all
Includes:
Validatable
Defined in:
lib/cdek_api_client/entities/order_data.rb

Overview

Represents the data required to create an order in the CDEK API. Each order includes attributes such as type, number, tariff code, locations, recipient, sender, and packages.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Validatable

included, #validate!

Constructor Details

#initialize(type:, number:, tariff_code:, from_location:, to_location:, recipient:, sender:, packages:, comment: nil, shipment_point: nil, delivery_point: nil, services: []) ⇒ OrderData

Initializes a new OrderData object.

Parameters:

  • type (Integer)

    the type of the order.

  • number (String)

    the order number.

  • tariff_code (Integer)

    the tariff code.

  • from_location (Location)

    the location details from where the order is shipped.

  • to_location (Location)

    the location details to where the order is shipped.

  • recipient (Recipient)

    the recipient details.

  • sender (Sender)

    the sender details.

  • packages (Array<Package>)

    the list of packages.

  • comment (String, nil) (defaults to: nil)

    the comment for the order.

  • shipment_point (String, nil) (defaults to: nil)

    the shipment point.

  • delivery_point (String, nil) (defaults to: nil)

    the delivery point.

  • services (Array, nil) (defaults to: [])

    additional services.

Raises:

  • (ArgumentError)

    if any attribute validation fails.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/cdek_api_client/entities/order_data.rb', line 43

def initialize(type:, number:, tariff_code:, from_location:, to_location:, recipient:, sender:, packages:,
               comment: nil, shipment_point: nil, delivery_point: nil, services: [])
  @type = type
  @number = number
  @tariff_code = tariff_code
  @comment = comment
  @shipment_point = shipment_point
  @delivery_point = delivery_point
  @from_location = from_location
  @to_location = to_location
  @recipient = recipient
  @sender = sender
  @services = services
  @packages = packages
  validate!
end

Instance Attribute Details

#commentObject

Returns the value of attribute comment.



15
16
17
# File 'lib/cdek_api_client/entities/order_data.rb', line 15

def comment
  @comment
end

#delivery_pointObject

Returns the value of attribute delivery_point.



15
16
17
# File 'lib/cdek_api_client/entities/order_data.rb', line 15

def delivery_point
  @delivery_point
end

#from_locationObject

Returns the value of attribute from_location.



15
16
17
# File 'lib/cdek_api_client/entities/order_data.rb', line 15

def from_location
  @from_location
end

#numberObject

Returns the value of attribute number.



15
16
17
# File 'lib/cdek_api_client/entities/order_data.rb', line 15

def number
  @number
end

#packagesObject

Returns the value of attribute packages.



15
16
17
# File 'lib/cdek_api_client/entities/order_data.rb', line 15

def packages
  @packages
end

#recipientObject

Returns the value of attribute recipient.



15
16
17
# File 'lib/cdek_api_client/entities/order_data.rb', line 15

def recipient
  @recipient
end

#senderObject

Returns the value of attribute sender.



15
16
17
# File 'lib/cdek_api_client/entities/order_data.rb', line 15

def sender
  @sender
end

#servicesObject

Returns the value of attribute services.



15
16
17
# File 'lib/cdek_api_client/entities/order_data.rb', line 15

def services
  @services
end

#shipment_pointObject

Returns the value of attribute shipment_point.



15
16
17
# File 'lib/cdek_api_client/entities/order_data.rb', line 15

def shipment_point
  @shipment_point
end

#tariff_codeObject

Returns the value of attribute tariff_code.



15
16
17
# File 'lib/cdek_api_client/entities/order_data.rb', line 15

def tariff_code
  @tariff_code
end

#to_locationObject

Returns the value of attribute to_location.



15
16
17
# File 'lib/cdek_api_client/entities/order_data.rb', line 15

def to_location
  @to_location
end

#typeObject

Returns the value of attribute type.



15
16
17
# File 'lib/cdek_api_client/entities/order_data.rb', line 15

def type
  @type
end

Instance Method Details

#to_json(*_args) ⇒ String

Converts the OrderData object to a JSON representation.

Returns:

  • (String)

    the JSON representation of the OrderData.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/cdek_api_client/entities/order_data.rb', line 63

def to_json(*_args)
  {
    type: @type,
    number: @number,
    tariff_code: @tariff_code,
    comment: @comment,
    shipment_point: @shipment_point,
    delivery_point: @delivery_point,
    from_location: @from_location,
    to_location: @to_location,
    recipient: @recipient,
    sender: @sender,
    services: @services,
    packages: @packages
  }.to_json
end