Class: CDEKApiClient::Entities::Agreement

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

Overview

Represents an agreement entity for delivery agreements in the CDEK API.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Validatable

included, #validate!

Constructor Details

#initialize(cdek_number:, date:, time_from:, time_to:, comment: nil, delivery_point: nil, to_location: nil) ⇒ Agreement

Initializes a new Agreement object.

Parameters:

  • cdek_number (String)

    the CDEK order number.

  • date (String)

    the delivery date in YYYY-MM-DD format.

  • time_from (String)

    the start time in HH:MM format.

  • time_to (String)

    the end time in HH:MM format.

  • comment (String) (defaults to: nil)

    the comment for the agreement.

  • delivery_point (String) (defaults to: nil)

    the delivery point code.

  • to_location (Location) (defaults to: nil)

    the delivery location.

Raises:

  • (ArgumentError)

    if any attribute validation fails.



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

def initialize(cdek_number:, date:, time_from:, time_to:, comment: nil, delivery_point: nil, to_location: nil)
  @cdek_number = cdek_number
  @date = date
  @time_from = time_from
  @time_to = time_to
  @comment = comment
  @delivery_point = delivery_point
  @to_location = to_location
  validate!
end

Instance Attribute Details

#cdek_numberObject

Returns the value of attribute cdek_number.



11
12
13
# File 'lib/cdek_api_client/entities/agreement.rb', line 11

def cdek_number
  @cdek_number
end

#commentObject

Returns the value of attribute comment.



11
12
13
# File 'lib/cdek_api_client/entities/agreement.rb', line 11

def comment
  @comment
end

#dateObject

Returns the value of attribute date.



11
12
13
# File 'lib/cdek_api_client/entities/agreement.rb', line 11

def date
  @date
end

#delivery_pointObject

Returns the value of attribute delivery_point.



11
12
13
# File 'lib/cdek_api_client/entities/agreement.rb', line 11

def delivery_point
  @delivery_point
end

#time_fromObject

Returns the value of attribute time_from.



11
12
13
# File 'lib/cdek_api_client/entities/agreement.rb', line 11

def time_from
  @time_from
end

#time_toObject

Returns the value of attribute time_to.



11
12
13
# File 'lib/cdek_api_client/entities/agreement.rb', line 11

def time_to
  @time_to
end

#to_locationObject

Returns the value of attribute to_location.



11
12
13
# File 'lib/cdek_api_client/entities/agreement.rb', line 11

def to_location
  @to_location
end

Instance Method Details

#to_json(*_args) ⇒ String

Converts the Agreement object to a JSON representation.

Returns:

  • (String)

    the JSON representation of the Agreement.



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

def to_json(*_args)
  data = {
    cdek_number: @cdek_number,
    date: @date,
    time_from: @time_from,
    time_to: @time_to
  }
  data[:comment] = @comment if @comment
  data[:delivery_point] = @delivery_point if @delivery_point
  data[:to_location] = @to_location if @to_location
  data.to_json
end