Class: SWD::Resource

Inherits:
Object
  • Object
show all
Includes:
AttrRequired
Defined in:
lib/swd/resource.rb

Defined Under Namespace

Classes: ContentExpired

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Resource

Returns a new instance of Resource.



14
15
16
17
18
19
20
21
# File 'lib/swd/resource.rb', line 14

def initialize(attributes = {})
  required_attributes.each do |key|
    self.send "#{key}=", attributes[key]
  end
  @path ||= '/.well-known/simple-web-discovery'
  @cache_options = attributes[:cache] || {}
  attr_missing!
end

Instance Method Details

#discover!Object



23
24
25
26
27
28
29
# File 'lib/swd/resource.rb', line 23

def discover!
  SWD.cache.fetch(cache_key, @cache_options) do
    handle_response do
      HTTPClient.get endpoint.to_s
    end
  end
end

#endpointObject



31
32
33
34
35
36
# File 'lib/swd/resource.rb', line 31

def endpoint
  URI::HTTPS.build [nil, host, 443, path, {
    :principal => principal,
    :service => service
  }.to_query, nil]
end