Class: CDEKApiClient::Entities::Item

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

Overview

Represents an item in the CDEK API. Each item has attributes such as ware key, payment, name, cost, amount, weight, and optional URL.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Validatable

included, #validate!

Constructor Details

#initialize(ware_key:, payment:, name:, cost:, amount:, weight:, url: nil) ⇒ Item

Initializes a new Item object.

Parameters:

  • ware_key (String)

    the ware key of the item.

  • payment (Payment)

    the payment details of the item.

  • name (String)

    the name of the item.

  • cost (Integer)

    the cost of the item.

  • amount (Integer)

    the amount of the item.

  • weight (Integer)

    the weight of the item.

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

    the optional URL of the item.

Raises:

  • (ArgumentError)

    if any attribute validation fails.



32
33
34
35
36
37
38
39
40
41
# File 'lib/cdek_api_client/entities/item.rb', line 32

def initialize(ware_key:, payment:, name:, cost:, amount:, weight:, url: nil)
  @ware_key = ware_key
  @payment = payment
  @name = name
  @cost = cost
  @amount = amount
  @weight = weight
  @url = url
  validate!
end

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



13
14
15
# File 'lib/cdek_api_client/entities/item.rb', line 13

def amount
  @amount
end

#costObject

Returns the value of attribute cost.



13
14
15
# File 'lib/cdek_api_client/entities/item.rb', line 13

def cost
  @cost
end

#nameObject

Returns the value of attribute name.



13
14
15
# File 'lib/cdek_api_client/entities/item.rb', line 13

def name
  @name
end

#paymentObject

Returns the value of attribute payment.



13
14
15
# File 'lib/cdek_api_client/entities/item.rb', line 13

def payment
  @payment
end

#urlObject

Returns the value of attribute url.



13
14
15
# File 'lib/cdek_api_client/entities/item.rb', line 13

def url
  @url
end

#ware_keyObject

Returns the value of attribute ware_key.



13
14
15
# File 'lib/cdek_api_client/entities/item.rb', line 13

def ware_key
  @ware_key
end

#weightObject

Returns the value of attribute weight.



13
14
15
# File 'lib/cdek_api_client/entities/item.rb', line 13

def weight
  @weight
end

Instance Method Details

#to_json(*_args) ⇒ String

Converts the Item object to a JSON representation.

Returns:

  • (String)

    the JSON representation of the Item.



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/cdek_api_client/entities/item.rb', line 46

def to_json(*_args)
  {
    ware_key: @ware_key,
    payment: @payment,
    name: @name,
    cost: @cost,
    amount: @amount,
    weight: @weight,
    url: @url
  }.to_json
end