Class: SmsRu::CostItem

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#costFloat? (readonly)

Returns the price for this recipient, or nil when it errored.

Returns:

  • (Float, nil)

    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_codeInteger? (readonly)

Returns the error code, or nil when priced.

Returns:

  • (Integer, nil)

    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_textString? (readonly)

Returns the error reason, or nil when priced.

Returns:

  • (String, nil)

    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

#phoneString (readonly)

Returns the recipient’s phone number.

Returns:

  • (String)

    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_countInteger? (readonly)

Returns the number of SMS segments, or nil when it errored.

Returns:

  • (Integer, nil)

    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

Parameters:

  • phone (String)

    the recipient’s phone number

  • hash (Hash)

    one entry of the response ‘sms` object

Returns:



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.

Returns:

  • (Boolean)

    true when this recipient was priced successfully



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

def ok? = error_code.nil?