Class: Swiftner::API::Organisation
- 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
Class Method Summary collapse
-
.add_org_to_token(organisation_id) ⇒ Hash
Add org to token.
-
.create(attributes) ⇒ Swiftner::API::Organisation
Creates a new organisation.
-
.find(organisation_id) ⇒ Swiftner::API::Organisation
Finds organisation by id.
-
.find_organisations ⇒ Array<Swiftner::API::Organisation>
Finds all organisations user is in.
Instance Method Summary collapse
-
#delete ⇒ Object
Deletes organisation.
-
#update(attributes) ⇒ Swiftner::API::Organisation
Updates organisation.
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
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
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
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_organisations ⇒ Array<Swiftner::API::Organisation>
Finds all organisations user is in
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
#delete ⇒ Object
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
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 |