Class: CDEKApiClient::Entities::Check
- Inherits:
-
Object
- Object
- CDEKApiClient::Entities::Check
- 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
-
#cdek_number ⇒ Object
Returns the value of attribute cdek_number.
-
#date ⇒ Object
Returns the value of attribute date.
Instance Method Summary collapse
-
#initialize(cdek_number: nil, date: nil) ⇒ Check
constructor
Initializes a new Check object.
-
#to_json(*_args) ⇒ String
Converts the Check object to a JSON representation.
-
#to_query_params ⇒ Hash
Converts the Check object to a hash for query parameters.
-
#validate! ⇒ Object
Override validate! to allow both fields to be nil.
Methods included from Validatable
Constructor Details
#initialize(cdek_number: nil, date: nil) ⇒ Check
Initializes a new Check object.
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_number ⇒ Object
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 |
#date ⇒ Object
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.
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_params ⇒ Hash
Converts the Check object to a hash for 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 |