Class: Eli::Admin::App

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

Overview

Represents an App belonging to an organization and exposes the administrative endpoints to manage apps, their users and tokens.

Instances carry the attributes used by create and update:

app = Eli::Admin::App.new(
  name: "New App Name",
  description: "New App Description",
  organization_id: "3d36fb7c-bbb6-4b27-8945-c7880de5484f",
  unlock_sign_in_url: "http://localhost:4000"
)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: nil, description: nil, organization_id: nil, unlock_sign_in_url: nil) ⇒ App

Returns a new instance of App.



19
20
21
22
23
24
# File 'lib/eli/admin/app.rb', line 19

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

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#organization_idObject

Returns the value of attribute organization_id.



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

def organization_id
  @organization_id
end

#unlock_sign_in_urlObject

Returns the value of attribute unlock_sign_in_url.



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

def 
  @unlock_sign_in_url
end

Class Method Details

.add_app_user(session_token, organization_id, id, email, password) ⇒ Object

Add app user.

Examples

Eli::Admin::App.add_app_user(
  "JWT session token",
  "3d36fb7c-bbb6-4b27-8945-c7880de5484f",
  "5223b223-52f0-4e61-afbe-e44ce60515e4",
  "one.more_user@domain.com",
  "Secret.123!"
)
# status: 201
# body: { "data" => { "id" => "...", "user" => { ... } } }


185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/eli/admin/app.rb', line 185

def add_app_user(session_token, organization_id, id, email, password)
  url = Eli::Config.base_url +
        "/rest/admin/organizations/" + organization_id + "/apps/" + id + "/users"

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

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

.create(session_token, app) ⇒ Object

Examples

app = Eli::Admin::App.new(
  name: "New App Name",
  description: "New App Description",
  organization_id: "3d36fb7c-bbb6-4b27-8945-c7880de5484f",
  unlock_sign_in_url: "http://localhost:4000"
)

Eli::Admin::App.create("JWT session token", app)
# status: 201
# body: { "data" => { "description" => "New App Description",
#                     "id" => "319f3afa-69bd-4bcc-b168-f26613c9581f",
#                     "name" => "New App Name" } }


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/eli/admin/app.rb', line 41

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

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

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

.create_token(session_token, organization_id, app_id) ⇒ Object

Create token.

Examples

Eli::Admin::App.create_token(
  "JWT session token",
  "3d36fb7c-bbb6-4b27-8945-c7880de5484f",
  "5223b223-52f0-4e61-afbe-e44ce60515e4"
)
# status: 201
# body: { "data" => { "app_id" => "...", "id" => "...", "token" => "..." } }


235
236
237
238
239
240
241
242
243
244
# File 'lib/eli/admin/app.rb', line 235

def create_token(session_token, organization_id, app_id)
  url = Eli::Config.base_url +
        "/rest/admin/organizations/" + organization_id + "/apps/" + app_id + "/tokens"

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

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

.delete(session_token, organization_id, id) ⇒ Object

Examples

Eli::Admin::App.delete(
  "JWT session token",
  "3d36fb7c-bbb6-4b27-8945-c7880de5484f",
  "319f3afa-69bd-4bcc-b168-f26613c9581f"
)
# status: 204
# body: ""


138
139
140
141
142
143
144
145
146
# File 'lib/eli/admin/app.rb', line 138

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

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

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

.get(session_token, organization_id, id) ⇒ Object

Examples

Eli::Admin::App.get(
  "JWT session token",
  "3d36fb7c-bbb6-4b27-8945-c7880de5484f",
  "5223b223-52f0-4e61-afbe-e44ce60515e4"
)
# status: 200
# body: { "data" => { "description" => nil,
#                     "id" => "5223b223-52f0-4e61-afbe-e44ce60515e4",
#                     "name" => "App Test" } }


88
89
90
91
92
93
94
95
96
# File 'lib/eli/admin/app.rb', line 88

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

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

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

.get_token(session_token, organization_id, app_id, id) ⇒ Object

Show token.

Examples

Eli::Admin::App.get_token(
  "JWT session token",
  "3d36fb7c-bbb6-4b27-8945-c7880de5484f",
  "5223b223-52f0-4e61-afbe-e44ce60515e4",
  "63cb25d9-d321-4f0e-aa24-a195e3aea2c4"
)
# status: 200
# body: { "data" => { "app_id" => "...", "id" => "..." } }


