Class: Hootenanny::Verification

Inherits:
Object
  • Object
show all
Defined in:
lib/hootenanny/verification.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_urlObject

Returns the value of attribute base_url.



16
17
18
# File 'lib/hootenanny/verification.rb', line 16

def base_url
  @base_url
end

#modeObject

Returns the value of attribute mode.



16
17
18
# File 'lib/hootenanny/verification.rb', line 16

def mode
  @mode
end

#requester_tokenObject

Returns the value of attribute requester_token.



16
17
18
# File 'lib/hootenanny/verification.rb', line 16

def requester_token
  @requester_token
end

#topicObject

Returns the value of attribute topic.



16
17
18
# File 'lib/hootenanny/verification.rb', line 16

def topic
  @topic
end

Instance Method Details

#responseObject

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

#uriObject

Private: Constructs a PubSubHubbub compliant verification URI

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

Returns:

  • (Boolean)


38
39
40
41
42
# File 'lib/hootenanny/verification.rb', line 38

def verified?
  return false unless response.body == challenge

  response.success?
end