Class: Astroapi::HTTP::Client
- Inherits:
-
Object
- Object
- Astroapi::HTTP::Client
- Defined in:
- lib/astroapi/http/client.rb
Overview
HTTP client wrapper using Faraday
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#delete(path) ⇒ Hash
Make a DELETE request.
-
#get(path, params: {}) ⇒ Hash
Make a GET request.
-
#initialize(config) ⇒ Client
constructor
A new instance of Client.
-
#post(path, body: {}) ⇒ Hash
Make a POST request.
-
#put(path, body: {}) ⇒ Hash
Make a PUT request.
Constructor Details
#initialize(config) ⇒ Client
Returns a new instance of Client.
15 16 17 18 |
# File 'lib/astroapi/http/client.rb', line 15 def initialize(config) @config = config @connection = build_connection end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
13 14 15 |
# File 'lib/astroapi/http/client.rb', line 13 def config @config end |
Instance Method Details
#delete(path) ⇒ Hash
Make a DELETE request
60 61 62 63 64 65 |
# File 'lib/astroapi/http/client.rb', line 60 def delete(path) response = @connection.delete(path) response.body rescue Faraday::Error => e raise Astroapi::Error.from_faraday_error(e) end |
#get(path, params: {}) ⇒ Hash
Make a GET request
24 25 26 27 28 29 |
# File 'lib/astroapi/http/client.rb', line 24 def get(path, params: {}) response = @connection.get(path, params) response.body rescue Faraday::Error => e raise Astroapi::Error.from_faraday_error(e) end |
#post(path, body: {}) ⇒ Hash
Make a POST request
35 36 37 38 39 40 41 42 |
# File 'lib/astroapi/http/client.rb', line 35 def post(path, body: {}) response = @connection.post(path) do |req| req.body = body.to_json end response.body rescue Faraday::Error => e raise Astroapi::Error.from_faraday_error(e) end |
#put(path, body: {}) ⇒ Hash
Make a PUT request
48 49 50 51 52 53 54 55 |
# File 'lib/astroapi/http/client.rb', line 48 def put(path, body: {}) response = @connection.put(path) do |req| req.body = body.to_json end response.body rescue Faraday::Error => e raise Astroapi::Error.from_faraday_error(e) end |