Module: Rapidash::HTTPClient
- Defined in:
- lib/rapidash/http_client.rb
Instance Attribute Summary collapse
- #connection ⇒ Object
-
#login ⇒ Object
Returns the value of attribute login.
-
#password ⇒ Object
Returns the value of attribute password.
Instance Method Summary collapse
- #initialize(options = {}) ⇒ Object
- #process_response(response, verb, options) ⇒ Object
- #request(verb, url, options = {}) ⇒ Object
Instance Attribute Details
#connection ⇒ Object
14 15 16 17 |
# File 'lib/rapidash/http_client.rb', line 14 def connection raise ConfigurationError.new "Site is required" unless site @connection ||= Faraday.new(site) end |
#login ⇒ Object
Returns the value of attribute login.
5 6 7 |
# File 'lib/rapidash/http_client.rb', line 5 def login @login end |
#password ⇒ Object
Returns the value of attribute password.
5 6 7 |
# File 'lib/rapidash/http_client.rb', line 5 def password @password end |
Instance Method Details
#initialize(options = {}) ⇒ Object
8 9 10 11 12 |
# File 'lib/rapidash/http_client.rb', line 8 def initialize( = {}) [:login, :password].each do |key| self.send("#{key.to_s}=".to_sym, [key]) end end |
#process_response(response, verb, options) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rapidash/http_client.rb', line 28 def process_response(response, verb, ) # "foo"[0] does not work in 1.8.7, "foo"[0,1] is required case response.status.to_s[0, 1] when "5", "4" error = ResponseError.new(response) raise error if self.class.respond_to?(:raise_error) && self.class.raise_error return nil #Handle redirects when "3" request(verb, response.headers["location"], ) when "2" return Response.new(response) end end |
#request(verb, url, options = {}) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/rapidash/http_client.rb', line 19 def request(verb, url, = {}) url = connection.build_url(normalize_url(url), [:params]).to_s response = connection.run_request verb, url, [:body], [:header] do |request| request.headers.update(:Authorization => connection.basic_auth(login, password)) if login && password end process_response(response, verb, ) end |