Class: Swiftner::API::Organisation

Inherits:
Service
  • Object
show all
Defined in:
lib/swiftner/API/organisation.rb

Overview

Represents a Organisation service responsible for finding, creating, and deleting organisations. Inherits from the Service class. Provides methods for interacting with spaces.

Constant Summary collapse

REQUIRED_ATTRIBUTES =
%i[name].freeze

Instance Attribute Summary

Attributes inherited from Service

#client, #details, #id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Service

build, client, #initialize, map_collection, validate_required

Constructor Details

This class inherits a constructor from Swiftner::API::Service

Class Method Details

.add_org_to_token(organisation_id) ⇒ Hash

Add org to token

Parameters:

  • organisation_id (Integer)

Returns:

  • (Hash)

    String, refresh_token: String



29
30
31
# File 'lib/swiftner/API/organisation.rb', line 29

def self.add_org_to_token(organisation_id)
  client.put("/organisation/add-org-to-token?organisation_id=#{organisation_id}")
end

.create(attributes) ⇒ Swiftner::API::Organisation

Creates a new organisation

Parameters:

  • attributes (Hash)

Options Hash (attributes):

  • :name (String) — default: required
  • :description (String) — default: optional
  • :default_prompt_id (Integer) — default: optional
  • :language (String) — default: optional

Returns:



40
41
42
43
44
45
46
47
48
# File 'lib/swiftner/API/organisation.rb', line 40

def self.create(attributes)
  validate_required(attributes, *REQUIRED_ATTRIBUTES)
  response = client.post(
    "/organisation/create",
    body: attributes.to_json,
    headers: { "Content-Type" => "application/json" }
  )
  build(response.parsed_response)
end

.find(organisation_id) ⇒ Swiftner::API::Organisation

Finds organisation by id

Parameters:

  • organisation_id (Integer)

Returns:



21
22
23
24
# File 'lib/swiftner/API/organisation.rb', line 21

def self.find(organisation_id)
  response = client.get("/organisation/get/#{organisation_id}")
  build(response.parsed_response)
end

.find_organisationsArray<Swiftner::API::Organisation>

Finds all organisations user is in

Returns:



13
14
15
16
# File 'lib/swiftner/API/organisation.rb', line 13

def self.find_organisations
  response = client.get("/organisation/get-current-user-orgs")
  map_collection(response)
end

Instance Method Details

#deleteObject

Deletes organisation



72
73
74
# File 'lib/swiftner/API/organisation.rb', line 72

def delete
  client.delete("/organisation/delete/#{id}")
end

#update(attributes) ⇒ Swiftner::API::Organisation

Updates organisation

Parameters:

  • attributes (Hash)

Options Hash (attributes):

  • :name (String) — default: optional
  • :description (String) — default: optional
  • :default_prompt_id (Integer) — default: optional
  • :language (String) — default: optional

Returns:



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/swiftner/API/organisation.rb', line 57

def update(attributes)
  attributes = attributes.transform_keys(&:to_s)
  @details = @details.merge(attributes)

  self.class.validate_required(@details, *REQUIRED_ATTRIBUTES)

  client.put(
    "/organisation/update/#{id}",
    body: @details.to_json,
    headers: { "Content-Type" => "application/json" }
  )
  self
end