Class: SmsRu::Sms
- Inherits:
-
Object
- Object
- SmsRu::Sms
- Defined in:
- lib/sms_ru/data.rb
Overview
A single message inside a send response (one entry of the ‘sms` object). `error_code`/`error_text` are populated only when this recipient was rejected.
Instance Attribute Summary collapse
-
#error_code ⇒ Integer?
readonly
The rejection code, or nil when accepted.
-
#error_text ⇒ String?
readonly
The rejection reason, or nil when accepted.
-
#phone ⇒ String
readonly
The recipient’s phone number.
-
#sms_id ⇒ String?
readonly
The message id assigned by SMS.ru (nil when rejected).
Class Method Summary collapse
Instance Method Summary collapse
-
#ok? ⇒ Boolean
True when this recipient was accepted.
Instance Attribute Details
#error_code ⇒ Integer? (readonly)
Returns the rejection code, or nil when accepted.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/sms_ru/data.rb', line 30 class Sms < Data.define(:phone, :sms_id, :error_code, :error_text) # @param phone [String] the recipient's phone number # @param hash [Hash] one entry of the response `sms` object # @return [SmsRu::Sms] def self.build(phone, hash) ok = Coerce.string(hash["status"]) == "OK" new( phone: String(phone), sms_id: Coerce.string?(hash["sms_id"]), error_code: ok ? nil : Coerce.integer(hash["status_code"]), error_text: ok ? nil : Coerce.string(hash["status_text"]) ) end # @return [Boolean] true when this recipient was accepted def ok? = error_code.nil? end |
#error_text ⇒ String? (readonly)
Returns the rejection reason, or nil when accepted.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/sms_ru/data.rb', line 30 class Sms < Data.define(:phone, :sms_id, :error_code, :error_text) # @param phone [String] the recipient's phone number # @param hash [Hash] one entry of the response `sms` object # @return [SmsRu::Sms] def self.build(phone, hash) ok = Coerce.string(hash["status"]) == "OK" new( phone: String(phone), sms_id: Coerce.string?(hash["sms_id"]), error_code: ok ? nil : Coerce.integer(hash["status_code"]), error_text: ok ? nil : Coerce.string(hash["status_text"]) ) end # @return [Boolean] true when this recipient was accepted def ok? = error_code.nil? end |
#phone ⇒ String (readonly)
Returns the recipient’s phone number.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/sms_ru/data.rb', line 30 class Sms < Data.define(:phone, :sms_id, :error_code, :error_text) # @param phone [String] the recipient's phone number # @param hash [Hash] one entry of the response `sms` object # @return [SmsRu::Sms] def self.build(phone, hash) ok = Coerce.string(hash["status"]) == "OK" new( phone: String(phone), sms_id: Coerce.string?(hash["sms_id"]), error_code: ok ? nil : Coerce.integer(hash["status_code"]), error_text: ok ? nil : Coerce.string(hash["status_text"]) ) end # @return [Boolean] true when this recipient was accepted def ok? = error_code.nil? end |
#sms_id ⇒ String? (readonly)
Returns the message id assigned by SMS.ru (nil when rejected).
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/sms_ru/data.rb', line 30 class Sms < Data.define(:phone, :sms_id, :error_code, :error_text) # @param phone [String] the recipient's phone number # @param hash [Hash] one entry of the response `sms` object # @return [SmsRu::Sms] def self.build(phone, hash) ok = Coerce.string(hash["status"]) == "OK" new( phone: String(phone), sms_id: Coerce.string?(hash["sms_id"]), error_code: ok ? nil : Coerce.integer(hash["status_code"]), error_text: ok ? nil : Coerce.string(hash["status_text"]) ) end # @return [Boolean] true when this recipient was accepted def ok? = error_code.nil? end |
Class Method Details
.build(phone, hash) ⇒ SmsRu::Sms
34 35 36 37 38 39 40 41 42 |
# File 'lib/sms_ru/data.rb', line 34 def self.build(phone, hash) ok = Coerce.string(hash["status"]) == "OK" new( phone: String(phone), sms_id: Coerce.string?(hash["sms_id"]), error_code: ok ? nil : Coerce.integer(hash["status_code"]), error_text: ok ? nil : Coerce.string(hash["status_text"]) ) end |
Instance Method Details
#ok? ⇒ Boolean
Returns true when this recipient was accepted.
45 |
# File 'lib/sms_ru/data.rb', line 45 def ok? = error_code.nil? |