Module: Eli::Admin

Defined in:
lib/eli/admin.rb,
lib/eli/admin/app.rb,
lib/eli/admin/organization.rb

Overview

Documentation for Eli::Admin.

Administrative REST client used to manage admin sessions, accounts and to sign users in on their behalf.

Defined Under Namespace

Classes: App, Organization

Class Method Summary collapse

Class Method Details

.confirm(confirmation_token) ⇒ Object

Confirms user's email.

Examples

Eli::Admin.confirm("Confirmation token")
# 202
# { "data" => { "message" => "account was successfully confirmed" } }

# 404
# { "errors" => { "detail" => "Not Found" } }


151
152
153
154
155
156
157
158
159
# File 'lib/eli/admin.rb', line 151

def confirm(confirmation_token)
  url = Eli::Config.base_url + "/rest/accounts/confirm"

  options = {
    params: { token: confirmation_token }
  }

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

.current_user(session_token) ⇒ Object

Returns the current admin user data.

Examples

Eli::Admin.current_user("JWT session token")
# 200
# {
#   "data" => {
#     "active" => true,
#     "email" => "user@mail.com",
#     "id" => "732cf1c2-6299-41fa-8784-e458765743b7",
#     "language" => "en",
#     "name" => "User Name",
#     "timezone" => "Europe/London"
#   }
# }

# 404
# { "errors" => { "detail" => "Not Found" } }


71
72
73
74
75
76
77
78
79
# File 'lib/eli/admin.rb', line 71

def current_user(session_token)
  url = Eli::Config.base_url + "/rest/admin/sessions"

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

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

.recover_password(token, password, password_confirmation) ⇒ Object

Recover password updating it.

Examples

Eli::Admin.recover_password("token", "Secret.123", "Secret.123")
# 200
# { "data" => { "message" => "password was successfully recovered" } }

# 400
# { "errors" => { "detail" => "token is invalid" } }

# 400
# { "errors" => { "detail" => "password has an invalid format" } }

# 400
# { "errors" => { "detail" => "password and confirmation password are different" } }


198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/eli/admin.rb', line 198

def recover_password(token, password, password_confirmation)
  url = Eli::Config.base_url + "/rest/accounts/password/recover"

  options = {
    params: {
      token: token,
      password: password,
      password_confirmation: password_confirmation
    }
  }

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

.refresh(session_token) ⇒ Object

Refresh your token session returning a new session token.

Examples

Eli::Admin.refresh("JWT session token")
# 200
# { "data" => { "token" => "JWT session token" } }

# 404
# { "errors" => { "detail" => "Not Found" } }


91
92
93
94
95
96
97
98
99
# File 'lib/eli/admin.rb', line 91

def refresh(session_token)
  url = Eli::Config.base_url + "/rest/admin/sessions"

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

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

.request_password_recovery(app_token, email) ⇒ Object

Requests password recovery.

Examples

Eli::Admin.request_password_recovery("app token", "user@example.com")
# 200
# { "data" => { "message" => "password recovery was successfully requested" } }

# 404
# { "errors" => { "detail" => "Not Found" } }


171
172
173
174
175
176
177
178
179
180
# File 'lib/eli/admin.rb', line 171

def request_password_recovery(app_token, email)
  url = Eli::Config.base_url + "/rest/accounts/password/recover"

  options = {
    headers: { "app-token" => app_token },
    params: { email: email }
  }

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

.sign_in(email, password) ⇒ Object

Sign in.

Examples

Eli::Admin.("user.email@domain.com", "seCr#t.passw0rd")
# 200
# { "data" => { "token" => "JWT session token" } }

# 400
# { "errors" => { "detail" => "invalid credentials" } }


21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/eli/admin.rb', line 21

def (email, password)
  url = Eli::Config.base_url + "/rest/admin/sessions"

  options = {
    params: {
      email: email,
      password: password
    }
  }

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

.sign_out(session_token) ⇒ Object

Signs the admin user out closing and deleting the session.

Examples

Eli::Admin.sign_out("JWT session token")
# 200
# { "data" => { "message" => "signed out successfully" } }

# 404
# { "errors" => { "detail" => "Not Found" } }


111
112
113
114
115
116
117
118
119
# File 'lib/eli/admin.rb', line 111

def sign_out(session_token)
  url = Eli::Config.base_url + "/rest/admin/sessions"

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

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

.signed_in(session_token) ⇒ Object

Checks whether the admin user is signed in or not.

Examples

Eli::Admin.signed_in("JWT session token")
# true
# false


41
42
43
44
45
46
47
48
49
50
# File 'lib/eli/admin.rb', line 41

def signed_in(session_token)
  url = Eli::Config.base_url + "/rest/admin/sessions/signed_in"

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

  resp = Eli::RestApi.head(url, options)
  resp.status == 200
end

.signs_in(session_token, user_data, app_id) ⇒ Object

Admin signs in any user without password.

Examples

Eli::Admin.signs_in(
  "JWT session token",
  { email: "user.email@domain.com", name: "User Name" },
  "app_id"
)
# 200
# { "data" => { "user" => { "active" => true, "email" => "..." } } }

# 400
# { "errors" => { "detail" => "invalid credentials" } }


226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/eli/admin.rb', line 226

def signs_in(session_token, user_data, app_id)
  url = Eli::Config.base_url + "/rest/admin/sessions/signs_in"

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

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

.unlock(unlock_token) ⇒ Object

Unlocks user making him/her able to sign in again.

Examples

Eli::Admin.unlock("Unlock token")
# 202
# { "data" => { "message" => "account was successfully unlocked" } }

# 404
# { "errors" => { "detail" => "Not Found" } }


131
132
133
134
135
136
137
138
139
# File 'lib/eli/admin.rb', line 131

def unlock(unlock_token)
  url = Eli::Config.base_url + "/rest/accounts/unlock"

  options = {
    params: { token: unlock_token }
  }

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