Class: Grist::Type::Organization

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

Overview

Defines a Grist Organization

Constant Summary collapse

PATH =
"/orgs"
KEYS =
%w[
  id
  name
  createdAt
  updatedAt
  domain
  host
  owner
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

all, delete, #deleted?, find, #keys, update

Methods included from Searchable

find_by

Methods included from Accessible

#access

Methods included from Rest

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

Constructor Details

#initialize(params = {}) ⇒ Grist::Type::Organization

Initialize a new Organization )

Examples:

org = Grist::Type::Organization.new(
"id" => 1,
"name" => "Grist Labs",
"domain" => "gristlabs",
"host" => "gristlabs.com",


32
33
34
35
# File 'lib/grist/type/organization.rb', line 32

def initialize(params = {})
  super params
  @workspaces = []
end

Instance Attribute Details

#workspacesArray (readonly)

List Workspaces in the organization



40
41
42
# File 'lib/grist/type/organization.rb', line 40

def workspaces
  @workspaces
end

Class Method Details

.access(id) ⇒ Array?

Get users which can access to the organization



79
80
81
82
83
84
85
86
87
# File 'lib/grist/type/organization.rb', line 79

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

  grist_res.data["users"].map do |access|
    Access.new(access)
  end
end

.create_workspace(org_id, data) ⇒ Grist::Type::Workspace?

Create a new workspace in the organization



103
104
105
106
107
108
# File 'lib/grist/type/organization.rb', line 103

def self.create_workspace(org_id, data)
  org = find(org_id)
  return unless org

  org.create_workspace(data)
end

.list_workspaces(id) ⇒ Array

List workspaces in the organization



92
93
94
95
96
97
# File 'lib/grist/type/organization.rb', line 92

def self.list_workspaces(id)
  org = find(id)
  return [] unless org

  org.workspaces
end

Instance Method Details

#create_workspace(data) ⇒ Decidim::Type::Workspace?

Create a new Workspace in the organization



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/grist/type/organization.rb', line 53

def create_workspace(data)
  grist_res = request(:post, workspaces_path, data)

  unless grist_res.success?
    grist_res.print_error
    return
  end

  data["id"] = grist_res.data
  data.transform_keys!(&:to_s)

  ws = Workspace.new(data)
  @workspaces << ws

  ws
end

#workspaces_pathString

Get the path for the organization



72
73
74
# File 'lib/grist/type/organization.rb', line 72

def workspaces_path
  "#{path}/#{@id}/workspaces"
end