Class: SmsRu::Status

Inherits:
Object
  • Object
show all
Includes:
DeliveryStatus
Defined in:
lib/sms_ru/data.rb

Overview

Delivery status of one message (one entry of a /sms/status response). ‘status_code` is the message’s delivery state; read it with #delivered?, #pending?, #failed?, or the SmsRu::Statuses constants.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DeliveryStatus

#delivered?, #failed?, #pending?

Instance Attribute Details

#costFloat? (readonly)

Returns the message cost, when present.

Returns:

  • (Float, nil)

    the message cost, when present



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/sms_ru/data.rb', line 79

class Status < Data.define(:sms_id, :status_code, :status_text, :cost)
  include DeliveryStatus

  # @param sms_id [String] the message id
  # @param hash [Hash] one entry of the response `sms` object
  # @return [SmsRu::Status]
  def self.build(sms_id, hash)
    new(
      sms_id: String(sms_id),
      status_code: Coerce.integer(hash["status_code"], Statuses::NOT_FOUND),
      status_text: Coerce.string(hash["status_text"]),
      cost: Coerce.float?(hash["cost"])
    )
  end

  # @param hash [Hash] the parsed /sms/status response
  # @return [Array<SmsRu::Status>] one Status per requested id
  def self.build_all(hash) = Coerce.records(hash["sms"]).map { |sms_id, sms| build(sms_id, sms) }

  # @return [Boolean] true when the queried id exists (not status code -1)
  def found? = status_code != Statuses::NOT_FOUND
end

#sms_idString (readonly)

Returns the message id.

Returns:

  • (String)

    the message id



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/sms_ru/data.rb', line 79

class Status < Data.define(:sms_id, :status_code, :status_text, :cost)
  include DeliveryStatus

  # @param sms_id [String] the message id
  # @param hash [Hash] one entry of the response `sms` object
  # @return [SmsRu::Status]
  def self.build(sms_id, hash)
    new(
      sms_id: String(sms_id),
      status_code: Coerce.integer(hash["status_code"], Statuses::NOT_FOUND),
      status_text: Coerce.string(hash["status_text"]),
      cost: Coerce.float?(hash["cost"])
    )
  end

  # @param hash [Hash] the parsed /sms/status response
  # @return [Array<SmsRu::Status>] one Status per requested id
  def self.build_all(hash) = Coerce.records(hash["sms"]).map { |sms_id, sms| build(sms_id, sms) }

  # @return [Boolean] true when the queried id exists (not status code -1)
  def found? = status_code != Statuses::NOT_FOUND
end

#status_codeInteger (readonly)

Returns the delivery state code (see SmsRu::Statuses).

Returns:

  • (Integer)

    the delivery state code (see SmsRu::Statuses)



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/sms_ru/data.rb', line 79

class Status < Data.define(:sms_id, :status_code, :status_text, :cost)
  include DeliveryStatus

  # @param sms_id [String] the message id
  # @param hash [Hash] one entry of the response `sms` object
  # @return [SmsRu::Status]
  def self.build(sms_id, hash)
    new(
      sms_id: String(sms_id),
      status_code: Coerce.integer(hash["status_code"], Statuses::NOT_FOUND),
      status_text: Coerce.string(hash["status_text"]),
      cost: Coerce.float?(hash["cost"])
    )
  end

  # @param hash [Hash] the parsed /sms/status response
  # @return [Array<SmsRu::Status>] one Status per requested id
  def self.build_all(hash) = Coerce.records(hash["sms"]).map { |sms_id, sms| build(sms_id, sms) }

  # @return [Boolean] true when the queried id exists (not status code -1)
  def found? = status_code != Statuses::NOT_FOUND
end

#status_textString (readonly)

Returns the human-readable delivery state.

Returns:

  • (String)

    the human-readable delivery state



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/sms_ru/data.rb', line 79

class Status < Data.define(:sms_id, :status_code, :status_text, :cost)
  include DeliveryStatus

  # @param sms_id [String] the message id
  # @param hash [Hash] one entry of the response `sms` object
  # @return [SmsRu::Status]
  def self.build(sms_id, hash)
    new(
      sms_id: String(sms_id),
      status_code: Coerce.integer(hash["status_code"], Statuses::NOT_FOUND),
      status_text: Coerce.string(hash["status_text"]),
      cost: Coerce.float?(hash["cost"])
    )
  end

  # @param hash [Hash] the parsed /sms/status response
  # @return [Array<SmsRu::Status>] one Status per requested id
  def self.build_all(hash) = Coerce.records(hash["sms"]).map { |sms_id, sms| build(sms_id, sms) }

  # @return [Boolean] true when the queried id exists (not status code -1)
  def found? = status_code != Statuses::NOT_FOUND
end

Class Method Details

.build(sms_id, hash) ⇒ SmsRu::Status

Parameters:

  • sms_id (String)

    the message id

  • hash (Hash)

    one entry of the response ‘sms` object

Returns:



85
86
87
88
89
90
91
92
# File 'lib/sms_ru/data.rb', line 85

def self.build(sms_id, hash)
  new(
    sms_id: String(sms_id),
    status_code: Coerce.integer(hash["status_code"], Statuses::NOT_FOUND),
    status_text: Coerce.string(hash["status_text"]),
    cost: Coerce.float?(hash["cost"])
  )
end

.build_all(hash) ⇒ Array<SmsRu::Status>

Returns one Status per requested id.

Parameters:

  • hash (Hash)

    the parsed /sms/status response

Returns:



96
# File 'lib/sms_ru/data.rb', line 96

def self.build_all(hash) = Coerce.records(hash["sms"]).map { |sms_id, sms| build(sms_id, sms) }

Instance Method Details

#found?Boolean

Returns true when the queried id exists (not status code -1).

Returns:

  • (Boolean)

    true when the queried id exists (not status code -1)



99
# File 'lib/sms_ru/data.rb', line 99

def found? = status_code != Statuses::NOT_FOUND