Class: OSub::Subscription
- Inherits:
-
Object
- Object
- OSub::Subscription
- Defined in:
- lib/osub/subscription.rb
Instance Attribute Summary collapse
-
#callback_url ⇒ Object
readonly
Returns the value of attribute callback_url.
-
#topic_url ⇒ Object
readonly
Returns the value of attribute topic_url.
Instance Method Summary collapse
- #change_subscription(mode, hub_url, async, token) ⇒ Object
-
#hubs ⇒ Object
Actively searches for hubs by talking to publisher directly.
-
#initialize(callback_url, topic_url, secret = nil, token = nil) ⇒ Subscription
constructor
A new instance of Subscription.
- #perform_challenge(challenge_code) ⇒ Object
-
#subscribe(hub_url, async = false, token = nil) ⇒ Object
Subscribe to the topic through the given hub.
-
#unsubscribe(hub_url, async = false, token = nil) ⇒ Object
Unsubscribe to the topic through the given hub.
- #verify_content(body, signature) ⇒ Object
- #verify_subscription(token) ⇒ Object
Constructor Details
#initialize(callback_url, topic_url, secret = nil, token = nil) ⇒ Subscription
Returns a new instance of Subscription.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/osub/subscription.rb', line 12 def initialize(callback_url, topic_url, secret = nil, token = nil) @tokens = [] if token != nil @tokens << token end secret = "" if secret == nil @secret = secret.to_s @callback_url = callback_url @topic_url = topic_url end |
Instance Attribute Details
#callback_url ⇒ Object (readonly)
Returns the value of attribute callback_url.
9 10 11 |
# File 'lib/osub/subscription.rb', line 9 def callback_url @callback_url end |
#topic_url ⇒ Object (readonly)
Returns the value of attribute topic_url.
10 11 12 |
# File 'lib/osub/subscription.rb', line 10 def topic_url @topic_url end |
Instance Method Details
#change_subscription(mode, hub_url, async, token) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/osub/subscription.rb', line 46 def change_subscription(mode, hub_url, async, token) res = Net::HTTP.post_form(URI.parse(hub_url), { 'hub.mode' => mode.to_s, 'hub.callback' => @callback_url, 'hub.verify' => async ? 'async' : 'sync', 'hub.verify_token' => token, 'hub.lease_seconds' => '', 'hub.secret' => @secret, 'hub.topic' => @topic_url}) end |
#hubs ⇒ Object
Actively searches for hubs by talking to publisher directly
26 27 28 |
# File 'lib/osub/subscription.rb', line 26 def hubs OStatus::Feed.from_url(topic_url).hubs end |
#perform_challenge(challenge_code) ⇒ Object
70 71 72 |
# File 'lib/osub/subscription.rb', line 70 def perform_challenge(challenge_code) {:body => challenge_code, :status => 200} end |
#subscribe(hub_url, async = false, token = nil) ⇒ Object
Subscribe to the topic through the given hub.
31 32 33 34 35 36 |
# File 'lib/osub/subscription.rb', line 31 def subscribe(hub_url, async = false, token = nil) if token != nil @tokens << token.to_s end change_subscription(:subscribe, hub_url, async, token) end |
#unsubscribe(hub_url, async = false, token = nil) ⇒ Object
Unsubscribe to the topic through the given hub.
39 40 41 42 43 44 |
# File 'lib/osub/subscription.rb', line 39 def unsubscribe(hub_url, async = false, token = nil) if token != nil @tokens << token.to_s end change_subscription(:unsubscribe, hub_url, async, token) end |
#verify_content(body, signature) ⇒ Object
64 65 66 67 68 |
# File 'lib/osub/subscription.rb', line 64 def verify_content(body, signature) hmac = HMAC::SHA1.hexdigest(@secret, body) check = "sha1=" + hmac check == signature end |
#verify_subscription(token) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/osub/subscription.rb', line 57 def verify_subscription(token) result = @tokens.index(token) != nil @tokens.delete(token) result end |