Class: CDEKApiClient::Entities::Check

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

Overview

Represents a check entity for retrieving check information in the CDEK API.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Validatable

included

Constructor Details

#initialize(cdek_number: nil, date: nil) ⇒ Check

Initializes a new Check object.

Parameters:

  • cdek_number (String) (defaults to: nil)

    the CDEK order number.

  • date (String) (defaults to: nil)

    the date in YYYY-MM-DD format.

Raises:

  • (ArgumentError)

    if any attribute validation fails.



31
32
33
34
35
# File 'lib/cdek_api_client/entities/check.rb', line 31

def initialize(cdek_number: nil, date: nil)
  @cdek_number = cdek_number
  @date = date
  validate!
end

Instance Attribute Details

#cdek_numberObject

Returns the value of attribute cdek_number.



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

def cdek_number
  @cdek_number
end

#dateObject

Returns the value of attribute date.



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

def date
  @date
end

Instance Method Details

#to_json(*_args) ⇒ String

Converts the Check object to a JSON representation.

Returns:

  • (String)

    the JSON representation of the Check.



50
51
52
# File 'lib/cdek_api_client/entities/check.rb', line 50

def to_json(*_args)
  to_query_params.to_json
end

#to_query_paramsHash

Converts the Check object to a hash for query parameters.

Returns:

  • (Hash)

    the query parameters.



40
41
42
43
44
45
# File 'lib/cdek_api_client/entities/check.rb', line 40

def to_query_params
  params = {}
  params[:cdek_number] = @cdek_number if @cdek_number
  params[:date] = @date if @date
  params
end

#validate!Object

Override validate! to allow both fields to be nil



17
18
19
20
21
22
23
24
# File 'lib/cdek_api_client/entities/check.rb', line 17

def validate!
  # Only validate non-nil fields
  validate_presence(:cdek_number, @cdek_number, { presence: false }) unless @cdek_number.nil?
  validate_type(:cdek_number, @cdek_number, { type: :string }) unless @cdek_number.nil?

  validate_presence(:date, @date, { presence: false }) unless @date.nil?
  validate_type(:date, @date, { type: :string }) unless @date.nil?
end