Class: TentClient::Discovery
- Inherits:
-
Object
- Object
- TentClient::Discovery
- Defined in:
- lib/tent-client/discovery.rb
Constant Summary collapse
- META_POST_REL =
"https://tent.io/rels/meta-post".freeze
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#entity_uri ⇒ Object
readonly
Returns the value of attribute entity_uri.
-
#last_response ⇒ Object
Returns the value of attribute last_response.
Class Method Summary collapse
Instance Method Summary collapse
- #discover(options = {}) ⇒ Object
-
#initialize(client, entity_uri, options = {}) ⇒ Discovery
constructor
A new instance of Discovery.
Constructor Details
#initialize(client, entity_uri, options = {}) ⇒ Discovery
Returns a new instance of Discovery.
19 20 21 22 23 24 |
# File 'lib/tent-client/discovery.rb', line 19 def initialize(client, entity_uri, = {}) @entity_uri = entity_uri @client = client.dup @client.faraday_adapter = :net_http @options = end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
17 18 19 |
# File 'lib/tent-client/discovery.rb', line 17 def client @client end |
#entity_uri ⇒ Object (readonly)
Returns the value of attribute entity_uri.
17 18 19 |
# File 'lib/tent-client/discovery.rb', line 17 def entity_uri @entity_uri end |
#last_response ⇒ Object
Returns the value of attribute last_response.
18 19 20 |
# File 'lib/tent-client/discovery.rb', line 18 def last_response @last_response end |
Class Method Details
.discover(client, entity_uri, options = {}) ⇒ Object
13 14 15 |
# File 'lib/tent-client/discovery.rb', line 13 def self.discover(client, entity_uri, = {}) new(client, entity_uri, :skip_serialization => false).discover() end |
Instance Method Details
#discover(options = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/tent-client/discovery.rb', line 26 def discover( = {}) discover_res, = perform_head_discovery || perform_get_discovery if .empty? return [:return_response] ? last_response : nil end .uniq.each do |url| url = URI.join(discover_res.env[:url].to_s, url).to_s begin res = http.get(url) do |request| request.headers['Accept'] = POST_CONTENT_TYPE % "https://tent.io/types/meta/v0#" end rescue Faraday::Error::TimeoutError, Faraday::Error::ConnectionFailed res = Faraday::Response.new({}) end if [:return_response] return res elsif res.success? && (Hash === res.body) return res.body['post'] end end nil end |