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, max_endpoints: nil, show_event_types: 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, max_endpoints: UNSET, show_event_types: UNSET) ⇒ 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, max_endpoints: nil, show_event_types: nil) ⇒ Hash
Create a new application.
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/nahook/resources/applications.rb', line 54 def create(workspace_id, name:, external_id: nil, metadata: nil, max_endpoints: nil, show_event_types: nil) body = { "name" => name } body["externalId"] = external_id if external_id body["metadata"] = if body["maxEndpoints"] = max_endpoints unless max_endpoints.nil? body["showEventTypes"] = show_event_types unless show_event_types.nil? @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.
140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/nahook/resources/applications.rb', line 140 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.
110 111 112 113 114 115 |
# File 'lib/nahook/resources/applications.rb', line 110 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.
73 74 75 76 77 78 |
# File 'lib/nahook/resources/applications.rb', line 73 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.
122 123 124 125 126 127 128 |
# File 'lib/nahook/resources/applications.rb', line 122 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, max_endpoints: UNSET, show_event_types: UNSET) ⇒ Hash
Update an existing application.
91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/nahook/resources/applications.rb', line 91 def update(workspace_id, id, name: nil, metadata: nil, max_endpoints: UNSET, show_event_types: UNSET) body = {} body["name"] = name unless name.nil? body["metadata"] = unless .nil? body["maxEndpoints"] = max_endpoints unless max_endpoints.equal?(UNSET) body["showEventTypes"] = show_event_types unless show_event_types.equal?(UNSET) @http.request( method: :patch, path: "/management/v1/workspaces/#{e(workspace_id)}/applications/#{e(id)}", body: body ) end |