Class: SWD::Resource

Inherits:
Object
  • Object
show all
Includes:
AttrOptional, 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.



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

def initialize(attributes = {})
  (optional_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



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

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

#endpointObject



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

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