Class: Grist::Type::Access

Inherits:
Base
  • Object
show all
Defined in:
lib/grist/type/access.rb

Overview

Defines a Grist Organization

Constant Summary collapse

PATH =
"/access"
KEYS =
%w[
  id
  email
  name
  picture
  ref
  access
  isMember
].freeze

Class Method Summary collapse

Methods inherited from Base

#deleted?, #initialize, #keys

Methods included from Searchable

find_by

Methods included from Accessible

#access

Methods included from Rest

#create, #delete, #get, #list, #path, #request, #update

Constructor Details

This class inherits a constructor from Grist::Type::Base

Class Method Details

.access(id) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/grist/type/access.rb', line 60

def self.access(id)
  org = find(id)
  grist_res = org.access
  return unless grist_res.success? && grist_res.data

  grist_res.data
end

.allArray

List all organizations

Returns:

  • (Array)

    Array of organizations



22
23
24
25
26
27
# File 'lib/grist/type/access.rb', line 22

def self.all
  grist_res = new.list
  return [] unless grist_res&.data.is_a?(Array)

  grist_res.data&.map { |org| Organization.new(org) }
end

.delete(id) ⇒ self | nil

Deletes the organization

Parameters:

  • id (Integer)

    The ID of the organization to delete

Returns:

  • (self | nil)

    The deleted organization or nil if not found



53
54
55
56
57
58
# File 'lib/grist/type/access.rb', line 53

def self.delete(id)
  org = find(id)
  return unless org

  org.delete
end

.find(id) ⇒ Object

Finds an organization by ID return [self | nil] The organization or nil if not found

Parameters:

  • id (Integer)

    The ID of the organization to find



32
33
34
35
36
37
# File 'lib/grist/type/access.rb', line 32

def self.find(id)
  grist_res = new.get(id)
  return unless grist_res.success? && grist_res.data

  new(grist_res.data)
end

.update(id, data) ⇒ self | nil

Updates the organization

Parameters:

  • id (Integer)

    The ID of the organization to delete

  • data (Hash)

    The data to update the organization with

Returns:

  • (self | nil)

    The updated organization or nil if not found



43
44
45
46
47
48
# File 'lib/grist/type/access.rb', line 43

def self.update(id, data)
  org = find(id)
  return unless org

  org.update(data)
end