Class: Lago::Api::Connection
- Inherits:
-
Object
- Object
- Lago::Api::Connection
- Defined in:
- lib/lago/api/connection.rb
Constant Summary collapse
- RESPONSE_SUCCESS_CODES =
[200, 201, 202, 204].freeze
Instance Method Summary collapse
- #delete(body, path = uri.path) ⇒ Object
- #destroy(path = uri.path, identifier:) ⇒ Object
- #get(path = uri.path, identifier:) ⇒ Object
- #get_all(options, path = uri.path) ⇒ Object
-
#initialize(api_key, uri) ⇒ Connection
constructor
A new instance of Connection.
- #post(body, path = uri.path) ⇒ Object
- #put(path = uri.path, identifier:, body:) ⇒ Object
Constructor Details
#initialize(api_key, uri) ⇒ Connection
Returns a new instance of Connection.
8 9 10 11 |
# File 'lib/lago/api/connection.rb', line 8 def initialize(api_key, uri) @api_key = api_key @uri = uri end |
Instance Method Details
#delete(body, path = uri.path) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/lago/api/connection.rb', line 36 def delete(body, path = uri.path) response = http_client.send_request( 'DELETE', path, prepare_payload(body), headers ) handle_response(response) end |
#destroy(path = uri.path, identifier:) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/lago/api/connection.rb', line 59 def destroy(path = uri.path, identifier:) uri_path = "#{path}/#{identifier}" response = http_client.send_request( 'DELETE', uri_path, prepare_payload(nil), headers ) handle_response(response) end |
#get(path = uri.path, identifier:) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/lago/api/connection.rb', line 47 def get(path = uri.path, identifier:) uri_path = identifier.nil? ? path : "#{path}/#{identifier}" response = http_client.send_request( 'GET', uri_path, prepare_payload(nil), headers ) handle_response(response) end |
#get_all(options, path = uri.path) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/lago/api/connection.rb', line 71 def get_all(, path = uri.path) uri_path = .empty? ? path : "#{path}?#{URI.encode_www_form()}" response = http_client.send_request( 'GET', uri_path, prepare_payload(nil), headers ) handle_response(response) end |
#post(body, path = uri.path) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/lago/api/connection.rb', line 13 def post(body, path = uri.path) response = http_client.send_request( 'POST', path, prepare_payload(body), headers ) handle_response(response) end |
#put(path = uri.path, identifier:, body:) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/lago/api/connection.rb', line 24 def put(path = uri.path, identifier:, body:) uri_path = identifier.nil? ? path : "#{path}/#{identifier}" response = http_client.send_request( 'PUT', uri_path, prepare_payload(body), headers ) handle_response(response) end |