Class: SmsRu::Sms

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

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#error_codeInteger? (readonly)

Returns the rejection code, or nil when accepted.

Returns:

  • (Integer, nil)

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

Returns the rejection reason, or nil when accepted.

Returns:

  • (String, nil)

    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

#phoneString (readonly)

Returns the recipient’s phone number.

Returns:

  • (String)

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

Returns the message id assigned by SMS.ru (nil when rejected).

Returns:

  • (String, nil)

    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

Parameters:

  • phone (String)

    the recipient’s phone number

  • hash (Hash)

    one entry of the response ‘sms` object

Returns:



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.

Returns:

  • (Boolean)

    true when this recipient was accepted



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

def ok? = error_code.nil?