Class: Grist::Type::Organization
- 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
-
#workspaces ⇒ Array
readonly
List Workspaces in the organization.
Class Method Summary collapse
-
.access(id) ⇒ Array?
Get users which can access to the organization.
-
.create_workspace(org_id, data) ⇒ Grist::Type::Workspace?
Create a new workspace in the organization.
-
.list_workspaces(id) ⇒ Array
List workspaces in the organization.
Instance Method Summary collapse
-
#create_workspace(data) ⇒ Decidim::Type::Workspace?
Create a new Workspace in the organization.
-
#initialize(params = {}) ⇒ Grist::Type::Organization
constructor
Initialize a new Organization ).
-
#workspaces_path ⇒ String
Get the path for the organization.
Methods inherited from Base
all, delete, #deleted?, find, #keys, update
Methods included from Searchable
Methods included from Accessible
Methods included from Rest
#create, #delete, #get, #list, #path, #request, #update
Constructor Details
#initialize(params = {}) ⇒ Grist::Type::Organization
Note:
Initialize a new Organization )
32 33 34 35 |
# File 'lib/grist/type/organization.rb', line 32 def initialize(params = {}) super params @workspaces = [] end |
Instance Attribute Details
#workspaces ⇒ Array (readonly)
Note:
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_path ⇒ String
Get the path for the organization
72 73 74 |
# File 'lib/grist/type/organization.rb', line 72 def workspaces_path "#{path}/#{@id}/workspaces" end |