Class: OpenTransact::Server
- Inherits:
-
Object
- Object
- OpenTransact::Server
- 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
-
#options ⇒ Object
Returns the value of attribute options.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #consumer ⇒ Object
-
#host_meta ⇒ Object
returns host_meta xml document.
-
#host_meta_url ⇒ Object
returns the wellknown url for host-meta.
-
#initialize(options = {}) ⇒ Server
constructor
Create a server with the url option and optional key and secret.
-
#rel_link(rel) ⇒ Object
returns a rel link from host meta.
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=||{} @url=[:url] end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
9 10 11 |
# File 'lib/opentransact/server.rb', line 9 def @options end |
#url ⇒ Object
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 |
#consumer ⇒ Object
44 45 46 |
# File 'lib/opentransact/server.rb', line 44 def consumer @consumer ||= OAuth::Consumer.new @options[:key], @options[:secret], :site=>@url end |
#host_meta ⇒ Object
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 ||= begin request = Net::HTTP::Get.new(.path) http = Net::HTTP.new(.host, .port) http.use_ssl = (.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_url ⇒ Object
returns the wellknown url for host-meta
19 20 21 |
# File 'lib/opentransact/server.rb', line 19 def .to_s end |
#rel_link(rel) ⇒ Object
returns a rel link from host meta
36 37 38 |
# File 'lib/opentransact/server.rb', line 36 def rel_link(rel) ["Link"].detect{|l| l["rel"]==rel}["href"] if && ["Link"] end |