Class: Groem::Response
- Inherits:
-
Struct
- Object
- Struct
- Groem::Response
- Extended by:
- Forwardable
- Includes:
- Marshal::Response
- Defined in:
- lib/groem/response.rb
Constant Summary
Constants included from Constants
Constants::ENVIRONMENT_KEY, Constants::GNTP_APPLICATION_ICON_KEY, Constants::GNTP_APPLICATION_NAME_KEY, Constants::GNTP_CALLBACK_RESPONSE, Constants::GNTP_CLICK_CALLBACK_RESULT, Constants::GNTP_CLOSE_CALLBACK_RESULT, Constants::GNTP_DEFAULT_ENVIRONMENT, Constants::GNTP_ENCRYPTION_ID_KEY, Constants::GNTP_ERROR_CODE_KEY, Constants::GNTP_ERROR_CODE_OK, Constants::GNTP_ERROR_RESPONSE, Constants::GNTP_NOTIFICATION_CALLBACK_CONTEXT_KEY, Constants::GNTP_NOTIFICATION_CALLBACK_CONTEXT_TYPE_KEY, Constants::GNTP_NOTIFICATION_CALLBACK_RESULT_KEY, Constants::GNTP_NOTIFICATION_CALLBACK_TARGET_KEY, Constants::GNTP_NOTIFICATION_CALLBACK_TIMESTAMP_KEY, Constants::GNTP_NOTIFICATION_COUNT_KEY, Constants::GNTP_NOTIFICATION_ICON_KEY, Constants::GNTP_NOTIFICATION_ID_KEY, Constants::GNTP_NOTIFICATION_NAME_KEY, Constants::GNTP_NOTIFY_METHOD, Constants::GNTP_OK_RESPONSE, Constants::GNTP_PROTOCOL_KEY, Constants::GNTP_REGISTER_METHOD, Constants::GNTP_REQUEST_METHOD_KEY, Constants::GNTP_RESPONSE_ACTION_KEY, Constants::GNTP_RESPONSE_METHOD_KEY, Constants::GNTP_SUBSCRIBE_METHOD, Constants::GNTP_TIMEDOUT_CALLBACK_RESULT, Constants::GNTP_VERSION_KEY, Constants::HEADERS_KEY, Constants::NOTIFICATIONS_KEY
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#callback_result ⇒ Object
Returns the value of attribute callback_result.
-
#context ⇒ Object
Returns the value of attribute context.
-
#context_type ⇒ Object
Returns the value of attribute context_type.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#method ⇒ Object
Returns the value of attribute method.
-
#notification_id ⇒ Object
Returns the value of attribute notification_id.
-
#status ⇒ Object
Returns the value of attribute status.
Instance Method Summary collapse
- #callback?(&blk) ⇒ Boolean
- #callback_route ⇒ Object
- #clicked?(&blk) ⇒ Boolean (also: #click?)
- #closed?(&blk) ⇒ Boolean (also: #close?)
- #error?(code = nil, &blk) ⇒ Boolean
-
#initialize(resp) ⇒ Response
constructor
A new instance of Response.
- #ok?(&blk) ⇒ Boolean
- #timedout?(&blk) ⇒ Boolean (also: #timeout?)
- #to_notify?(&blk) ⇒ Boolean
- #to_register?(&blk) ⇒ Boolean
Methods included from Marshal::Response
Methods included from Constants
#growlify_action, #growlify_key, included
Constructor Details
#initialize(resp) ⇒ Response
Returns a new instance of Response.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/groem/response.rb', line 17 def initialize(resp) @raw = resp self.status = resp[0] self.headers = resp[1] self.action = resp[1][GNTP_RESPONSE_ACTION_KEY] self.notification_id = resp[1][GNTP_NOTIFICATION_ID_KEY] self.context = resp[2][GNTP_NOTIFICATION_CALLBACK_CONTEXT_KEY] self.context_type = resp[2][GNTP_NOTIFICATION_CALLBACK_CONTEXT_TYPE_KEY] self.callback_result = resp[2][GNTP_NOTIFICATION_CALLBACK_RESULT_KEY] self.method = if self.status.to_i == 0 if self.callback_result GNTP_CALLBACK_RESPONSE else GNTP_OK_RESPONSE end else GNTP_ERROR_RESPONSE end end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action
4 5 6 |
# File 'lib/groem/response.rb', line 4 def action @action end |
#callback_result ⇒ Object
Returns the value of attribute callback_result
4 5 6 |
# File 'lib/groem/response.rb', line 4 def callback_result @callback_result end |
#context ⇒ Object
Returns the value of attribute context
4 5 6 |
# File 'lib/groem/response.rb', line 4 def context @context end |
#context_type ⇒ Object
Returns the value of attribute context_type
4 5 6 |
# File 'lib/groem/response.rb', line 4 def context_type @context_type end |
#headers ⇒ Object
Returns the value of attribute headers
4 5 6 |
# File 'lib/groem/response.rb', line 4 def headers @headers end |
#method ⇒ Object
Returns the value of attribute method
4 5 6 |
# File 'lib/groem/response.rb', line 4 def method @method end |
#notification_id ⇒ Object
Returns the value of attribute notification_id
4 5 6 |
# File 'lib/groem/response.rb', line 4 def notification_id @notification_id end |
#status ⇒ Object
Returns the value of attribute status
4 5 6 |
# File 'lib/groem/response.rb', line 4 def status @status end |
Instance Method Details
#callback?(&blk) ⇒ Boolean
53 54 55 |
# File 'lib/groem/response.rb', line 53 def callback? &blk yield_and_return_if self.method == GNTP_CALLBACK_RESPONSE, &blk end |
#callback_route ⇒ Object
37 38 39 |
# File 'lib/groem/response.rb', line 37 def callback_route [self.callback_result, self.context, self.context_type] end |
#clicked?(&blk) ⇒ Boolean Also known as: click?
62 63 64 |
# File 'lib/groem/response.rb', line 62 def clicked? &blk yield_and_return_if self.callback_result == GNTP_CLICK_CALLBACK_RESULT, &blk end |
#closed?(&blk) ⇒ Boolean Also known as: close?
66 67 68 |
# File 'lib/groem/response.rb', line 66 def closed? &blk yield_and_return_if self.callback_result == GNTP_CLOSE_CALLBACK_RESULT, &blk end |
#error?(code = nil, &blk) ⇒ Boolean
57 58 59 60 |
# File 'lib/groem/response.rb', line 57 def error?(code=nil, &blk) yield_and_return_if (self.method == GNTP_ERROR_RESPONSE && \ code.nil? || self.status == code), &blk end |
#ok?(&blk) ⇒ Boolean
49 50 51 |
# File 'lib/groem/response.rb', line 49 def ok? &blk yield_and_return_if self.method == GNTP_OK_RESPONSE, &blk end |
#timedout?(&blk) ⇒ Boolean Also known as: timeout?
70 71 72 |
# File 'lib/groem/response.rb', line 70 def timedout? &blk yield_and_return_if self.callback_result == GNTP_TIMEDOUT_CALLBACK_RESULT, &blk end |
#to_notify?(&blk) ⇒ Boolean
45 46 47 |
# File 'lib/groem/response.rb', line 45 def to_notify? &blk yield_and_return_if self.action == GNTP_NOTIFY_METHOD, &blk end |
#to_register?(&blk) ⇒ Boolean
41 42 43 |
# File 'lib/groem/response.rb', line 41 def to_register? &blk yield_and_return_if self.action == GNTP_REGISTER_METHOD, &blk end |