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
- #destroy(path = uri.path, identifier:, options: nil) ⇒ 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
#destroy(path = uri.path, identifier:, options: nil) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/lago/api/connection.rb', line 48 def destroy(path = uri.path, identifier:, options: nil) uri_path = path uri_path += "/#{URI.encode_www_form_component(identifier)}" if identifier uri_path += "?#{URI.encode_www_form()}" unless .nil? response = http_client.send_request( 'DELETE', uri_path, prepare_payload(nil), headers ) handle_response(response) end |
#get(path = uri.path, identifier:) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/lago/api/connection.rb', line 36 def get(path = uri.path, identifier:) uri_path = identifier.nil? ? path : "#{path}/#{URI.encode_www_form_component(identifier)}" response = http_client.send_request( 'GET', uri_path, prepare_payload(nil), headers ) handle_response(response) end |
#get_all(options, path = uri.path) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/lago/api/connection.rb', line 62 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}/#{URI.encode_www_form_component(identifier)}" response = http_client.send_request( 'PUT', uri_path, prepare_payload(body), headers ) handle_response(response) end |