Class: SWD::Resource

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

Defined Under Namespace

Classes: Expired

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Resource

Returns a new instance of Resource.



8
9
10
11
12
13
14
# File 'lib/swd/resource.rb', line 8

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

Instance Method Details

#discover!(cache_options = {}) ⇒ Object



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

def discover!(cache_options = {})
  SWD.cache.fetch(cache_key, cache_options) do
    handle_response do
      SWD.http_client.get_content endpoint.to_s
    end
  end
end

#endpointObject



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

def endpoint
  SWD.url_builder.build [nil, host, 443, path, {
    :principal => principal,
    :service => service
  }.to_query, nil]
rescue URI::Error => e
  raise Exception.new(e.message)
end