Class: Eli::Admin::Organization

Inherits:
Object
  • Object
show all
Defined in:
lib/eli/admin/organization.rb

Overview

Represents an Organization and exposes the administrative endpoints to manage organizations and their admin users.

Instances carry the attributes used by create and update:

organization = Eli::Admin::Organization.new(
  name: "New Organization",
  description: "New organization description"
)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: nil, description: nil) ⇒ Organization

Returns a new instance of Organization.



17
18
19
20
# File 'lib/eli/admin/organization.rb', line 17

def initialize(name: nil, description: nil)
  @name = name
  @description = description
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



15
16
17
# File 'lib/eli/admin/organization.rb', line 15

def description
  @description
end

#nameObject

Returns the value of attribute name.



15
16
17
# File 'lib/eli/admin/organization.rb', line 15

def name
  @name
end

Class Method Details

.add_admin_user(session_token, id, email) ⇒ Object

Examples

Eli::Admin::Organization.add_admin_user(
  "Session token",
  "c28de4d1-14ea-4494-99a9-cf7cf9f8f186",
  "user.email@domain.com"
)
# status: 201
# body: { "data" => { "id" => "...", "user" => { ... } } }


165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/eli/admin/organization.rb', line 165

def add_admin_user(session_token, id, email)
  url = Eli::Config.base_url + "/rest/admin/organizations/" + id + "/admin_users"

  options = {
    params: {
      email: email
    },
    headers: { "authorization" => "Bearer #{session_token}" }
  }

  Eli::RestApi.post(url, options)
end

.create(session_token, organization) ⇒ Object

Examples

organization = Eli::Admin::Organization.new(
  name: "New Organization",
  description: "New orgranization description"
)

Eli::Admin::Organization.create("JWT session token", organization)
# status: 201
# body: { "data" => { "description" => "New orgranization description",
#                     "id" => "bf893f08-72ba-46f7-9320-0aec814d668c",
#                     "name" => "New Organization" } }


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/eli/admin/organization.rb', line 35

def create(session_token, organization)
  url = Eli::Config.base_url + "/rest/admin/organizations"

  options = {
    params: {
      organization: {
        name: organization.name,
        description: organization.description
      }
    },
    headers: { "authorization" => "Bearer #{session_token}" }
  }

  Eli::RestApi.post(url, options)
end

.delete(session_token, id) ⇒ Object

Examples

Eli::Admin::Organization.delete("JWT session token", "00543b54-ab48-458d-b73a-3fe0177315aa")
# status: 204
# body: ""


124
125
126
127
128
129
130
131
132
# File 'lib/eli/admin/organization.rb', line 124

def delete(session_token, id)
  url = Eli::Config.base_url + "/rest/admin/organizations/" + id

  options = {
    headers: { "authorization" => "Bearer #{session_token}" }
  }

  Eli::RestApi.delete(url, options)
end

.get(session_token, id) ⇒ Object

Examples

Eli::Admin::Organization.get("JWT session token", "76f4b18b-e612-438c-a1e2-74b12beccdd1")
# status: 200
# body: { "data" => { "description" => "A description example",
#                     "id" => "76f4b18b-e612-438c-a1e2-74b12beccdd1",
#                     "name" => "Org Name Example" } }


77
78
79
80
81
82
83
84
85
# File 'lib/eli/admin/organization.rb', line 77

def get(session_token, id)
  url = Eli::Config.base_url + "/rest/admin/organizations/" + id

  options = {
    headers: { "authorization" => "Bearer #{session_token}" }
  }

  Eli::RestApi.get(url, options)
end

.list(session_token, page = 1, per_page = 20) ⇒ Object

Examples

Eli::Admin::Organization.list("JWT session token")
# status: 200
# body: { "data" => [ ... ], "pagination" => { ... } }


56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/eli/admin/organization.rb', line 56

def list(session_token, page = 1, per_page = 20)
  url = Eli::Config.base_url + "/rest/admin/organizations"

  options = {
    params: {
      page: page,
      per_page: per_page
    },
    headers: { "authorization" => "Bearer #{session_token}" }
  }

  Eli::RestApi.get(url, options)
end

.list_admin_users(session_token, id, page = 1, per_page = 20) ⇒ Object

Examples

Eli::Admin::Organization.list_admin_users(
  "Session token",
  "c28de4d1-14ea-4494-99a9-cf7cf9f8f186"
)
# status: 200
# body: { "data" => [ ... ], "pagination" => { ... } }


142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/eli/admin/organization.rb', line 142

def list_admin_users(session_token, id, page = 1, per_page = 20)
  url = Eli::Config.base_url + "/rest/admin/organizations/" + id + "/admin_users"

  options = {
    params: {
      page: page,
      per_page: per_page
    },
    headers: { "authorization" => "Bearer #{session_token}" }
  }

  Eli::RestApi.get(url, options)
end

.remove_admin_user(session_token, id, organization_admin_user_id) ⇒ Object

Examples

Eli::Admin::Organization.remove_admin_user(
  "Session token",
  "c28de4d1-14ea-4494-99a9-cf7cf9f8f186",
  "47dff89a-97ca-4eca-8057-2a9398d90e03"
)
# status: 204
# body: ""


187
188
189
190
191
192
193
194
195
196
# File 'lib/eli/admin/organization.rb', line 187

def remove_admin_user(session_token, id, organization_admin_user_id)
  url = Eli::Config.base_url +
        "/rest/admin/organizations/" + id + "/admin_users/" + organization_admin_user_id

  options = {
    headers: { "authorization" => "Bearer #{session_token}" }
  }

  Eli::RestApi.delete(url, options)
end

.update(session_token, id, organization) ⇒ Object

Examples

organization = Eli::Admin::Organization.new(
  name: "New name for Organization",
  description: "New Some description"
)

Eli::Admin::Organization.update(
  "JWT session token",
  "00543b54-ab48-458d-b73a-3fe0177315aa",
  organization
)
# status: 200
# body: { "data" => { "description" => "New Some description",
#                     "id" => "00543b54-ab48-458d-b73a-3fe0177315aa",
#                     "name" => "New name for Organization" } }


103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/eli/admin/organization.rb', line 103

def update(session_token, id, organization)
  url = Eli::Config.base_url + "/rest/admin/organizations/" + id

  options = {
    params: {
      organization: {
        name: organization.name,
        description: organization.description
      }
    },
    headers: { "authorization" => "Bearer #{session_token}" }
  }

  Eli::RestApi.put(url, options)
end