# frozen_string_literal: true module Files class Group attr_reader :options, :attributes def initialize(attributes = {}, options = {}) @attributes = attributes || {} @options = options || {} end # int64 - Group ID def id @attributes[:id] end def id=(value) @attributes[:id] = value end # string - Group name def name @attributes[:name] end def name=(value) @attributes[:name] = value end # array - List of user IDs who are group administrators (separated by commas) def admin_ids @attributes[:admin_ids] end def admin_ids=(value) @attributes[:admin_ids] = value end # string - Notes about this group def notes @attributes[:notes] end def notes=(value) @attributes[:notes] = value end # array - List of user IDs who belong to this group (separated by commas) def user_ids @attributes[:user_ids] end def user_ids=(value) @attributes[:user_ids] = value end # array - List of usernames who belong to this group (separated by commas) def usernames @attributes[:usernames] end def usernames=(value) @attributes[:usernames] = value end # Parameters: # name - string - Group name. # notes - string - Group notes. # user_ids - string - A list of user ids. If sent as a string, should be comma-delimited. # admin_ids - string - A list of group admin user ids. If sent as a string, should be comma-delimited. def update(params = {}) params ||= {} params[:id] = @attributes[:id] raise MissingParameterError.new("Current object doesn't have a id") unless @attributes[:id] raise InvalidParameterError.new("Bad parameter: id must be an Integer") if params.dig(:id) and !params.dig(:id).is_a?(Integer) raise InvalidParameterError.new("Bad parameter: name must be an String") if params.dig(:name) and !params.dig(:name).is_a?(String) raise InvalidParameterError.new("Bad parameter: notes must be an String") if params.dig(:notes) and !params.dig(:notes).is_a?(String) raise InvalidParameterError.new("Bad parameter: user_ids must be an String") if params.dig(:user_ids) and !params.dig(:user_ids).is_a?(String) raise InvalidParameterError.new("Bad parameter: admin_ids must be an String") if params.dig(:admin_ids) and !params.dig(:admin_ids).is_a?(String) raise MissingParameterError.new("Parameter missing: id") unless params.dig(:id) Api.send_request("/groups/#{@attributes[:id]}", :patch, params, @options) end def delete(params = {}) params ||= {} params[:id] = @attributes[:id] raise MissingParameterError.new("Current object doesn't have a id") unless @attributes[:id] raise InvalidParameterError.new("Bad parameter: id must be an Integer") if params.dig(:id) and !params.dig(:id).is_a?(Integer) raise MissingParameterError.new("Parameter missing: id") unless params.dig(:id) Api.send_request("/groups/#{@attributes[:id]}", :delete, params, @options) end def destroy(params = {}) delete(params) end def save if @attributes[:id] update(@attributes) else new_obj = Group.create(@attributes, @options) @attributes = new_obj.attributes end end # Parameters: # page - int64 - Current page number. # per_page - int64 - Number of records to show per page. (Max: 10,000, 1,000 or less is recommended). # action - string - Deprecated: If set to `count` returns a count of matching records rather than the records themselves. # ids - string - Comma-separated list of group ids to include in results. def self.list(params = {}, options = {}) raise InvalidParameterError.new("Bad parameter: page must be an Integer") if params.dig(:page) and !params.dig(:page).is_a?(Integer) raise InvalidParameterError.new("Bad parameter: per_page must be an Integer") if params.dig(:per_page) and !params.dig(:per_page).is_a?(Integer) raise InvalidParameterError.new("Bad parameter: action must be an String") if params.dig(:action) and !params.dig(:action).is_a?(String) raise InvalidParameterError.new("Bad parameter: ids must be an String") if params.dig(:ids) and !params.dig(:ids).is_a?(String) response, options = Api.send_request("/groups", :get, params, options) response.data.map do |entity_data| Group.new(entity_data, options) end end def self.all(params = {}, options = {}) list(params, options) end # Parameters: # id (required) - int64 - Group ID. def self.find(id, params = {}, options = {}) params ||= {} params[:id] = id raise InvalidParameterError.new("Bad parameter: id must be an Integer") if params.dig(:id) and !params.dig(:id).is_a?(Integer) raise MissingParameterError.new("Parameter missing: id") unless params.dig(:id) response, options = Api.send_request("/groups/#{params[:id]}", :get, params, options) Group.new(response.data, options) end def self.get(id, params = {}, options = {}) find(id, params, options) end # Parameters: # name - string - Group name. # notes - string - Group notes. # user_ids - string - A list of user ids. If sent as a string, should be comma-delimited. # admin_ids - string - A list of group admin user ids. If sent as a string, should be comma-delimited. def self.create(params = {}, options = {}) raise InvalidParameterError.new("Bad parameter: name must be an String") if params.dig(:name) and !params.dig(:name).is_a?(String) raise InvalidParameterError.new("Bad parameter: notes must be an String") if params.dig(:notes) and !params.dig(:notes).is_a?(String) raise InvalidParameterError.new("Bad parameter: user_ids must be an String") if params.dig(:user_ids) and !params.dig(:user_ids).is_a?(String) raise InvalidParameterError.new("Bad parameter: admin_ids must be an String") if params.dig(:admin_ids) and !params.dig(:admin_ids).is_a?(String) response, options = Api.send_request("/groups", :post, params, options) Group.new(response.data, options) end # Parameters: # name - string - Group name. # notes - string - Group notes. # user_ids - string - A list of user ids. If sent as a string, should be comma-delimited. # admin_ids - string - A list of group admin user ids. If sent as a string, should be comma-delimited. def self.update(id, params = {}, options = {}) params ||= {} params[:id] = id raise InvalidParameterError.new("Bad parameter: id must be an Integer") if params.dig(:id) and !params.dig(:id).is_a?(Integer) raise InvalidParameterError.new("Bad parameter: name must be an String") if params.dig(:name) and !params.dig(:name).is_a?(String) raise InvalidParameterError.new("Bad parameter: notes must be an String") if params.dig(:notes) and !params.dig(:notes).is_a?(String) raise InvalidParameterError.new("Bad parameter: user_ids must be an String") if params.dig(:user_ids) and !params.dig(:user_ids).is_a?(String) raise InvalidParameterError.new("Bad parameter: admin_ids must be an String") if params.dig(:admin_ids) and !params.dig(:admin_ids).is_a?(String) raise MissingParameterError.new("Parameter missing: id") unless params.dig(:id) response, options = Api.send_request("/groups/#{params[:id]}", :patch, params, options) Group.new(response.data, options) end def self.delete(id, params = {}, options = {}) params ||= {} params[:id] = id raise InvalidParameterError.new("Bad parameter: id must be an Integer") if params.dig(:id) and !params.dig(:id).is_a?(Integer) raise MissingParameterError.new("Parameter missing: id") unless params.dig(:id) response, _options = Api.send_request("/groups/#{params[:id]}", :delete, params, options) response.data end def self.destroy(id, params = {}, options = {}) delete(id, params, options) end end end