Class: SmsRu::Status
- Inherits:
-
Object
- Object
- SmsRu::Status
- 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
-
#cost ⇒ Float?
readonly
The message cost, when present.
-
#sms_id ⇒ String
readonly
The message id.
-
#status_code ⇒ Integer
readonly
The delivery state code (see SmsRu::Statuses).
-
#status_text ⇒ String
readonly
The human-readable delivery state.
Class Method Summary collapse
- .build(sms_id, hash) ⇒ SmsRu::Status
-
.build_all(hash) ⇒ Array<SmsRu::Status>
One Status per requested id.
Instance Method Summary collapse
-
#found? ⇒ Boolean
True when the queried id exists (not status code -1).
Methods included from DeliveryStatus
#delivered?, #failed?, #pending?
Instance Attribute Details
#cost ⇒ Float? (readonly)
Returns 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_id ⇒ String (readonly)
Returns 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_code ⇒ Integer (readonly)
Returns 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_text ⇒ String (readonly)
Returns 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
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.
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) } |