Class: CDEKApiClient::Entities::Recipient

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

Overview

Represents a recipient entity in the CDEK API. Each recipient includes attributes such as name, phones, and email.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Validatable

included, #validate!

Constructor Details

#initialize(name:, phones:, email:) ⇒ Recipient

Initializes a new Recipient object.

Parameters:

  • name (String)

    the name of the recipient.

  • phones (Array<Hash>)

    the list of phone numbers for the recipient.

  • email (String)

    the email address of the recipient.

Raises:

  • (ArgumentError)

    if any attribute validation fails.



25
26
27
28
29
30
# File 'lib/cdek_api_client/entities/recipient.rb', line 25

def initialize(name:, phones:, email:)
  @name = name
  @phones = phones
  @email = email
  validate!
end

Instance Attribute Details

#emailObject

Returns the value of attribute email.



12
13
14
# File 'lib/cdek_api_client/entities/recipient.rb', line 12

def email
  @email
end

#nameObject

Returns the value of attribute name.



12
13
14
# File 'lib/cdek_api_client/entities/recipient.rb', line 12

def name
  @name
end

#phonesObject

Returns the value of attribute phones.



12
13
14
# File 'lib/cdek_api_client/entities/recipient.rb', line 12

def phones
  @phones
end

Instance Method Details

#to_json(*_args) ⇒ String

Converts the Recipient object to a JSON representation.

Returns:

  • (String)

    the JSON representation of the Recipient.



35
36
37
38
39
40
41
# File 'lib/cdek_api_client/entities/recipient.rb', line 35

def to_json(*_args)
  {
    name: @name,
    phones: @phones,
    email: @email
  }.to_json
end