Class: Hootenanny::Verification
- Inherits:
-
Object
- Object
- Hootenanny::Verification
- Defined in:
- lib/hootenanny/verification.rb
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#requester_token ⇒ Object
readonly
Returns the value of attribute requester_token.
-
#topic ⇒ Object
readonly
Returns the value of attribute topic.
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ Verification
constructor
A new instance of Verification.
-
#response ⇒ Object
Private: Attempts to verify the URI which has been requested to receive topic feed updates.
-
#uri ⇒ Object
Private: Constructs a PubSubHubbub compliant verification URI.
-
#verified? ⇒ Boolean
Private: Identifies whether the originating system has verified the verification.
Constructor Details
#initialize(attrs = {}) ⇒ Verification
Returns a new instance of Verification.
21 22 23 24 25 26 |
# File 'lib/hootenanny/verification.rb', line 21 def initialize(attrs = {}) self.base_url = attrs.fetch(:url) self.topic = attrs.fetch(:topic) self.mode = attrs.fetch(:mode) self.requester_token = attrs.fetch(:requester_token, nil) end |
Instance Attribute Details
#base_url ⇒ Object
Returns the value of attribute base_url.
16 17 18 |
# File 'lib/hootenanny/verification.rb', line 16 def base_url @base_url end |
#mode ⇒ Object
Returns the value of attribute mode.
16 17 18 |
# File 'lib/hootenanny/verification.rb', line 16 def mode @mode end |
#requester_token ⇒ Object
Returns the value of attribute requester_token.
16 17 18 |
# File 'lib/hootenanny/verification.rb', line 16 def requester_token @requester_token end |
#topic ⇒ Object
Returns the value of attribute topic.
16 17 18 |
# File 'lib/hootenanny/verification.rb', line 16 def topic @topic end |
Instance Method Details
#response ⇒ Object
Private: Attempts to verify the URI which has been requested to receive topic feed updates.
Returns a Faraday::Response
50 51 52 |
# File 'lib/hootenanny/verification.rb', line 50 def response @response ||= Faraday.get(uri.to_s) end |
#uri ⇒ Object
Private: Constructs a PubSubHubbub compliant verification URI
-
Parameters which exist in the base_url must not be overwritten by verification parameters even if they are of the same name. For example:
example.com?hub.mode=foo&hub.mode=subscribe
not
Returns a URI Raises a Hootenanny::URI::InvalidError if the base_url is not a valid URI
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/hootenanny/verification.rb', line 69 def uri @uri ||= -> do uri = base_url params = ::URI.encode_www_form(parameters) uri.query = [uri.query, params].compact.join('&') uri end.call end |
#verified? ⇒ Boolean
Private: Identifies whether the originating system has verified the verification.
This involves not only checking to see whether the system itself confirms it but also by verifying that the response from the originating system contains the challenge code sent to it.
Returns a TrueClass or FalseClass
38 39 40 41 42 |
# File 'lib/hootenanny/verification.rb', line 38 def verified? return false unless response.body == challenge response.success? end |