Class: CDEKApiClient::Entities::Intakes

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

Overview

Represents an intakes entity for courier intake requests in the CDEK API.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Validatable

included, #validate!

Constructor Details

#initialize(cdek_number:, intake_date:, intake_time_from:, intake_time_to:, name:, sender:, from_location:, lunch_time_from: nil, lunch_time_to: nil, need_call: nil, comment: nil, weight: nil, length: nil, width: nil, height: nil) ⇒ Intakes

Initializes a new Intakes object.

Parameters:

  • cdek_number (String)

    the CDEK order number.

  • intake_date (String)

    the intake date in YYYY-MM-DD format.

  • intake_time_from (String)

    the start time in HH:MM format.

  • intake_time_to (String)

    the end time in HH:MM format.

  • lunch_time_from (String) (defaults to: nil)

    the lunch start time in HH:MM format.

  • lunch_time_to (String) (defaults to: nil)

    the lunch end time in HH:MM format.

  • name (String)

    the name/description of the cargo.

  • need_call (Boolean) (defaults to: nil)

    whether a call is needed.

  • comment (String) (defaults to: nil)

    the comment for the intake.

  • sender (Contact)

    the sender contact information.

  • from_location (Location)

    the pickup location.

  • weight (Numeric) (defaults to: nil)

    the weight of the cargo.

  • length (Numeric) (defaults to: nil)

    the length of the cargo.

  • width (Numeric) (defaults to: nil)

    the width of the cargo.

  • height (Numeric) (defaults to: nil)

    the height of the cargo.

Raises:

  • (ArgumentError)

    if any attribute validation fails.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/cdek_api_client/entities/intakes.rb', line 49

def initialize(cdek_number:, intake_date:, intake_time_from:, intake_time_to:,
               name:, sender:, from_location:, lunch_time_from: nil, lunch_time_to: nil, need_call: nil,
               comment: nil, weight: nil, length: nil,
               width: nil, height: nil)
  @cdek_number = cdek_number
  @intake_date = intake_date
  @intake_time_from = intake_time_from
  @intake_time_to = intake_time_to
  @lunch_time_from = lunch_time_from
  @lunch_time_to = lunch_time_to
  @name = name
  @need_call = need_call
  @comment = comment
  @sender = sender
  @from_location = from_location
  @weight = weight
  @length = length
  @width = width
  @height = height
  validate!
end

Instance Attribute Details

#cdek_numberObject

Returns the value of attribute cdek_number.



11
12
13
# File 'lib/cdek_api_client/entities/intakes.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/intakes.rb', line 11

def comment
  @comment
end

#from_locationObject

Returns the value of attribute from_location.



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

def from_location
  @from_location
end

#heightObject

Returns the value of attribute height.



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

def height
  @height
end

#intake_dateObject

Returns the value of attribute intake_date.



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

def intake_date
  @intake_date
end

#intake_time_fromObject

Returns the value of attribute intake_time_from.



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

def intake_time_from
  @intake_time_from
end

#intake_time_toObject

Returns the value of attribute intake_time_to.



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

def intake_time_to
  @intake_time_to
end

#lengthObject

Returns the value of attribute length.



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

def length
  @length
end

#lunch_time_fromObject

Returns the value of attribute lunch_time_from.



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

def lunch_time_from
  @lunch_time_from
end

#lunch_time_toObject

Returns the value of attribute lunch_time_to.



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

def lunch_time_to
  @lunch_time_to
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#need_callObject

Returns the value of attribute need_call.



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

def need_call
  @need_call
end

#senderObject

Returns the value of attribute sender.



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

def sender
  @sender
end

#weightObject

Returns the value of attribute weight.



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

def weight
  @weight
end

#widthObject

Returns the value of attribute width.



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

def width
  @width
end

Instance Method Details

#to_json(*_args) ⇒ String

Converts the Intakes object to a JSON representation.

Returns:

  • (String)

    the JSON representation of the Intakes.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/cdek_api_client/entities/intakes.rb', line 74

def to_json(*_args)
  data = {
    cdek_number: @cdek_number,
    intake_date: @intake_date,
    intake_time_from: @intake_time_from,
    intake_time_to: @intake_time_to,
    name: @name,
    sender: @sender,
    from_location: @from_location
  }
  data[:lunch_time_from] = @lunch_time_from if @lunch_time_from
  data[:lunch_time_to] = @lunch_time_to if @lunch_time_to
  data[:need_call] = @need_call unless @need_call.nil?
  data[:comment] = @comment if @comment
  data[:weight] = @weight if @weight
  data[:length] = @length if @length
  data[:width] = @width if @width
  data[:height] = @height if @height
  data.to_json
end