Module: Groem::Marshal::Response::ClassMethods

Includes:
Constants
Defined in:
lib/groem/marshal.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 Method Summary collapse

Methods included from Constants

#growlify_action, #growlify_key, included

Instance Method Details

#load(input, klass = self) ⇒ Object

Load GNTP response into array of:

status  (error code or '0' for OK) 
hash of headers  (except error code and notification-callback-*)
hash of callback headers (for callback responses, otherwise {})

Note this is explicitly modeled after Rack’s interface



265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# File 'lib/groem/marshal.rb', line 265

def load(input, klass = self)
  env, hdrs, cb_hdrs = {}, {}, {}
  status, meth = nil
  section = :init
  s = StringScanner.new(input)
  until s.eos?
    line, section = scan_line(s, meth, section)
    case section
    when :first
      parse_first_header(line, env)
    when :headers
      parse_header(line, hdrs)
    end
  end
  
  # pull out status from headers

  status = hdrs.delete(GNTP_ERROR_CODE_KEY)
  status ||= GNTP_ERROR_CODE_OK
  
  # pull out notification-callback-* from headers

  [GNTP_NOTIFICATION_CALLBACK_CONTEXT_KEY,
   GNTP_NOTIFICATION_CALLBACK_CONTEXT_TYPE_KEY,
   GNTP_NOTIFICATION_CALLBACK_RESULT_KEY,
   GNTP_NOTIFICATION_CALLBACK_TIMESTAMP_KEY].each do |key|
    if val = hdrs.delete(key)
      cb_hdrs[key] = val
    end
  end
  
  out = [ status, hdrs, cb_hdrs ]
        
  klass ? klass.new(out) : out
end