Class: TentClient::CycleHTTP
- Inherits:
-
Object
- Object
- TentClient::CycleHTTP
- Defined in:
- lib/tent-client/cycle_http.rb
Overview
Proxies to Faraday and cycles through server urls
until either non left or response status in the 200s or 400s
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#server_urls ⇒ Object
readonly
Returns the value of attribute server_urls.
Instance Method Summary collapse
- #http ⇒ Object
-
#initialize(client, &faraday_block) ⇒ CycleHTTP
constructor
A new instance of CycleHTTP.
- #method_missing(method_name, *args, &block) ⇒ Object
- #new_http ⇒ Object
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Constructor Details
#initialize(client, &faraday_block) ⇒ CycleHTTP
Returns a new instance of CycleHTTP.
7 8 9 10 11 |
# File 'lib/tent-client/cycle_http.rb', line 7 def initialize(client, &faraday_block) @faraday_block = faraday_block @client = client @server_urls = client.server_urls.dup end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/tent-client/cycle_http.rb', line 41 def method_missing(method_name, *args, &block) if http.respond_to?(method_name) http.send(method_name, *args, &block) else super end end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/tent-client/cycle_http.rb', line 6 def client @client end |
#server_urls ⇒ Object (readonly)
Returns the value of attribute server_urls.
6 7 8 |
# File 'lib/tent-client/cycle_http.rb', line 6 def server_urls @server_urls end |
Instance Method Details
#http ⇒ Object
19 20 21 |
# File 'lib/tent-client/cycle_http.rb', line 19 def http @http || new_http end |
#new_http ⇒ Object
13 14 15 16 17 |
# File 'lib/tent-client/cycle_http.rb', line 13 def new_http @http = Faraday.new(:url => server_urls.shift) do |f| @faraday_block.call(f) end end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
37 38 39 |
# File 'lib/tent-client/cycle_http.rb', line 37 def respond_to_missing?(method_name, include_private = false) http.respond_to?(method_name, include_private) end |