Module: HyperResource::Modules::HTTP
- Included in:
- HyperResource
- Defined in:
- lib/hyper_resource/modules/http.rb
Instance Method Summary collapse
-
#faraday_connection(url = nil) ⇒ Object
Returns a per-thread Faraday connection for this object.
-
#get ⇒ Object
Loads and returns the resource pointed to by
href.
Instance Method Details
#faraday_connection(url = nil) ⇒ Object
Returns a per-thread Faraday connection for this object.
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/hyper_resource/modules/http.rb', line 16 def faraday_connection(url=nil) url ||= self.root key = "faraday_connection_#{url}" return Thread.current[key] if Thread.current[key] fc = Faraday.new(:url => url) fc.headers.merge!('User-Agent' => "HyperResource #{HyperResource::VERSION}") fc.headers.merge!(self.headers || {}) if ba=self.auth[:basic] fc.basic_auth(*ba) end Thread.current[key] = fc end |
#get ⇒ Object
Loads and returns the resource pointed to by href. The returned
resource will be blessed into its "proper" class, if
self.class.namespace != nil.
10 11 12 13 |
# File 'lib/hyper_resource/modules/http.rb', line 10 def get self.response = faraday_connection.get(self.href || '') finish_up end |