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.
-
#request_default_options ⇒ Object
Returns the value of attribute request_default_options.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Object
Provide login and password fields for basic HTTP authentication Provide request_default_options field for default options to be provided on each http request To set a default User-agent which identifies your application, provide { request_default_options: { header: { user_agent: ‘My great new App V.0.1 Contact: [email protected]’} } }.
- #request(verb, url, options = {}) ⇒ Object
Instance Attribute Details
#connection ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rapidash/http_client.rb', line 20 def connection raise ConfigurationError.new "Site is required" unless site @connection ||= Faraday.new(site) do |builder| if login || password builder.use Faraday::Request::BasicAuthentication, login, password end connection_builder.call(builder) end end |
#login ⇒ Object
Returns the value of attribute login.
7 8 9 |
# File 'lib/rapidash/http_client.rb', line 7 def login @login end |
#password ⇒ Object
Returns the value of attribute password.
7 8 9 |
# File 'lib/rapidash/http_client.rb', line 7 def password @password end |
#request_default_options ⇒ Object
Returns the value of attribute request_default_options.
7 8 9 |
# File 'lib/rapidash/http_client.rb', line 7 def @request_default_options end |
Instance Method Details
#initialize(options = {}) ⇒ Object
Provide login and password fields for basic HTTP authentication Provide request_default_options field for default options to be provided on each http request To set a default User-agent which identifies your application, provide { request_default_options: { header: { user_agent: ‘My great new App V.0.1 Contact: [email protected]’} } }
14 15 16 17 18 |
# File 'lib/rapidash/http_client.rb', line 14 def initialize( = {}) [:login, :password, :request_default_options].each do |key| self.send("#{key.to_s}=".to_sym, [key]) end end |
#request(verb, url, options = {}) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/rapidash/http_client.rb', line 32 def request(verb, url, = {}) .merge!(self.) if self. url = connection.build_url(normalize_url(url), [:params]).to_s response = connection.run_request(verb, url, [:body], [:header]) response.body end |