Class: Hanko::Api::BaseResource
- Inherits:
-
Object
- Object
- Hanko::Api::BaseResource
- Defined in:
- lib/hanko/api/base_resource.rb
Overview
Direct Known Subclasses
Admin::AuditLogs, Admin::Emails, Admin::Sessions, Admin::Users, Admin::WebauthnCredentials, Admin::Webhooks
Instance Method Summary collapse
-
#create(**params) ⇒ Resource
Create a new resource with the given attributes.
-
#delete(id) ⇒ void
Delete a resource by its ID.
-
#get(id) ⇒ Resource
Fetch a single resource by its ID.
-
#initialize(connection, base_path) ⇒ BaseResource
constructor
Initialize a new resource endpoint.
-
#list(params = {}) ⇒ Array<Resource>
List all resources, optionally filtered by query parameters.
-
#update(id, **params) ⇒ Resource
Update an existing resource by its ID.
Constructor Details
#initialize(connection, base_path) ⇒ BaseResource
Initialize a new resource endpoint.
15 16 17 18 |
# File 'lib/hanko/api/base_resource.rb', line 15 def initialize(connection, base_path) @connection = connection @base_path = base_path end |
Instance Method Details
#create(**params) ⇒ Resource
Create a new resource with the given attributes.
42 43 44 45 |
# File 'lib/hanko/api/base_resource.rb', line 42 def create(**params) response = @connection.post(@base_path, params) parse_resource(response.body) end |
#delete(id) ⇒ void
This method returns an undefined value.
Delete a resource by its ID.
61 62 63 64 |
# File 'lib/hanko/api/base_resource.rb', line 61 def delete(id) @connection.delete("#{@base_path}/#{id}") nil end |
#get(id) ⇒ Resource
Fetch a single resource by its ID.
33 34 35 36 |
# File 'lib/hanko/api/base_resource.rb', line 33 def get(id) response = @connection.get("#{@base_path}/#{id}") parse_resource(response.body) end |
#list(params = {}) ⇒ Array<Resource>
List all resources, optionally filtered by query parameters.
24 25 26 27 |
# File 'lib/hanko/api/base_resource.rb', line 24 def list(params = {}) response = @connection.get(@base_path, params) parse_array(response.body) end |
#update(id, **params) ⇒ Resource
Update an existing resource by its ID.
52 53 54 55 |
# File 'lib/hanko/api/base_resource.rb', line 52 def update(id, **params) response = @connection.put("#{@base_path}/#{id}", params) parse_resource(response.body) end |