Class: Satori::RTM::BaseReply

Inherits:
Object
  • Object
show all
Defined in:
lib/satori-rtm-sdk/model.rb

Overview

Base RTM reply for a request.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, data) ⇒ BaseReply

Returns a new instance of BaseReply



73
74
75
76
77
78
79
80
81
# File 'lib/satori-rtm-sdk/model.rb', line 73

def initialize(type, data)
  if type == :pdu
    @type = data[:action].end_with?('/ok') ? :ok : :error
    @data = data[:body]
  else
    @type = type
    @data = data
  end
end

Instance Attribute Details

#dataHash (readonly)

Returns a reply data. It represent body field from reply PDUs from RTM. Information about fields in data could be found in RTM API specification.

Returns:

  • (Hash)

    event data



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/satori-rtm-sdk/model.rb', line 70

class BaseReply
  attr_reader :data, :type

  def initialize(type, data)
    if type == :pdu
      @type = data[:action].end_with?('/ok') ? :ok : :error
      @data = data[:body]
    else
      @type = type
      @data = data
    end
  end

  # Returns +true+ if a reply is positive
  #
  # @return [Boolean] +true+ if a reply is positive, +false+ otherwise
  def success?
    type == :ok
  end

  # Returns +true+ if a reply is not positive
  #
  # @return [Boolean] +true+ if a reply is not positive, +false+ otherwise
  def error?
    !success?
  end
end

#type:ok, ... (readonly)

Returns a type of reply.

Returns:

  • (:ok)

    when RTM positive reply is received

  • (:error)

    when RTM error is received

  • (:disconnect)

    when connection is lost



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/satori-rtm-sdk/model.rb', line 70

class BaseReply
  attr_reader :data, :type

  def initialize(type, data)
    if type == :pdu
      @type = data[:action].end_with?('/ok') ? :ok : :error
      @data = data[:body]
    else
      @type = type
      @data = data
    end
  end

  # Returns +true+ if a reply is positive
  #
  # @return [Boolean] +true+ if a reply is positive, +false+ otherwise
  def success?
    type == :ok
  end

  # Returns +true+ if a reply is not positive
  #
  # @return [Boolean] +true+ if a reply is not positive, +false+ otherwise
  def error?
    !success?
  end
end

Instance Method Details

#error?Boolean

Returns true if a reply is not positive

Returns:

  • (Boolean)

    true if a reply is not positive, false otherwise



93
94
95
# File 'lib/satori-rtm-sdk/model.rb', line 93

def error?
  !success?
end

#success?Boolean

Returns true if a reply is positive

Returns:

  • (Boolean)

    true if a reply is positive, false otherwise



86
87
88
# File 'lib/satori-rtm-sdk/model.rb', line 86

def success?
  type == :ok
end