Module: Groem::Marshal::Request::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
-
#load(input, klass = self) ⇒ Object
Load GNTP request into hash of: ‘environment’ => hash of environment (protocol, version, request_method, encryption data) ‘headers’ => hash of headers ‘notifications’ => hash of notifications keyed by name (REGISTER requests only, otherwise empty).
Methods included from Constants
#growlify_action, #growlify_key, included
Instance Method Details
#load(input, klass = self) ⇒ Object
Load GNTP request into hash of:
'environment' => hash of environment (protocol, version, request_method, encryption data)
'headers' => hash of headers
'notifications' => hash of notifications keyed by name (REGISTER requests only, otherwise empty)
Note that binary identifiers are resolved in both headers and notifications.
If passed an optional klass, will return klass.new(out), otherwise just the hash. By default it tries to use the including object’s class
Note entire GNTP message must be passed as input.
No semantic validation of input is done,
and all key values are stored as strings, not casted
Syntactic validation may be implemented in the future.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/groem/marshal.rb', line 78 def load(input, klass = self) env, hdrs, notifs = {}, {}, {} meth, notif_name, id, len, bin = 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) meth = env[(GNTP_REQUEST_METHOD_KEY)] when :headers parse_header(line, hdrs) when :notification_start notif_name = parse_notification_name(line) when :notification parse_notification_header(line, notif_name, notifs) when :identifier_start id = parse_identifier(line) when :identifier_length len = parse_identifier_length(line) when :binary bin = \ (1..len).inject('') do |memo, i| memo << s.getch; memo end resolve_binary_key(id, bin, hdrs) resolve_binary_key(id, bin, notifs) end end out = { ENVIRONMENT_KEY => env, HEADERS_KEY => hdrs, NOTIFICATIONS_KEY => notifs } klass ? klass.new(out) : out end |