Class: OpenTransact::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/opentransact/server.rb

Overview

This class initially maintains and creates the OAuth Consumer for a particular OAuth site. The idea though is for it to handle various other discovery related features

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Server

Create a server with the url option and optional key and secret



13
14
15
16
# File 'lib/opentransact/server.rb', line 13

def initialize(options={})
  @options=options||{}
  @url=options[:url]
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



9
10
11
# File 'lib/opentransact/server.rb', line 9

def options
  @options
end

#urlObject

Returns the value of attribute url.



9
10
11
# File 'lib/opentransact/server.rb', line 9

def url
  @url
end

Instance Method Details

#[](key) ⇒ Object



40
41
42
# File 'lib/opentransact/server.rb', line 40

def [](key)
  @options[key] if @options
end

#consumerObject



44
45
46
# File 'lib/opentransact/server.rb', line 44

def consumer
  @consumer ||= OAuth::Consumer.new @options[:key],  @options[:secret], :site=>@url
end

#host_metaObject

returns host_meta xml document



24
25
26
27
28
29
30
31
32
33
# File 'lib/opentransact/server.rb', line 24

def host_meta
  @host_meta ||= begin
    request = Net::HTTP::Get.new(host_meta_uri.path)
    http = Net::HTTP.new(host_meta_uri.host, host_meta_uri.port)
    http.use_ssl = (host_meta_uri.port==443)
    response = http.start {|http| http.request(request) }
    raise OpenTransact::UndiscoverableResource unless response.code=="200"
    MultiXml.parse(response.body)["XRD"]
  end
end

#host_meta_urlObject

returns the wellknown url for host-meta



19
20
21
# File 'lib/opentransact/server.rb', line 19

def host_meta_url
  host_meta_uri.to_s
end

returns a rel link from host meta



36
37
38
# File 'lib/opentransact/server.rb', line 36

def rel_link(rel)
  host_meta["Link"].detect{|l| l["rel"]==rel}["href"] if host_meta && host_meta["Link"]
end