eli 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +146 -0
- data/lib/eli/admin/app.rb +322 -0
- data/lib/eli/admin/organization.rb +200 -0
- data/lib/eli/admin.rb +240 -0
- data/lib/eli/client.rb +259 -0
- data/lib/eli/config.rb +39 -0
- data/lib/eli/rest_api.rb +171 -0
- data/lib/eli/version.rb +5 -0
- data/lib/eli.rb +13 -0
- metadata +137 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 9cdbb2b2e204e2d47796915fb1333006eaaa07285105546ac5c8a1b7920697e7
|
|
4
|
+
data.tar.gz: 5628df01ace38d93283345e0824eb5782666c52cd673477a61f4597536cbc56c
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 9b91b4d86c32961aa378621ba08f76d22f960943e7da5894f7896de09c1b09a069ae4fb7dfd9153831c4ebe80e08803ba03065e2ffe1c24744ccda506e759765
|
|
7
|
+
data.tar.gz: 263cd04e49743941101c5f107960d27cd5a08e6f6148f581264e61df194e9e8fb76253ef6d288b876e05830dbfe50c0075a8faa267e0652960fb9c9a02809216
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Adilson Chacon Cavalcanti
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# Eli
|
|
2
|
+
|
|
3
|
+
Library for Letmein Integration.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem "eli"
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
bundle install
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
gem install eli
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Configuration
|
|
26
|
+
|
|
27
|
+
Set the base URL of the Letmein server you are integrating with. It defaults to
|
|
28
|
+
`http://localhost:4000` and can also be provided through the `LETMEIN_BASE_URL`
|
|
29
|
+
environment variable.
|
|
30
|
+
|
|
31
|
+
```ruby
|
|
32
|
+
Eli::Config.base_url = "http://localhost:4000"
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Usage
|
|
36
|
+
|
|
37
|
+
### Public API
|
|
38
|
+
|
|
39
|
+
```ruby
|
|
40
|
+
# Sign in and obtain a session token
|
|
41
|
+
response = Eli.sign_in("app token", "user.email@domain.com", "secret.password")
|
|
42
|
+
response.status # => 200
|
|
43
|
+
response.body # => { "data" => { "token" => "JWT session token" } }
|
|
44
|
+
|
|
45
|
+
# Check whether a session token is still valid
|
|
46
|
+
Eli.signed_in("JWT session token") # => true / false
|
|
47
|
+
|
|
48
|
+
# Current user, refresh and sign out
|
|
49
|
+
Eli.current_user("JWT session token")
|
|
50
|
+
Eli.refresh("JWT session token")
|
|
51
|
+
Eli.sign_out("JWT session token")
|
|
52
|
+
|
|
53
|
+
# Account management
|
|
54
|
+
Eli.unlock("Unlock token")
|
|
55
|
+
Eli.confirm("Confirmation token")
|
|
56
|
+
Eli.request_password_recovery("app token", "user@example.com")
|
|
57
|
+
Eli.recover_password("token", "Secret.123", "Secret.123")
|
|
58
|
+
Eli.update_password("JWT session token", {
|
|
59
|
+
current_password: "Secret.123",
|
|
60
|
+
new_password: "NewSecret.1234",
|
|
61
|
+
new_password_confirmation: "NewSecret.1234"
|
|
62
|
+
})
|
|
63
|
+
Eli.resend_account_confirmation_email("App token", "user@example.com")
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Admin API
|
|
67
|
+
|
|
68
|
+
```ruby
|
|
69
|
+
# Admin sessions
|
|
70
|
+
Eli::Admin.sign_in("user.email@domain.com", "seCr#t.passw0rd")
|
|
71
|
+
Eli::Admin.signed_in("JWT session token")
|
|
72
|
+
Eli::Admin.current_user("JWT session token")
|
|
73
|
+
Eli::Admin.refresh("JWT session token")
|
|
74
|
+
Eli::Admin.sign_out("JWT session token")
|
|
75
|
+
|
|
76
|
+
# Sign a user in on their behalf
|
|
77
|
+
Eli::Admin.signs_in(
|
|
78
|
+
"JWT session token",
|
|
79
|
+
{ email: "user.email@domain.com", name: "User Name" },
|
|
80
|
+
"app_id"
|
|
81
|
+
)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Organizations
|
|
85
|
+
|
|
86
|
+
```ruby
|
|
87
|
+
organization = Eli::Admin::Organization.new(
|
|
88
|
+
name: "New Organization",
|
|
89
|
+
description: "New organization description"
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
Eli::Admin::Organization.create("JWT session token", organization)
|
|
93
|
+
Eli::Admin::Organization.list("JWT session token")
|
|
94
|
+
Eli::Admin::Organization.get("JWT session token", "organization-id")
|
|
95
|
+
Eli::Admin::Organization.update("JWT session token", "organization-id", organization)
|
|
96
|
+
Eli::Admin::Organization.delete("JWT session token", "organization-id")
|
|
97
|
+
|
|
98
|
+
Eli::Admin::Organization.list_admin_users("JWT session token", "organization-id")
|
|
99
|
+
Eli::Admin::Organization.add_admin_user("JWT session token", "organization-id", "user@domain.com")
|
|
100
|
+
Eli::Admin::Organization.remove_admin_user("JWT session token", "organization-id", "admin-user-id")
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Apps
|
|
104
|
+
|
|
105
|
+
```ruby
|
|
106
|
+
app = Eli::Admin::App.new(
|
|
107
|
+
name: "New App Name",
|
|
108
|
+
description: "New App Description",
|
|
109
|
+
organization_id: "organization-id",
|
|
110
|
+
unlock_sign_in_url: "http://localhost:4000"
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
Eli::Admin::App.create("JWT session token", app)
|
|
114
|
+
Eli::Admin::App.list("JWT session token", "organization-id")
|
|
115
|
+
Eli::Admin::App.get("JWT session token", "organization-id", "app-id")
|
|
116
|
+
Eli::Admin::App.update("JWT session token", "app-id", app)
|
|
117
|
+
Eli::Admin::App.delete("JWT session token", "organization-id", "app-id")
|
|
118
|
+
|
|
119
|
+
# App users
|
|
120
|
+
Eli::Admin::App.list_app_users("JWT session token", "organization-id", "app-id")
|
|
121
|
+
Eli::Admin::App.add_app_user("JWT session token", "organization-id", "app-id", "user@domain.com", "Secret.123!")
|
|
122
|
+
Eli::Admin::App.remove_app_user("JWT session token", "organization-id", "app-id", "app-user-id")
|
|
123
|
+
|
|
124
|
+
# Tokens
|
|
125
|
+
Eli::Admin::App.create_token("JWT session token", "organization-id", "app-id")
|
|
126
|
+
Eli::Admin::App.list_tokens("JWT session token", "organization-id", "app-id")
|
|
127
|
+
Eli::Admin::App.get_token("JWT session token", "organization-id", "app-id", "token-id")
|
|
128
|
+
Eli::Admin::App.revoke_token("JWT session token", "organization-id", "app-id", "token-id")
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Responses
|
|
132
|
+
|
|
133
|
+
Every request returns an `Eli::RestApi::Response` value object exposing:
|
|
134
|
+
|
|
135
|
+
- `status` — the HTTP status code as an integer.
|
|
136
|
+
- `body` — the response body, parsed from JSON into a Hash/Array when possible.
|
|
137
|
+
|
|
138
|
+
## Development
|
|
139
|
+
|
|
140
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then run
|
|
141
|
+
`bundle exec rake spec` to run the tests.
|
|
142
|
+
|
|
143
|
+
## License
|
|
144
|
+
|
|
145
|
+
The gem is available as open source under the terms of the
|
|
146
|
+
[MIT License](LICENSE).
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Eli
|
|
4
|
+
module Admin
|
|
5
|
+
# Represents an App belonging to an organization and exposes the
|
|
6
|
+
# administrative endpoints to manage apps, their users and tokens.
|
|
7
|
+
#
|
|
8
|
+
# Instances carry the attributes used by `create` and `update`:
|
|
9
|
+
#
|
|
10
|
+
# app = Eli::Admin::App.new(
|
|
11
|
+
# name: "New App Name",
|
|
12
|
+
# description: "New App Description",
|
|
13
|
+
# organization_id: "3d36fb7c-bbb6-4b27-8945-c7880de5484f",
|
|
14
|
+
# unlock_sign_in_url: "http://localhost:4000"
|
|
15
|
+
# )
|
|
16
|
+
class App
|
|
17
|
+
attr_accessor :name, :description, :organization_id, :unlock_sign_in_url
|
|
18
|
+
|
|
19
|
+
def initialize(name: nil, description: nil, organization_id: nil, unlock_sign_in_url: nil)
|
|
20
|
+
@name = name
|
|
21
|
+
@description = description
|
|
22
|
+
@organization_id = organization_id
|
|
23
|
+
@unlock_sign_in_url = unlock_sign_in_url
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
class << self
|
|
27
|
+
# ## Examples
|
|
28
|
+
#
|
|
29
|
+
# app = Eli::Admin::App.new(
|
|
30
|
+
# name: "New App Name",
|
|
31
|
+
# description: "New App Description",
|
|
32
|
+
# organization_id: "3d36fb7c-bbb6-4b27-8945-c7880de5484f",
|
|
33
|
+
# unlock_sign_in_url: "http://localhost:4000"
|
|
34
|
+
# )
|
|
35
|
+
#
|
|
36
|
+
# Eli::Admin::App.create("JWT session token", app)
|
|
37
|
+
# # status: 201
|
|
38
|
+
# # body: { "data" => { "description" => "New App Description",
|
|
39
|
+
# # "id" => "319f3afa-69bd-4bcc-b168-f26613c9581f",
|
|
40
|
+
# # "name" => "New App Name" } }
|
|
41
|
+
def create(session_token, app)
|
|
42
|
+
url = Eli::Config.base_url + "/rest/admin/organizations/" + app.organization_id + "/apps"
|
|
43
|
+
|
|
44
|
+
options = {
|
|
45
|
+
params: {
|
|
46
|
+
app: {
|
|
47
|
+
name: app.name,
|
|
48
|
+
description: app.description,
|
|
49
|
+
unlock_sign_in_url: app.unlock_sign_in_url
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
headers: { "authorization" => "Bearer #{session_token}" }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
Eli::RestApi.post(url, options)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# ## Examples
|
|
59
|
+
#
|
|
60
|
+
# Eli::Admin::App.list("JWT session token", "3d36fb7c-bbb6-4b27-8945-c7880de5484f")
|
|
61
|
+
# # status: 200
|
|
62
|
+
# # body: { "data" => [ ... ], "pagination" => { ... } }
|
|
63
|
+
def list(session_token, organization_id, page = 1, per_page = 20)
|
|
64
|
+
url = Eli::Config.base_url + "/rest/admin/organizations/" + organization_id + "/apps"
|
|
65
|
+
|
|
66
|
+
options = {
|
|
67
|
+
params: {
|
|
68
|
+
page: page,
|
|
69
|
+
per_page: per_page
|
|
70
|
+
},
|
|
71
|
+
headers: { "authorization" => "Bearer #{session_token}" }
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
Eli::RestApi.get(url, options)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# ## Examples
|
|
78
|
+
#
|
|
79
|
+
# Eli::Admin::App.get(
|
|
80
|
+
# "JWT session token",
|
|
81
|
+
# "3d36fb7c-bbb6-4b27-8945-c7880de5484f",
|
|
82
|
+
# "5223b223-52f0-4e61-afbe-e44ce60515e4"
|
|
83
|
+
# )
|
|
84
|
+
# # status: 200
|
|
85
|
+
# # body: { "data" => { "description" => nil,
|
|
86
|
+
# # "id" => "5223b223-52f0-4e61-afbe-e44ce60515e4",
|
|
87
|
+
# # "name" => "App Test" } }
|
|
88
|
+
def get(session_token, organization_id, id)
|
|
89
|
+
url = Eli::Config.base_url + "/rest/admin/organizations/" + organization_id + "/apps/" + id
|
|
90
|
+
|
|
91
|
+
options = {
|
|
92
|
+
headers: { "authorization" => "Bearer #{session_token}" }
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
Eli::RestApi.get(url, options)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# ## Examples
|
|
99
|
+
#
|
|
100
|
+
# app = Eli::Admin::App.new(
|
|
101
|
+
# name: "Another App Name",
|
|
102
|
+
# description: "Changed Description",
|
|
103
|
+
# organization_id: "3d36fb7c-bbb6-4b27-8945-c7880de5484f",
|
|
104
|
+
# unlock_sign_in_url: "http://localhost:4000"
|
|
105
|
+
# )
|
|
106
|
+
#
|
|
107
|
+
# Eli::Admin::App.update("JWT session token", "319f3afa-69bd-4bcc-b168-f26613c9581f", app)
|
|
108
|
+
# # status: 200
|
|
109
|
+
# # body: { "data" => { "description" => "Changed Description",
|
|
110
|
+
# # "id" => "319f3afa-69bd-4bcc-b168-f26613c9581f",
|
|
111
|
+
# # "name" => "Another App Name" } }
|
|
112
|
+
def update(session_token, id, app)
|
|
113
|
+
url = Eli::Config.base_url + "/rest/admin/organizations/" + app.organization_id + "/apps/" + id
|
|
114
|
+
|
|
115
|
+
options = {
|
|
116
|
+
params: {
|
|
117
|
+
app: {
|
|
118
|
+
name: app.name,
|
|
119
|
+
description: app.description,
|
|
120
|
+
unlock_sign_in_url: app.unlock_sign_in_url
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
headers: { "authorization" => "Bearer #{session_token}" }
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
Eli::RestApi.put(url, options)
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
# ## Examples
|
|
130
|
+
#
|
|
131
|
+
# Eli::Admin::App.delete(
|
|
132
|
+
# "JWT session token",
|
|
133
|
+
# "3d36fb7c-bbb6-4b27-8945-c7880de5484f",
|
|
134
|
+
# "319f3afa-69bd-4bcc-b168-f26613c9581f"
|
|
135
|
+
# )
|
|
136
|
+
# # status: 204
|
|
137
|
+
# # body: ""
|
|
138
|
+
def delete(session_token, organization_id, id)
|
|
139
|
+
url = Eli::Config.base_url + "/rest/admin/organizations/" + organization_id + "/apps/" + id
|
|
140
|
+
|
|
141
|
+
options = {
|
|
142
|
+
headers: { "authorization" => "Bearer #{session_token}" }
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
Eli::RestApi.delete(url, options)
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
# ## Examples
|
|
149
|
+
#
|
|
150
|
+
# Eli::Admin::App.list_app_users(
|
|
151
|
+
# "JWT session token",
|
|
152
|
+
# "3d36fb7c-bbb6-4b27-8945-c7880de5484f",
|
|
153
|
+
# "5223b223-52f0-4e61-afbe-e44ce60515e4"
|
|
154
|
+
# )
|
|
155
|
+
# # status: 200
|
|
156
|
+
# # body: { "data" => [ ... ], "pagination" => { ... } }
|
|
157
|
+
def list_app_users(session_token, organization_id, id, page = 1, per_page = 20)
|
|
158
|
+
url = Eli::Config.base_url +
|
|
159
|
+
"/rest/admin/organizations/" + organization_id + "/apps/" + id + "/users"
|
|
160
|
+
|
|
161
|
+
options = {
|
|
162
|
+
params: {
|
|
163
|
+
page: page,
|
|
164
|
+
per_page: per_page
|
|
165
|
+
},
|
|
166
|
+
headers: { "authorization" => "Bearer #{session_token}" }
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
Eli::RestApi.get(url, options)
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
# Add app user.
|
|
173
|
+
#
|
|
174
|
+
# ## Examples
|
|
175
|
+
#
|
|
176
|
+
# Eli::Admin::App.add_app_user(
|
|
177
|
+
# "JWT session token",
|
|
178
|
+
# "3d36fb7c-bbb6-4b27-8945-c7880de5484f",
|
|
179
|
+
# "5223b223-52f0-4e61-afbe-e44ce60515e4",
|
|
180
|
+
# "one.more_user@domain.com",
|
|
181
|
+
# "Secret.123!"
|
|
182
|
+
# )
|
|
183
|
+
# # status: 201
|
|
184
|
+
# # body: { "data" => { "id" => "...", "user" => { ... } } }
|
|
185
|
+
def add_app_user(session_token, organization_id, id, email, password)
|
|
186
|
+
url = Eli::Config.base_url +
|
|
187
|
+
"/rest/admin/organizations/" + organization_id + "/apps/" + id + "/users"
|
|
188
|
+
|
|
189
|
+
options = {
|
|
190
|
+
params: {
|
|
191
|
+
password: password,
|
|
192
|
+
email: email
|
|
193
|
+
},
|
|
194
|
+
headers: { "authorization" => "Bearer #{session_token}" }
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
Eli::RestApi.post(url, options)
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
# Remove app user.
|
|
201
|
+
#
|
|
202
|
+
# ## Examples
|
|
203
|
+
#
|
|
204
|
+
# Eli::Admin::App.remove_app_user(
|
|
205
|
+
# "JWT session token",
|
|
206
|
+
# "3d36fb7c-bbb6-4b27-8945-c7880de5484f",
|
|
207
|
+
# "5223b223-52f0-4e61-afbe-e44ce60515e4",
|
|
208
|
+
# "b05b504b-d737-4962-835c-f5bc8a2518e2"
|
|
209
|
+
# )
|
|
210
|
+
# # status: 204
|
|
211
|
+
# # body: ""
|
|
212
|
+
def remove_app_user(session_token, organization_id, id, app_user_id)
|
|
213
|
+
url = Eli::Config.base_url +
|
|
214
|
+
"/rest/admin/organizations/" + organization_id +
|
|
215
|
+
"/apps/" + id + "/users/" + app_user_id
|
|
216
|
+
|
|
217
|
+
options = {
|
|
218
|
+
headers: { "authorization" => "Bearer #{session_token}" }
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
Eli::RestApi.delete(url, options)
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
# Create token.
|
|
225
|
+
#
|
|
226
|
+
# ## Examples
|
|
227
|
+
#
|
|
228
|
+
# Eli::Admin::App.create_token(
|
|
229
|
+
# "JWT session token",
|
|
230
|
+
# "3d36fb7c-bbb6-4b27-8945-c7880de5484f",
|
|
231
|
+
# "5223b223-52f0-4e61-afbe-e44ce60515e4"
|
|
232
|
+
# )
|
|
233
|
+
# # status: 201
|
|
234
|
+
# # body: { "data" => { "app_id" => "...", "id" => "...", "token" => "..." } }
|
|
235
|
+
def create_token(session_token, organization_id, app_id)
|
|
236
|
+
url = Eli::Config.base_url +
|
|
237
|
+
"/rest/admin/organizations/" + organization_id + "/apps/" + app_id + "/tokens"
|
|
238
|
+
|
|
239
|
+
options = {
|
|
240
|
+
headers: { "authorization" => "Bearer #{session_token}" }
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
Eli::RestApi.post(url, options)
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
# List tokens.
|
|
247
|
+
#
|
|
248
|
+
# ## Examples
|
|
249
|
+
#
|
|
250
|
+
# Eli::Admin::App.list_tokens(
|
|
251
|
+
# "JWT session token",
|
|
252
|
+
# "3d36fb7c-bbb6-4b27-8945-c7880de5484f",
|
|
253
|
+
# "5223b223-52f0-4e61-afbe-e44ce60515e4"
|
|
254
|
+
# )
|
|
255
|
+
# # status: 200
|
|
256
|
+
# # body: { "data" => [ ... ], "pagination" => { ... } }
|
|
257
|
+
def list_tokens(session_token, organization_id, app_id, page = 1, per_page = 20)
|
|
258
|
+
url = Eli::Config.base_url +
|
|
259
|
+
"/rest/admin/organizations/" + organization_id + "/apps/" + app_id + "/tokens"
|
|
260
|
+
|
|
261
|
+
options = {
|
|
262
|
+
params: {
|
|
263
|
+
page: page,
|
|
264
|
+
per_page: per_page
|
|
265
|
+
},
|
|
266
|
+
headers: { "authorization" => "Bearer #{session_token}" }
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
Eli::RestApi.get(url, options)
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
# Show token.
|
|
273
|
+
#
|
|
274
|
+
# ## Examples
|
|
275
|
+
#
|
|
276
|
+
# Eli::Admin::App.get_token(
|
|
277
|
+
# "JWT session token",
|
|
278
|
+
# "3d36fb7c-bbb6-4b27-8945-c7880de5484f",
|
|
279
|
+
# "5223b223-52f0-4e61-afbe-e44ce60515e4",
|
|
280
|
+
# "63cb25d9-d321-4f0e-aa24-a195e3aea2c4"
|
|
281
|
+
# )
|
|
282
|
+
# # status: 200
|
|
283
|
+
# # body: { "data" => { "app_id" => "...", "id" => "..." } }
|
|
284
|
+
def get_token(session_token, organization_id, app_id, id)
|
|
285
|
+
url = Eli::Config.base_url +
|
|
286
|
+
"/rest/admin/organizations/" + organization_id +
|
|
287
|
+
"/apps/" + app_id + "/tokens/" + id
|
|
288
|
+
|
|
289
|
+
options = {
|
|
290
|
+
headers: { "authorization" => "Bearer #{session_token}" }
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
Eli::RestApi.get(url, options)
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
# Revoke a token.
|
|
297
|
+
#
|
|
298
|
+
# ## Examples
|
|
299
|
+
#
|
|
300
|
+
# Eli::Admin::App.revoke_token(
|
|
301
|
+
# "JWT session token",
|
|
302
|
+
# "3d36fb7c-bbb6-4b27-8945-c7880de5484f",
|
|
303
|
+
# "5223b223-52f0-4e61-afbe-e44ce60515e4",
|
|
304
|
+
# "63cb25d9-d321-4f0e-aa24-a195e3aea2c4"
|
|
305
|
+
# )
|
|
306
|
+
# # status: 204
|
|
307
|
+
# # body: ""
|
|
308
|
+
def revoke_token(session_token, organization_id, app_id, id)
|
|
309
|
+
url = Eli::Config.base_url +
|
|
310
|
+
"/rest/admin/organizations/" + organization_id +
|
|
311
|
+
"/apps/" + app_id + "/tokens/" + id
|
|
312
|
+
|
|
313
|
+
options = {
|
|
314
|
+
headers: { "authorization" => "Bearer #{session_token}" }
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
Eli::RestApi.delete(url, options)
|
|
318
|
+
end
|
|
319
|
+
end
|
|
320
|
+
end
|
|
321
|
+
end
|
|
322
|
+
end
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Eli
|
|
4
|
+
module Admin
|
|
5
|
+
# Represents an Organization and exposes the administrative endpoints to
|
|
6
|
+
# manage organizations and their admin users.
|
|
7
|
+
#
|
|
8
|
+
# Instances carry the attributes used by `create` and `update`:
|
|
9
|
+
#
|
|
10
|
+
# organization = Eli::Admin::Organization.new(
|
|
11
|
+
# name: "New Organization",
|
|
12
|
+
# description: "New organization description"
|
|
13
|
+
# )
|
|
14
|
+
class Organization
|
|
15
|
+
attr_accessor :name, :description
|
|
16
|
+
|
|
17
|
+
def initialize(name: nil, description: nil)
|
|
18
|
+
@name = name
|
|
19
|
+
@description = description
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class << self
|
|
23
|
+
# ## Examples
|
|
24
|
+
#
|
|
25
|
+
# organization = Eli::Admin::Organization.new(
|
|
26
|
+
# name: "New Organization",
|
|
27
|
+
# description: "New orgranization description"
|
|
28
|
+
# )
|
|
29
|
+
#
|
|
30
|
+
# Eli::Admin::Organization.create("JWT session token", organization)
|
|
31
|
+
# # status: 201
|
|
32
|
+
# # body: { "data" => { "description" => "New orgranization description",
|
|
33
|
+
# # "id" => "bf893f08-72ba-46f7-9320-0aec814d668c",
|
|
34
|
+
# # "name" => "New Organization" } }
|
|
35
|
+
def create(session_token, organization)
|
|
36
|
+
url = Eli::Config.base_url + "/rest/admin/organizations"
|
|
37
|
+
|
|
38
|
+
options = {
|
|
39
|
+
params: {
|
|
40
|
+
organization: {
|
|
41
|
+
name: organization.name,
|
|
42
|
+
description: organization.description
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
headers: { "authorization" => "Bearer #{session_token}" }
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
Eli::RestApi.post(url, options)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# ## Examples
|
|
52
|
+
#
|
|
53
|
+
# Eli::Admin::Organization.list("JWT session token")
|
|
54
|
+
# # status: 200
|
|
55
|
+
# # body: { "data" => [ ... ], "pagination" => { ... } }
|
|
56
|
+
def list(session_token, page = 1, per_page = 20)
|
|
57
|
+
url = Eli::Config.base_url + "/rest/admin/organizations"
|
|
58
|
+
|
|
59
|
+
options = {
|
|
60
|
+
params: {
|
|
61
|
+
page: page,
|
|
62
|
+
per_page: per_page
|
|
63
|
+
},
|
|
64
|
+
headers: { "authorization" => "Bearer #{session_token}" }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
Eli::RestApi.get(url, options)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# ## Examples
|
|
71
|
+
#
|
|
72
|
+
# Eli::Admin::Organization.get("JWT session token", "76f4b18b-e612-438c-a1e2-74b12beccdd1")
|
|
73
|
+
# # status: 200
|
|
74
|
+
# # body: { "data" => { "description" => "A description example",
|
|
75
|
+
# # "id" => "76f4b18b-e612-438c-a1e2-74b12beccdd1",
|
|
76
|
+
# # "name" => "Org Name Example" } }
|
|
77
|
+
def get(session_token, id)
|
|
78
|
+
url = Eli::Config.base_url + "/rest/admin/organizations/" + id
|
|
79
|
+
|
|
80
|
+
options = {
|
|
81
|
+
headers: { "authorization" => "Bearer #{session_token}" }
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
Eli::RestApi.get(url, options)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# ## Examples
|
|
88
|
+
#
|
|
89
|
+
# organization = Eli::Admin::Organization.new(
|
|
90
|
+
# name: "New name for Organization",
|
|
91
|
+
# description: "New Some description"
|
|
92
|
+
# )
|
|
93
|
+
#
|
|
94
|
+
# Eli::Admin::Organization.update(
|
|
95
|
+
# "JWT session token",
|
|
96
|
+
# "00543b54-ab48-458d-b73a-3fe0177315aa",
|
|
97
|
+
# organization
|
|
98
|
+
# )
|
|
99
|
+
# # status: 200
|
|
100
|
+
# # body: { "data" => { "description" => "New Some description",
|
|
101
|
+
# # "id" => "00543b54-ab48-458d-b73a-3fe0177315aa",
|
|
102
|
+
# # "name" => "New name for Organization" } }
|
|
103
|
+
def update(session_token, id, organization)
|
|
104
|
+
url = Eli::Config.base_url + "/rest/admin/organizations/" + id
|
|
105
|
+
|
|
106
|
+
options = {
|
|
107
|
+
params: {
|
|
108
|
+
organization: {
|
|
109
|
+
name: organization.name,
|
|
110
|
+
description: organization.description
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
headers: { "authorization" => "Bearer #{session_token}" }
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
Eli::RestApi.put(url, options)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# ## Examples
|
|
120
|
+
#
|
|
121
|
+
# Eli::Admin::Organization.delete("JWT session token", "00543b54-ab48-458d-b73a-3fe0177315aa")
|
|
122
|
+
# # status: 204
|
|
123
|
+
# # body: ""
|
|
124
|
+
def delete(session_token, id)
|
|
125
|
+
url = Eli::Config.base_url + "/rest/admin/organizations/" + id
|
|
126
|
+
|
|
127
|
+
options = {
|
|
128
|
+
headers: { "authorization" => "Bearer #{session_token}" }
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
Eli::RestApi.delete(url, options)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# ## Examples
|
|
135
|
+
#
|
|
136
|
+
# Eli::Admin::Organization.list_admin_users(
|
|
137
|
+
# "Session token",
|
|
138
|
+
# "c28de4d1-14ea-4494-99a9-cf7cf9f8f186"
|
|
139
|
+
# )
|
|
140
|
+
# # status: 200
|
|
141
|
+
# # body: { "data" => [ ... ], "pagination" => { ... } }
|
|
142
|
+
def list_admin_users(session_token, id, page = 1, per_page = 20)
|
|
143
|
+
url = Eli::Config.base_url + "/rest/admin/organizations/" + id + "/admin_users"
|
|
144
|
+
|
|
145
|
+
options = {
|
|
146
|
+
params: {
|
|
147
|
+
page: page,
|
|
148
|
+
per_page: per_page
|
|
149
|
+
},
|
|
150
|
+
headers: { "authorization" => "Bearer #{session_token}" }
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
Eli::RestApi.get(url, options)
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
# ## Examples
|
|
157
|
+
#
|
|
158
|
+
# Eli::Admin::Organization.add_admin_user(
|
|
159
|
+
# "Session token",
|
|
160
|
+
# "c28de4d1-14ea-4494-99a9-cf7cf9f8f186",
|
|
161
|
+
# "user.email@domain.com"
|
|
162
|
+
# )
|
|
163
|
+
# # status: 201
|
|
164
|
+
# # body: { "data" => { "id" => "...", "user" => { ... } } }
|
|
165
|
+
def add_admin_user(session_token, id, email)
|
|
166
|
+
url = Eli::Config.base_url + "/rest/admin/organizations/" + id + "/admin_users"
|
|
167
|
+
|
|
168
|
+
options = {
|
|
169
|
+
params: {
|
|
170
|
+
email: email
|
|
171
|
+
},
|
|
172
|
+
headers: { "authorization" => "Bearer #{session_token}" }
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
Eli::RestApi.post(url, options)
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
# ## Examples
|
|
179
|
+
#
|
|
180
|
+
# Eli::Admin::Organization.remove_admin_user(
|
|
181
|
+
# "Session token",
|
|
182
|
+
# "c28de4d1-14ea-4494-99a9-cf7cf9f8f186",
|
|
183
|
+
# "47dff89a-97ca-4eca-8057-2a9398d90e03"
|
|
184
|
+
# )
|
|
185
|
+
# # status: 204
|
|
186
|
+
# # body: ""
|
|
187
|
+
def remove_admin_user(session_token, id, organization_admin_user_id)
|
|
188
|
+
url = Eli::Config.base_url +
|
|
189
|
+
"/rest/admin/organizations/" + id + "/admin_users/" + organization_admin_user_id
|
|
190
|
+
|
|
191
|
+
options = {
|
|
192
|
+
headers: { "authorization" => "Bearer #{session_token}" }
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
Eli::RestApi.delete(url, options)
|
|
196
|
+
end
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
end
|