Class: Imperium::HTTPClient
- Inherits:
-
Object
- Object
- Imperium::HTTPClient
- Defined in:
- lib/imperium/http_client.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #delete(path, query: {}) ⇒ Object
- #get(path, query: {}) ⇒ Object
-
#initialize(config) ⇒ HTTPClient
constructor
A new instance of HTTPClient.
- #put(path, value, query: {}) ⇒ Object
Constructor Details
#initialize(config) ⇒ HTTPClient
Returns a new instance of HTTPClient.
7 8 9 10 11 12 13 |
# File 'lib/imperium/http_client.rb', line 7 def initialize(config) @config = config @driver = ::HTTPClient.new @driver.connect_timeout = @config.connect_timeout @driver.send_timeout = @config.send_timeout @driver.receive_timeout = @config.receive_timeout end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/imperium/http_client.rb', line 5 def config @config end |
Instance Method Details
#delete(path, query: {}) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/imperium/http_client.rb', line 15 def delete(path, query: {}) wrapping_exceptions do url = config.url.join(path) url.query_values = query @driver.delete(url, header: build_request_headers) end end |
#get(path, query: {}) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/imperium/http_client.rb', line 23 def get(path, query: {}) wrapping_exceptions do url = config.url.join(path) url.query_values = query @driver.get(url, header: build_request_headers) end end |
#put(path, value, query: {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/imperium/http_client.rb', line 31 def put(path, value, query: {}) wrapping_exceptions do url = config.url.join(path) url.query_values = query if value.is_a?(String) @driver.put(url, body: value, header: build_request_headers) else @driver.put(url, body: JSON.generate(value), header: build_request_headers) end end end |