284
285
286
287
288
289
290
291
292
293
294
# File 'lib/eli/admin/app.rb', line 284

def get_token(session_token, organization_id, app_id, id)
  url = Eli::Config.base_url +
        "/rest/admin/organizations/" + organization_id +
        "/apps/" + app_id + "/tokens/" + id

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

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

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

Examples

Eli::Admin::App.list("JWT session token", "3d36fb7c-bbb6-4b27-8945-c7880de5484f")
# status: 200
# body: { "data" => [ ... ], "pagination" => { ... } }


63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/eli/admin/app.rb', line 63

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

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

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

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

Examples

Eli::Admin::App.list_app_users(
  "JWT session token",
  "3d36fb7c-bbb6-4b27-8945-c7880de5484f",
  "5223b223-52f0-4e61-afbe-e44ce60515e4"
)
# status: 200
# body: { "data" => [ ... ], "pagination" => { ... } }


157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/eli/admin/app.rb', line 157

def list_app_users(session_token, organization_id, id, page = 1, per_page = 20)
  url = Eli::Config.base_url +
        "/rest/admin/organizations/" + organization_id + "/apps/" + id + "/users"

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

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

.list_tokens(session_token, organization_id, app_id, page = 1, per_page = 20) ⇒ Object

List tokens.

Examples

Eli::Admin::App.list_tokens(
  "JWT session token",
  "3d36fb7c-bbb6-4b27-8945-c7880de5484f",
  "5223b223-52f0-4e61-afbe-e44ce60515e4"
)
# status: 200
# body: { "data" => [ ... ], "pagination" => { ... } }


257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/eli/admin/app.rb', line 257

def list_tokens(session_token, organization_id, app_id, page = 1, per_page = 20)
  url = Eli::Config.base_url +
        "/rest/admin/organizations/" + organization_id + "/apps/" + app_id + "/tokens"

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

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

.remove_app_user(session_token, organization_id, id, app_user_id) ⇒ Object

Remove app user.

Examples

Eli::Admin::App.remove_app_user(
  "JWT session token",
  "3d36fb7c-bbb6-4b27-8945-c7880de5484f",
  "5223b223-52f0-4e61-afbe-e44ce60515e4",
  "b05b504b-d737-4962-835c-f5bc8a2518e2"
)
# status: 204
# body: ""


212
213
214
215
216
217
218
219
220
221
222
# File 'lib/eli/admin/app.rb', line 212

def remove_app_user(session_token, organization_id, id, app_user_id)
  url = Eli::Config.base_url +
        "/rest/admin/organizations/" + organization_id +
        "/apps/" + id + "/users/" + app_user_id

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

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

.revoke_token(session_token, organization_id, app_id, id) ⇒ Object

Revoke a token.

Examples

Eli::Admin::App.revoke_token(
  "JWT session token",
  "3d36fb7c-bbb6-4b27-8945-c7880de5484f",
  "5223b223-52f0-4e61-afbe-e44ce60515e4",
  "63cb25d9-d321-4f0e-aa24-a195e3aea2c4"
)
# status: 204
# body: ""


308
309
310
311
312
313
314
315
316
317
318
# File 'lib/eli/admin/app.rb', line 308

def revoke_token(session_token, organization_id, app_id, id)
  url = Eli::Config.base_url +
        "/rest/admin/organizations/" + organization_id +
        "/apps/" + app_id + "/tokens/" + id

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

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

.update(session_token, id, app) ⇒ Object

Examples

app = Eli::Admin::App.new(
  name: "Another App Name",
  description: "Changed Description",
  organization_id: "3d36fb7c-bbb6-4b27-8945-c7880de5484f",
  unlock_sign_in_url: "http://localhost:4000"
)

Eli::Admin::App.update("JWT session token", "319f3afa-69bd-4bcc-b168-f26613c9581f", app)
# status: 200
# body: { "data" => { "description" => "Changed Description",
#                     "id" => "319f3afa-69bd-4bcc-b168-f26613c9581f",
#                     "name" => "Another App Name" } }


112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/eli/admin/app.rb', line 112

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

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

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