Class: Groem::Response

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

Instance Method Summary collapse

Methods included from Marshal::Response

#dump, included

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

#actionObject

Returns the value of attribute action

Returns:

  • (Object)

    the current value of action



4
5
6
# File 'lib/groem/response.rb', line 4

def action
  @action
end

#callback_resultObject

Returns the value of attribute callback_result

Returns:

  • (Object)

    the current value of callback_result



4
5
6
# File 'lib/groem/response.rb', line 4

def callback_result
  @callback_result
end

#contextObject

Returns the value of attribute context

Returns:

  • (Object)

    the current value of context



4
5
6
# File 'lib/groem/response.rb', line 4

def context
  @context
end

#context_typeObject

Returns the value of attribute context_type

Returns:

  • (Object)

    the current value of context_type



4
5
6
# File 'lib/groem/response.rb', line 4

def context_type
  @context_type
end

#headersObject

Returns the value of attribute headers

Returns:

  • (Object)

    the current value of headers



4
5
6
# File 'lib/groem/response.rb', line 4

def headers
  @headers
end

#methodObject

Returns the value of attribute method

Returns:

  • (Object)

    the current value of method



4
5
6
# File 'lib/groem/response.rb', line 4

def method
  @method
end

#notification_idObject

Returns the value of attribute notification_id

Returns:

  • (Object)

    the current value of notification_id



4
5
6
# File 'lib/groem/response.rb', line 4

def notification_id
  @notification_id
end

#statusObject

Returns the value of attribute status

Returns:

  • (Object)

    the current value of status



4
5
6
# File 'lib/groem/response.rb', line 4

def status
  @status
end

Instance Method Details

#callback?(&blk) ⇒ Boolean

Returns:

  • (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_routeObject



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?

Returns:

  • (Boolean)


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?

Returns:

  • (Boolean)


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

Returns:

  • (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

Returns:

  • (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?

Returns:

  • (Boolean)


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

Returns:

  • (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

Returns:

  • (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