Class: ActionTexter::Response Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/action_texter/response.rb

Overview

This class is abstract.

A response as sent from the provider.

Direct Known Subclasses

NexmoResponse, TestResponse, TwilioResponse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ Response

Returns a new instance of Response.


16
17
18
19
# File 'lib/action_texter/response.rb', line 16

def initialize(raw)
  @raw = raw
  process_response(raw)
end

Instance Attribute Details

#error_messageString

Returns a descriptive message of the error when an error happened.

Returns:

  • (String)

    a descriptive message of the error when an error happened.


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/action_texter/response.rb', line 13

class ActionTexter::Response
  attr_reader :raw, :success, :error_message

  def initialize(raw)
    @raw = raw
    process_response(raw)
  end

  # @return [Boolean] true when sending the message succeeded, false otherwise.
  def success?
    !!@success
  end

  # @return [Boolean] false when sending the message failed, true otherwise.
  def failed?
    !@success
  end

  # @private
  def to_s
    "#<#{self.class.name}:#{object_id}:#{@success ? "success" : "fail"}>"
  end

  private

  def process_response(raw)
    raise NotImplementedError.new("should be implemented by subclasses")
  end
end

#rawString (readonly)

Returns the raw response as returned by the provider.

Returns:

  • (String)

    the raw response as returned by the provider


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/action_texter/response.rb', line 13

class ActionTexter::Response
  attr_reader :raw, :success, :error_message

  def initialize(raw)
    @raw = raw
    process_response(raw)
  end

  # @return [Boolean] true when sending the message succeeded, false otherwise.
  def success?
    !!@success
  end

  # @return [Boolean] false when sending the message failed, true otherwise.
  def failed?
    !@success
  end

  # @private
  def to_s
    "#<#{self.class.name}:#{object_id}:#{@success ? "success" : "fail"}>"
  end

  private

  def process_response(raw)
    raise NotImplementedError.new("should be implemented by subclasses")
  end
end

#successBoolean

Returns weather sending the message succeeded or not. See #success? and #failed?.

Returns:

  • (Boolean)

    weather sending the message succeeded or not. See #success? and #failed?


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/action_texter/response.rb', line 13

class ActionTexter::Response
  attr_reader :raw, :success, :error_message

  def initialize(raw)
    @raw = raw
    process_response(raw)
  end

  # @return [Boolean] true when sending the message succeeded, false otherwise.
  def success?
    !!@success
  end

  # @return [Boolean] false when sending the message failed, true otherwise.
  def failed?
    !@success
  end

  # @private
  def to_s
    "#<#{self.class.name}:#{object_id}:#{@success ? "success" : "fail"}>"
  end

  private

  def process_response(raw)
    raise NotImplementedError.new("should be implemented by subclasses")
  end
end

Instance Method Details

#failed?Boolean

Returns false when sending the message failed, true otherwise.

Returns:

  • (Boolean)

    false when sending the message failed, true otherwise.


27
28
29
# File 'lib/action_texter/response.rb', line 27

def failed?
  !@success
end

#success?Boolean

Returns true when sending the message succeeded, false otherwise.

Returns:

  • (Boolean)

    true when sending the message succeeded, false otherwise.


22
23
24
# File 'lib/action_texter/response.rb', line 22

def success?
  !!@success
end

#to_sObject


32
33
34
# File 'lib/action_texter/response.rb', line 32

def to_s
  "#<#{self.class.name}:#{object_id}:#{@success ? "success" : "fail"}>"
end