Class: Nahook::Resources::Applications
- Inherits:
-
Object
- Object
- Nahook::Resources::Applications
- Defined in:
- lib/nahook/resources/applications.rb
Overview
Resource for managing applications via the Management API.
Applications group endpoints for multi-tenant use cases. Each application can have its own set of endpoints and a developer portal.
Instance Method Summary collapse
-
#create(workspace_id, name:, external_id: nil, metadata: nil) ⇒ Hash
Create a new application.
-
#create_endpoint(workspace_id, app_id, url:, type: nil, description: nil, metadata: nil, config: nil) ⇒ Hash
Create an endpoint within an application.
-
#delete(workspace_id, id) ⇒ nil
Delete an application.
-
#get(workspace_id, id) ⇒ Hash
Get a single application by ID.
-
#initialize(http) ⇒ Applications
constructor
private
A new instance of Applications.
-
#list(workspace_id, limit: nil, offset: nil) ⇒ Hash
List applications in a workspace with optional pagination.
-
#list_endpoints(workspace_id, app_id) ⇒ Hash
List endpoints belonging to an application.
-
#update(workspace_id, id, name: nil, metadata: nil) ⇒ Hash
Update an existing application.
Constructor Details
#initialize(http) ⇒ Applications
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Applications.
19 20 21 |
# File 'lib/nahook/resources/applications.rb', line 19 def initialize(http) @http = http end |
Instance Method Details
#create(workspace_id, name:, external_id: nil, metadata: nil) ⇒ Hash
Create a new application.
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/nahook/resources/applications.rb', line 49 def create(workspace_id, name:, external_id: nil, metadata: nil) body = { "name" => name } body["externalId"] = external_id if external_id body["metadata"] = if @http.request( method: :post, path: "/management/v1/workspaces/#{e(workspace_id)}/applications", body: body ) end |
#create_endpoint(workspace_id, app_id, url:, type: nil, description: nil, metadata: nil, config: nil) ⇒ Hash
Create an endpoint within an application.
127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/nahook/resources/applications.rb', line 127 def create_endpoint(workspace_id, app_id, url:, type: nil, description: nil, metadata: nil, config: nil) body = { "url" => url } body["type"] = type if type body["description"] = description if description body["metadata"] = if body["config"] = config if config @http.request( method: :post, path: "/management/v1/workspaces/#{e(workspace_id)}/applications/#{e(app_id)}/endpoints", body: body ) end |
#delete(workspace_id, id) ⇒ nil
Delete an application.
97 98 99 100 101 102 |
# File 'lib/nahook/resources/applications.rb', line 97 def delete(workspace_id, id) @http.request( method: :delete, path: "/management/v1/workspaces/#{e(workspace_id)}/applications/#{e(id)}" ) end |
#get(workspace_id, id) ⇒ Hash
Get a single application by ID.
66 67 68 69 70 71 |
# File 'lib/nahook/resources/applications.rb', line 66 def get(workspace_id, id) @http.request( method: :get, path: "/management/v1/workspaces/#{e(workspace_id)}/applications/#{e(id)}" ) end |
#list(workspace_id, limit: nil, offset: nil) ⇒ Hash
List applications in a workspace with optional pagination.
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/nahook/resources/applications.rb', line 29 def list(workspace_id, limit: nil, offset: nil) query = {} query["limit"] = limit if limit query["offset"] = offset if offset data = @http.request( method: :get, path: "/management/v1/workspaces/#{e(workspace_id)}/applications", query: query.empty? ? nil : query ) { "data" => data } end |
#list_endpoints(workspace_id, app_id) ⇒ Hash
List endpoints belonging to an application.
109 110 111 112 113 114 115 |
# File 'lib/nahook/resources/applications.rb', line 109 def list_endpoints(workspace_id, app_id) data = @http.request( method: :get, path: "/management/v1/workspaces/#{e(workspace_id)}/applications/#{e(app_id)}/endpoints" ) { "data" => data } end |
#update(workspace_id, id, name: nil, metadata: nil) ⇒ Hash
Update an existing application.
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/nahook/resources/applications.rb', line 80 def update(workspace_id, id, name: nil, metadata: nil) body = {} body["name"] = name unless name.nil? body["metadata"] = unless .nil? @http.request( method: :patch, path: "/management/v1/workspaces/#{e(workspace_id)}/applications/#{e(id)}", body: body ) end |