Class: Pubsubhubbub4r::Client
- Inherits:
-
Object
- Object
- Pubsubhubbub4r::Client
- Defined in:
- lib/pubsubhubbub4r/client.rb
Constant Summary collapse
- HTTP_TIMEOUT =
60
Instance Attribute Summary collapse
-
#cache ⇒ Object
Returns the value of attribute cache.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#post_data_overrides ⇒ Object
Returns the value of attribute post_data_overrides.
Instance Method Summary collapse
-
#initialize(cache, logger = nil, headers = nil, post_data_overrides = nil) ⇒ Client
constructor
A new instance of Client.
- #subscribe(hub_url, topic, callback_url, lease_seconds = 2592000, ack_timeout_seconds = 86400) ⇒ Object
- #unsubscribe(hub_url, topic, callback_url, lease_seconds = 2592000, ack_timeout_seconds = 86400) ⇒ Object
- #verify(params) ⇒ Object
Constructor Details
#initialize(cache, logger = nil, headers = nil, post_data_overrides = nil) ⇒ Client
Returns a new instance of Client.
12 13 14 15 16 17 18 19 |
# File 'lib/pubsubhubbub4r/client.rb', line 12 def initialize(cache, logger = nil, headers = nil, post_data_overrides = nil) # "cache" and "logger" must respond like Rails.cache / Rails.logger @cache = cache @logger = logger @headers = headers # e.g. {'hub.verify' => 'sync'} @post_data_overrides = post_data_overrides end |
Instance Attribute Details
#cache ⇒ Object
Returns the value of attribute cache.
10 11 12 |
# File 'lib/pubsubhubbub4r/client.rb', line 10 def cache @cache end |
#headers ⇒ Object
Returns the value of attribute headers.
10 11 12 |
# File 'lib/pubsubhubbub4r/client.rb', line 10 def headers @headers end |
#logger ⇒ Object
Returns the value of attribute logger.
10 11 12 |
# File 'lib/pubsubhubbub4r/client.rb', line 10 def logger @logger end |
#post_data_overrides ⇒ Object
Returns the value of attribute post_data_overrides.
10 11 12 |
# File 'lib/pubsubhubbub4r/client.rb', line 10 def post_data_overrides @post_data_overrides end |
Instance Method Details
#subscribe(hub_url, topic, callback_url, lease_seconds = 2592000, ack_timeout_seconds = 86400) ⇒ Object
21 22 23 |
# File 'lib/pubsubhubbub4r/client.rb', line 21 def subscribe(hub_url, topic, callback_url, lease_seconds = 2592000, ack_timeout_seconds = 86400) post('subscribe', hub_url, topic, callback_url, lease_seconds, ack_timeout_seconds) end |
#unsubscribe(hub_url, topic, callback_url, lease_seconds = 2592000, ack_timeout_seconds = 86400) ⇒ Object
25 26 27 |
# File 'lib/pubsubhubbub4r/client.rb', line 25 def unsubscribe(hub_url, topic, callback_url, lease_seconds = 2592000, ack_timeout_seconds = 86400) post('unsubscribe', hub_url, topic, callback_url, lease_seconds, ack_timeout_seconds) end |
#verify(params) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/pubsubhubbub4r/client.rb', line 29 def verify(params) cache_key = verification_cache_key(params['hub.verify_token']) cached_secret = self.cache.read(cache_key) new_secret = verification_secret(params['hub.mode'], params['hub.topic']) self.logger.debug "verifying #{cache_key.inspect}: #{cached_secret.inspect} vs #{new_secret.inspect}" if self.logger if cached_secret && cached_secret == new_secret self.cache.delete(cache_key) params['hub.challenge'] else false end end |