Class: Polar::Client
- Inherits:
-
Object
- Object
- Polar::Client
- Defined in:
- lib/polar/client.rb
Class Method Summary collapse
- .connection ⇒ Object
- .delete_request(path, **params) ⇒ Object
- .get_request(path, **params) ⇒ Object
- .patch_request(path, **params) ⇒ Object
- .post_request(path, **params) ⇒ Object
Class Method Details
.connection ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/polar/client.rb', line 8 def connection @connection ||= HTTP .persistent(Polar.config.endpoint) .follow .auth("Bearer #{Polar.config.access_token}") .headers( accept: "application/json", content_type: "application/json", user_agent: "polar_sh/v#{VERSION} (github.com/mikker/polar_sh)" ) # .use(logging: {logger: Logger.new(STDOUT)}) end |
.delete_request(path, **params) ⇒ Object
39 40 41 42 43 |
# File 'lib/polar/client.rb', line 39 def delete_request(path, **params) response = connection.delete(path, json: params) return true if response.status.success? raise Error.from_response(response) end |
.get_request(path, **params) ⇒ Object
21 22 23 24 25 |
# File 'lib/polar/client.rb', line 21 def get_request(path, **params) response = connection.get(path, params:) return response.parse if response.status.success? raise Error.from_response(response) end |
.patch_request(path, **params) ⇒ Object
33 34 35 36 37 |
# File 'lib/polar/client.rb', line 33 def patch_request(path, **params) response = connection.patch(path, json: params) return response.parse if response.status.success? raise Error.from_response(response) end |
.post_request(path, **params) ⇒ Object
27 28 29 30 31 |
# File 'lib/polar/client.rb', line 27 def post_request(path, **params) response = connection.post(path, json: params) return response.parse if response.status.success? raise Error.from_response(response) end |