Class: Hootenanny::Request::Subscription
- Inherits:
-
Hootenanny::Request
- Object
- Hootenanny::Request
- Hootenanny::Request::Subscription
- Defined in:
- lib/hootenanny/request/subscription.rb
Instance Attribute Summary collapse
-
#digest_secret ⇒ Object
readonly
Returns the value of attribute digest_secret.
-
#lease_duration ⇒ Object
readonly
Returns the value of attribute lease_duration.
-
#requester_token ⇒ Object
readonly
Returns the value of attribute requester_token.
-
#subscriber ⇒ Object
readonly
Returns the value of attribute subscriber.
-
#topic ⇒ Object
readonly
Returns the value of attribute topic.
-
#verification_class ⇒ Object
readonly
Returns the value of attribute verification_class.
Attributes inherited from Hootenanny::Request
Class Method Summary collapse
-
.build(options = {}) ⇒ Object
Private: Builds a subscription request object based on the options passed in.
Instance Method Summary collapse
-
#apply ⇒ Object
Private: Applies the subscription that the request is asking for.
-
#initialize(options = {}) ⇒ Subscription
constructor
A new instance of Subscription.
- #verification ⇒ Object
- #verified? ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ Subscription
Returns a new instance of Subscription.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/hootenanny/request/subscription.rb', line 16 def initialize( = {}) self.subscriber = .fetch(:subscriber) self.topic = .fetch(:topic) self.lease_duration = .fetch(:lease_duration) self.requester_token = .fetch(:requester_token, nil) self.digest_secret = .fetch(:secret, nil) self.verification_class = .fetch(:verification_class, Hootenanny::Verification) rescue KeyError => e raise Hootenanny::Request::BuildError.wrap(e) end |
Instance Attribute Details
#digest_secret ⇒ Object
Returns the value of attribute digest_secret.
9 10 11 |
# File 'lib/hootenanny/request/subscription.rb', line 9 def digest_secret @digest_secret end |
#lease_duration ⇒ Object
Returns the value of attribute lease_duration.
9 10 11 |
# File 'lib/hootenanny/request/subscription.rb', line 9 def lease_duration @lease_duration end |
#requester_token ⇒ Object
Returns the value of attribute requester_token.
9 10 11 |
# File 'lib/hootenanny/request/subscription.rb', line 9 def requester_token @requester_token end |
#subscriber ⇒ Object
Returns the value of attribute subscriber.
9 10 11 |
# File 'lib/hootenanny/request/subscription.rb', line 9 def subscriber @subscriber end |
#topic ⇒ Object
Returns the value of attribute topic.
9 10 11 |
# File 'lib/hootenanny/request/subscription.rb', line 9 def topic @topic end |
#verification_class ⇒ Object
Returns the value of attribute verification_class.
9 10 11 |
# File 'lib/hootenanny/request/subscription.rb', line 9 def verification_class @verification_class end |
Class Method Details
.build(options = {}) ⇒ Object
Private: Builds a subscription request object based on the options passed in.
options - A Hash of options representing the subscription request that will
be built.
:subscriber - A String or Ruby URI representing the URI which
the topic updates will be sent to.
:topic - A String or Ruby URI representing the URI which
publish the activities for a given topic.
:requester_token - A String token sent from the requester which
they can use to identify the request on their
system (optional).
:digest_secret - A String token of no more than 200 bytes which
will be used during content distribution so
that the subscriber can verify that the request
is from the hub and not a undesired 3rd party
(optional).
:lease_duration - A Number representing the amount of time after
the subscription is created during which time
the subscription will be active. This is
a _request_ and may be overridden (optional).
Examples:
Hootenanny::Request::Subscription.build(callback: 'http://example.com',
topic: 'http://another.org')
# => <Hootenanny::Request::Subscription subscriber: 'http://example.com',
topic: 'http://another.org'>
Returns a Hootenanny::Request::Subscription Raises Hootenanny::Request::BuildError if there is a problem
63 64 65 66 67 68 69 70 |
# File 'lib/hootenanny/request/subscription.rb', line 63 def self.build( = {}) = () request = allocate request.send(:initialize, ) request end |
Instance Method Details
#apply ⇒ Object
Private: Applies the subscription that the request is asking for. It does this in an idempotent way. If the subscription being requested already exists, it is not modified but is instead retrieved and returned.
The request itself must be verified prior to the request being applied. An unverifiable request will raise a Hootenanny::SubscriptionError.
Example:
# If the request for the subscription is verified
subscription_request = Hootenanny::Request::Subscription.build(
callback: 'http://example.com',
topic: 'http://another.org')
subscription_request.apply
# => <Hootenanny::Subscription subscriber: 'http://example.com',
topic: 'http://another.org'>
# If the request for the subscription is unverifiable
subscription_request = Hootenanny::Request::Subscription.build(
callback: 'http://iamahacker.com',
topic: 'http://thisdoesnotexist.org')
subscription_request.apply
# => <Hootenanny::SubscriptionError>
Returns a Hootenanny::Subscription if the request is verified Raises Hootenanny::SubscriptionError if there is a problem
108 109 110 111 112 113 114 115 |
# File 'lib/hootenanny/request/subscription.rb', line 108 def apply raise Hootenanny::SubscriptionError.new('Request could not be verified.') unless verified? Hootenanny::Subscription.subscribe( subscriber: subscriber, to: topic, lease_duration: lease_duration, digest_secret: digest_secret) end |
#verification ⇒ Object
121 122 123 124 125 126 127 128 |
# File 'lib/hootenanny/request/subscription.rb', line 121 def verification @verification ||= verification_class.new( url: subscriber, mode: :subscribe, topic: topic, requester_token: requester_token, ) end |
#verified? ⇒ Boolean
117 118 119 |
# File 'lib/hootenanny/request/subscription.rb', line 117 def verified? verification.verified? end |