Class: OStatus2::Subscription
- Inherits:
-
Object
- Object
- OStatus2::Subscription
- Defined in:
- lib/ostatus2/subscription.rb
Instance Method Summary collapse
-
#initialize(topic_url, options = {}) ⇒ Subscription
constructor
A new instance of Subscription.
-
#subscribe ⇒ HTTP::Response
Subscribe to the topic via a specified hub.
-
#unsubscribe ⇒ HTTP::Response
Unsubscribe from the topic via a specified hub.
-
#valid?(topic_url) ⇒ Boolean
Check if the hub is responding to the right subscription request.
-
#verify(content, signature) ⇒ Boolean
Verify that the feed contents were meant for this subscription.
Constructor Details
#initialize(topic_url, options = {}) ⇒ Subscription
Returns a new instance of Subscription.
10 11 12 13 14 15 16 |
# File 'lib/ostatus2/subscription.rb', line 10 def initialize(topic_url, = {}) @topic_url = topic_url @webhook_url = [:webhook] || '' @secret = [:secret] || '' @lease_seconds = [:lease_seconds] || '' @hub = [:hub] || '' end |
Instance Method Details
#subscribe ⇒ HTTP::Response
Subscribe to the topic via a specified hub
22 23 24 |
# File 'lib/ostatus2/subscription.rb', line 22 def subscribe update_subscription(:subscribe) end |
#unsubscribe ⇒ HTTP::Response
Unsubscribe from the topic via a specified hub
30 31 32 |
# File 'lib/ostatus2/subscription.rb', line 30 def unsubscribe update_subscription(:unsubscribe) end |
#valid?(topic_url) ⇒ Boolean
Check if the hub is responding to the right subscription request
37 38 39 |
# File 'lib/ostatus2/subscription.rb', line 37 def valid?(topic_url) @topic_url == topic_url end |
#verify(content, signature) ⇒ Boolean
Verify that the feed contents were meant for this subscription
45 46 47 48 |
# File 'lib/ostatus2/subscription.rb', line 45 def verify(content, signature) hmac = OpenSSL::HMAC.hexdigest('sha1', @secret, content) signature.downcase == "sha1=#{hmac}" end |