# The MIT License (MIT) # # Copyright (c) 2023 Losant IoT, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. require "json" module LosantRest # Class containing all the actions for the Org Resource class Org def initialize(client) @client = client end # Deletes an organization # # Authentication: # The client must be configured with a valid api # access token to call this action. The token # must include at least one of the following scopes: # all.Organization, all.User, org.*, or org.delete. # # Parameters: # * {string} orgId - ID associated with the organization # * {string} losantdomain - Domain scope of request (rarely needed) # * {boolean} _actions - Return resource actions in response # * {boolean} _links - Return resource link in response # * {boolean} _embedded - Return embedded resources in response # # Responses: # * 200 - If organization was successfully deleted (https://api.losant.com/#/definitions/success) # # Errors: # * 400 - Error if malformed request (https://api.losant.com/#/definitions/error) # * 404 - Error if organization was not found (https://api.losant.com/#/definitions/error) def delete(params = {}) params = Utils.symbolize_hash_keys(params) query_params = { _actions: false, _links: true, _embedded: true } headers = {} body = nil raise ArgumentError.new("orgId is required") unless params.has_key?(:orgId) headers[:losantdomain] = params[:losantdomain] if params.has_key?(:losantdomain) query_params[:_actions] = params[:_actions] if params.has_key?(:_actions) query_params[:_links] = params[:_links] if params.has_key?(:_links) query_params[:_embedded] = params[:_embedded] if params.has_key?(:_embedded) path = "/orgs/#{params[:orgId]}" @client.request( method: :delete, path: path, query: query_params, headers: headers, body: body) end # Retrieves information on an organization # # Authentication: # The client must be configured with a valid api # access token to call this action. The token # must include at least one of the following scopes: # all.Organization, all.Organization.read, all.User, all.User.read, org.*, or org.get. # # Parameters: # * {string} orgId - ID associated with the organization # * {string} summaryExclude - Comma-separated list of summary fields to exclude from org summary # * {string} summaryInclude - Comma-separated list of summary fields to include in org summary # * {string} losantdomain - Domain scope of request (rarely needed) # * {boolean} _actions - Return resource actions in response # * {boolean} _links - Return resource link in response # * {boolean} _embedded - Return embedded resources in response # # Responses: # * 200 - Organization information (https://api.losant.com/#/definitions/org) # # Errors: # * 400 - Error if malformed request (https://api.losant.com/#/definitions/error) # * 404 - Error if organization not found (https://api.losant.com/#/definitions/error) def get(params = {}) params = Utils.symbolize_hash_keys(params) query_params = { _actions: false, _links: true, _embedded: true } headers = {} body = nil raise ArgumentError.new("orgId is required") unless params.has_key?(:orgId) query_params[:summaryExclude] = params[:summaryExclude] if params.has_key?(:summaryExclude) query_params[:summaryInclude] = params[:summaryInclude] if params.has_key?(:summaryInclude) headers[:losantdomain] = params[:losantdomain] if params.has_key?(:losantdomain) query_params[:_actions] = params[:_actions] if params.has_key?(:_actions) query_params[:_links] = params[:_links] if params.has_key?(:_links) query_params[:_embedded] = params[:_embedded] if params.has_key?(:_embedded) path = "/orgs/#{params[:orgId]}" @client.request( method: :get, path: path, query: query_params, headers: headers, body: body) end # Invites a person to an organization # # Authentication: # The client must be configured with a valid api # access token to call this action. The token # must include at least one of the following scopes: # all.Organization, all.User, org.*, or org.inviteMember. # # Parameters: # * {string} orgId - ID associated with the organization # * {hash} invite - Object containing new invite info (https://api.losant.com/#/definitions/orgInvitePost) # * {string} losantdomain - Domain scope of request (rarely needed) # * {boolean} _actions - Return resource actions in response # * {boolean} _links - Return resource link in response # * {boolean} _embedded - Return embedded resources in response # # Responses: # * 200 - Invitation information (https://api.losant.com/#/definitions/orgInvites) # # Errors: # * 400 - Error if malformed request (https://api.losant.com/#/definitions/error) # * 404 - Error if organization not found (https://api.losant.com/#/definitions/error) def invite_member(params = {}) params = Utils.symbolize_hash_keys(params) query_params = { _actions: false, _links: true, _embedded: true } headers = {} body = nil raise ArgumentError.new("orgId is required") unless params.has_key?(:orgId) raise ArgumentError.new("invite is required") unless params.has_key?(:invite) body = params[:invite] if params.has_key?(:invite) headers[:losantdomain] = params[:losantdomain] if params.has_key?(:losantdomain) query_params[:_actions] = params[:_actions] if params.has_key?(:_actions) query_params[:_links] = params[:_links] if params.has_key?(:_links) query_params[:_embedded] = params[:_embedded] if params.has_key?(:_embedded) path = "/orgs/#{params[:orgId]}/invites" @client.request( method: :post, path: path, query: query_params, headers: headers, body: body) end # Modifies a current org member's role # # Authentication: # The client must be configured with a valid api # access token to call this action. The token # must include at least one of the following scopes: # all.Organization, all.User, org.*, or org.modifyMember. # # Parameters: # * {string} orgId - ID associated with the organization # * {hash} member - Object containing new member pair (https://api.losant.com/#/definitions/orgMemberPatch) # * {string} summaryExclude - Comma-separated list of summary fields to exclude from org summary # * {string} summaryInclude - Comma-separated list of summary fields to include in org summary # * {string} losantdomain - Domain scope of request (rarely needed) # * {boolean} _actions - Return resource actions in response # * {boolean} _links - Return resource link in response # * {boolean} _embedded - Return embedded resources in response # # Responses: # * 200 - Updated organization information (https://api.losant.com/#/definitions/org) # # Errors: # * 400 - Error if malformed request (https://api.losant.com/#/definitions/error) # * 404 - Error if organization not found (https://api.losant.com/#/definitions/error) def modify_member(params = {}) params = Utils.symbolize_hash_keys(params) query_params = { _actions: false, _links: true, _embedded: true } headers = {} body = nil raise ArgumentError.new("orgId is required") unless params.has_key?(:orgId) raise ArgumentError.new("member is required") unless params.has_key?(:member) body = params[:member] if params.has_key?(:member) query_params[:summaryExclude] = params[:summaryExclude] if params.has_key?(:summaryExclude) query_params[:summaryInclude] = params[:summaryInclude] if params.has_key?(:summaryInclude) headers[:losantdomain] = params[:losantdomain] if params.has_key?(:losantdomain) query_params[:_actions] = params[:_actions] if params.has_key?(:_actions) query_params[:_links] = params[:_links] if params.has_key?(:_links) query_params[:_embedded] = params[:_embedded] if params.has_key?(:_embedded) path = "/orgs/#{params[:orgId]}/member" @client.request( method: :patch, path: path, query: query_params, headers: headers, body: body) end # Updates information about an organization # # Authentication: # The client must be configured with a valid api # access token to call this action. The token # must include at least one of the following scopes: # all.Organization, all.User, org.*, or org.patch. # # Parameters: # * {string} orgId - ID associated with the organization # * {hash} organization - Object containing new organization properties (https://api.losant.com/#/definitions/orgPatch) # * {string} summaryExclude - Comma-separated list of summary fields to exclude from org summary # * {string} summaryInclude - Comma-separated list of summary fields to include in org summary # * {string} losantdomain - Domain scope of request (rarely needed) # * {boolean} _actions - Return resource actions in response # * {boolean} _links - Return resource link in response # * {boolean} _embedded - Return embedded resources in response # # Responses: # * 200 - Updated organization information (https://api.losant.com/#/definitions/org) # # Errors: # * 400 - Error if malformed request (https://api.losant.com/#/definitions/error) # * 404 - Error if organization was not found (https://api.losant.com/#/definitions/error) def patch(params = {}) params = Utils.symbolize_hash_keys(params) query_params = { _actions: false, _links: true, _embedded: true } headers = {} body = nil raise ArgumentError.new("orgId is required") unless params.has_key?(:orgId) raise ArgumentError.new("organization is required") unless params.has_key?(:organization) body = params[:organization] if params.has_key?(:organization) query_params[:summaryExclude] = params[:summaryExclude] if params.has_key?(:summaryExclude) query_params[:summaryInclude] = params[:summaryInclude] if params.has_key?(:summaryInclude) headers[:losantdomain] = params[:losantdomain] if params.has_key?(:losantdomain) query_params[:_actions] = params[:_actions] if params.has_key?(:_actions) query_params[:_links] = params[:_links] if params.has_key?(:_links) query_params[:_embedded] = params[:_embedded] if params.has_key?(:_embedded) path = "/orgs/#{params[:orgId]}" @client.request( method: :patch, path: path, query: query_params, headers: headers, body: body) end # Returns payload counts for the time range specified for all applications this organization owns # # Authentication: # The client must be configured with a valid api # access token to call this action. The token # must include at least one of the following scopes: # all.Organization, all.Organization.read, all.User, all.User.read, org.*, or org.payloadCounts. # # Parameters: # * {string} orgId - ID associated with the organization # * {string} start - Start of range for payload count query (ms since epoch) # * {string} end - End of range for payload count query (ms since epoch) # * {string} losantdomain - Domain scope of request (rarely needed) # * {boolean} _actions - Return resource actions in response # * {boolean} _links - Return resource link in response # * {boolean} _embedded - Return embedded resources in response # # Responses: # * 200 - Payload counts, by type and source (https://api.losant.com/#/definitions/payloadStats) # # Errors: # * 400 - Error if malformed request (https://api.losant.com/#/definitions/error) # * 404 - Error if organization was not found (https://api.losant.com/#/definitions/error) def payload_counts(params = {}) params = Utils.symbolize_hash_keys(params) query_params = { _actions: false, _links: true, _embedded: true } headers = {} body = nil raise ArgumentError.new("orgId is required") unless params.has_key?(:orgId) query_params[:start] = params[:start] if params.has_key?(:start) query_params[:end] = params[:end] if params.has_key?(:end) headers[:losantdomain] = params[:losantdomain] if params.has_key?(:losantdomain) query_params[:_actions] = params[:_actions] if params.has_key?(:_actions) query_params[:_links] = params[:_links] if params.has_key?(:_links) query_params[:_embedded] = params[:_embedded] if params.has_key?(:_embedded) path = "/orgs/#{params[:orgId]}/payloadCounts" @client.request( method: :get, path: path, query: query_params, headers: headers, body: body) end # Gets the current pending invites # # Authentication: # The client must be configured with a valid api # access token to call this action. The token # must include at least one of the following scopes: # all.Organization, all.Organization.read, all.User, all.User.read, org.*, or org.pendingInvites. # # Parameters: # * {string} orgId - ID associated with the organization # * {string} losantdomain - Domain scope of request (rarely needed) # * {boolean} _actions - Return resource actions in response # * {boolean} _links - Return resource link in response # * {boolean} _embedded - Return embedded resources in response # # Responses: # * 200 - Invitation information (https://api.losant.com/#/definitions/orgInvites) # # Errors: # * 400 - Error if malformed request (https://api.losant.com/#/definitions/error) # * 404 - Error if organization not found (https://api.losant.com/#/definitions/error) def pending_invites(params = {}) params = Utils.symbolize_hash_keys(params) query_params = { _actions: false, _links: true, _embedded: true } headers = {} body = nil raise ArgumentError.new("orgId is required") unless params.has_key?(:orgId) headers[:losantdomain] = params[:losantdomain] if params.has_key?(:losantdomain) query_params[:_actions] = params[:_actions] if params.has_key?(:_actions) query_params[:_links] = params[:_links] if params.has_key?(:_links) query_params[:_embedded] = params[:_embedded] if params.has_key?(:_embedded) path = "/orgs/#{params[:orgId]}/invites" @client.request( method: :get, path: path, query: query_params, headers: headers, body: body) end # Removes a member from the org # # Authentication: # The client must be configured with a valid api # access token to call this action. The token # must include at least one of the following scopes: # all.Organization, all.User, org.*, or org.removeMember. # # Parameters: # * {string} orgId - ID associated with the organization # * {string} userId - Id of user to remove # * {string} summaryExclude - Comma-separated list of summary fields to exclude from org summary # * {string} summaryInclude - Comma-separated list of summary fields to include in org summary # * {string} losantdomain - Domain scope of request (rarely needed) # * {boolean} _actions - Return resource actions in response # * {boolean} _links - Return resource link in response # * {boolean} _embedded - Return embedded resources in response # # Responses: # * 200 - Updated organization information (https://api.losant.com/#/definitions/org) # # Errors: # * 400 - Error if malformed request (https://api.losant.com/#/definitions/error) # * 404 - Error if organization not found (https://api.losant.com/#/definitions/error) def remove_member(params = {}) params = Utils.symbolize_hash_keys(params) query_params = { _actions: false, _links: true, _embedded: true } headers = {} body = nil raise ArgumentError.new("orgId is required") unless params.has_key?(:orgId) raise ArgumentError.new("userId is required") unless params.has_key?(:userId) query_params[:userId] = params[:userId] if params.has_key?(:userId) query_params[:summaryExclude] = params[:summaryExclude] if params.has_key?(:summaryExclude) query_params[:summaryInclude] = params[:summaryInclude] if params.has_key?(:summaryInclude) headers[:losantdomain] = params[:losantdomain] if params.has_key?(:losantdomain) query_params[:_actions] = params[:_actions] if params.has_key?(:_actions) query_params[:_links] = params[:_links] if params.has_key?(:_links) query_params[:_embedded] = params[:_embedded] if params.has_key?(:_embedded) path = "/orgs/#{params[:orgId]}/member" @client.request( method: :delete, path: path, query: query_params, headers: headers, body: body) end # Revokes an existing invite # # Authentication: # The client must be configured with a valid api # access token to call this action. The token # must include at least one of the following scopes: # all.Organization, all.User, org.*, or org.revokeInvite. # # Parameters: # * {string} orgId - ID associated with the organization # * {string} inviteId - Id of invite to revoke # * {string} losantdomain - Domain scope of request (rarely needed) # * {boolean} _actions - Return resource actions in response # * {boolean} _links - Return resource link in response # * {boolean} _embedded - Return embedded resources in response # # Responses: # * 200 - Invitation information (https://api.losant.com/#/definitions/orgInvites) # # Errors: # * 400 - Error if malformed request (https://api.losant.com/#/definitions/error) # * 404 - Error if organization not found (https://api.losant.com/#/definitions/error) def revoke_invite(params = {}) params = Utils.symbolize_hash_keys(params) query_params = { _actions: false, _links: true, _embedded: true } headers = {} body = nil raise ArgumentError.new("orgId is required") unless params.has_key?(:orgId) raise ArgumentError.new("inviteId is required") unless params.has_key?(:inviteId) query_params[:inviteId] = params[:inviteId] if params.has_key?(:inviteId) headers[:losantdomain] = params[:losantdomain] if params.has_key?(:losantdomain) query_params[:_actions] = params[:_actions] if params.has_key?(:_actions) query_params[:_links] = params[:_links] if params.has_key?(:_links) query_params[:_embedded] = params[:_embedded] if params.has_key?(:_embedded) path = "/orgs/#{params[:orgId]}/invites" @client.request( method: :delete, path: path, query: query_params, headers: headers, body: body) end # Moves resources to a new owner # # Authentication: # The client must be configured with a valid api # access token to call this action. The token # must include at least one of the following scopes: # all.Organization, all.User, org.*, or org.transferResources. # # Parameters: # * {string} orgId - ID associated with the organization # * {hash} transfer - Object containing properties of the transfer (https://api.losant.com/#/definitions/resourceTransfer) # * {string} losantdomain - Domain scope of request (rarely needed) # * {boolean} _actions - Return resource actions in response # * {boolean} _links - Return resource link in response # * {boolean} _embedded - Return embedded resources in response # # Responses: # * 200 - If resource transfer was successful (https://api.losant.com/#/definitions/success) # # Errors: # * 400 - Error if malformed request (https://api.losant.com/#/definitions/error) # * 404 - Error if organization was not found (https://api.losant.com/#/definitions/error) def transfer_resources(params = {}) params = Utils.symbolize_hash_keys(params) query_params = { _actions: false, _links: true, _embedded: true } headers = {} body = nil raise ArgumentError.new("orgId is required") unless params.has_key?(:orgId) raise ArgumentError.new("transfer is required") unless params.has_key?(:transfer) body = params[:transfer] if params.has_key?(:transfer) headers[:losantdomain] = params[:losantdomain] if params.has_key?(:losantdomain) query_params[:_actions] = params[:_actions] if params.has_key?(:_actions) query_params[:_links] = params[:_links] if params.has_key?(:_links) query_params[:_embedded] = params[:_embedded] if params.has_key?(:_embedded) path = "/orgs/#{params[:orgId]}/transferResources" @client.request( method: :patch, path: path, query: query_params, headers: headers, body: body) end end end