Class: SmsRu::CostItem
- Inherits:
-
Object
- Object
- SmsRu::CostItem
- Defined in:
- lib/sms_ru/data.rb
Overview
Per-recipient cost (one entry of a /sms/cost response). ‘error_code`/`error_text` are populated only when this recipient cannot be priced.
Instance Attribute Summary collapse
-
#cost ⇒ Float?
readonly
The price for this recipient, or nil when it errored.
-
#error_code ⇒ Integer?
readonly
The error code, or nil when priced.
-
#error_text ⇒ String?
readonly
The error reason, or nil when priced.
-
#phone ⇒ String
readonly
The recipient’s phone number.
-
#sms_count ⇒ Integer?
readonly
The number of SMS segments, or nil when it errored.
Class Method Summary collapse
Instance Method Summary collapse
-
#ok? ⇒ Boolean
True when this recipient was priced successfully.
Instance Attribute Details
#cost ⇒ Float? (readonly)
Returns the price for this recipient, or nil when it errored.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/sms_ru/data.rb', line 115 class CostItem < Data.define(:phone, :cost, :sms_count, :error_code, :error_text) # @param phone [String] the recipient's phone number # @param hash [Hash] one entry of the response `sms` object # @return [SmsRu::CostItem] def self.build(phone, hash) ok = Coerce.string(hash["status"]) == "OK" new( phone: String(phone), cost: Coerce.float?(hash["cost"]), sms_count: Coerce.integer?(hash["sms"]), 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 priced successfully def ok? = error_code.nil? end |
#error_code ⇒ Integer? (readonly)
Returns the error code, or nil when priced.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/sms_ru/data.rb', line 115 class CostItem < Data.define(:phone, :cost, :sms_count, :error_code, :error_text) # @param phone [String] the recipient's phone number # @param hash [Hash] one entry of the response `sms` object # @return [SmsRu::CostItem] def self.build(phone, hash) ok = Coerce.string(hash["status"]) == "OK" new( phone: String(phone), cost: Coerce.float?(hash["cost"]), sms_count: Coerce.integer?(hash["sms"]), 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 priced successfully def ok? = error_code.nil? end |
#error_text ⇒ String? (readonly)
Returns the error reason, or nil when priced.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/sms_ru/data.rb', line 115 class CostItem < Data.define(:phone, :cost, :sms_count, :error_code, :error_text) # @param phone [String] the recipient's phone number # @param hash [Hash] one entry of the response `sms` object # @return [SmsRu::CostItem] def self.build(phone, hash) ok = Coerce.string(hash["status"]) == "OK" new( phone: String(phone), cost: Coerce.float?(hash["cost"]), sms_count: Coerce.integer?(hash["sms"]), 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 priced successfully def ok? = error_code.nil? end |
#phone ⇒ String (readonly)
Returns the recipient’s phone number.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/sms_ru/data.rb', line 115 class CostItem < Data.define(:phone, :cost, :sms_count, :error_code, :error_text) # @param phone [String] the recipient's phone number # @param hash [Hash] one entry of the response `sms` object # @return [SmsRu::CostItem] def self.build(phone, hash) ok = Coerce.string(hash["status"]) == "OK" new( phone: String(phone), cost: Coerce.float?(hash["cost"]), sms_count: Coerce.integer?(hash["sms"]), 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 priced successfully def ok? = error_code.nil? end |
#sms_count ⇒ Integer? (readonly)
Returns the number of SMS segments, or nil when it errored.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/sms_ru/data.rb', line 115 class CostItem < Data.define(:phone, :cost, :sms_count, :error_code, :error_text) # @param phone [String] the recipient's phone number # @param hash [Hash] one entry of the response `sms` object # @return [SmsRu::CostItem] def self.build(phone, hash) ok = Coerce.string(hash["status"]) == "OK" new( phone: String(phone), cost: Coerce.float?(hash["cost"]), sms_count: Coerce.integer?(hash["sms"]), 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 priced successfully def ok? = error_code.nil? end |
Class Method Details
.build(phone, hash) ⇒ SmsRu::CostItem
119 120 121 122 123 124 125 126 127 128 |
# File 'lib/sms_ru/data.rb', line 119 def self.build(phone, hash) ok = Coerce.string(hash["status"]) == "OK" new( phone: String(phone), cost: Coerce.float?(hash["cost"]), sms_count: Coerce.integer?(hash["sms"]), 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 priced successfully.
131 |
# File 'lib/sms_ru/data.rb', line 131 def ok? = error_code.nil? |