Class: Satori::RTM::BaseReply
- Inherits:
-
Object
- Object
- Satori::RTM::BaseReply
- Defined in:
- lib/satori-rtm-sdk/model.rb
Overview
Base RTM reply for a request.
Instance Attribute Summary collapse
-
#data ⇒ Hash
readonly
Returns a reply data.
-
#type ⇒ :ok, ...
readonly
Returns a type of reply.
Instance Method Summary collapse
-
#error? ⇒ Boolean
Returns
true
if a reply is not positive. -
#initialize(type, data) ⇒ BaseReply
constructor
A new instance of BaseReply.
-
#success? ⇒ Boolean
Returns
true
if a reply is positive.
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
#data ⇒ Hash (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.
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.
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
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
86 87 88 |
# File 'lib/satori-rtm-sdk/model.rb', line 86 def success? type == :ok end |