Module: Eli

Defined in:
lib/eli.rb,
lib/eli/admin.rb,
lib/eli/client.rb,
lib/eli/config.rb,
lib/eli/version.rb,
lib/eli/rest_api.rb,
lib/eli/admin/app.rb,
lib/eli/admin/organization.rb

Overview

Documentation for Eli.

Public REST client used by applications integrating with Letmein. These are the end-user facing endpoints (sessions and account management). The methods are available directly on the Eli module, e.g. Eli.sign_in(...).

Defined Under Namespace

Modules: Admin Classes: Config, RestApi

Constant Summary collapse

VERSION =
"0.1.13"

Class Method Summary collapse

Class Method Details

.confirm(confirmation_token) ⇒ Object

Confirms user email.

Examples

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

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


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

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 user data.

Examples

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

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


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

def current_user(session_token)
  url = Eli::Config.base_url + "/rest/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.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" } }


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

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.refresh("JWT session token")
# 200
# { "data" => { "token" => "JWT session token" } }

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


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

def refresh(session_token)
  url = Eli::Config.base_url + "/rest/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.request_password_recovery("app token", "user@example.com")
# 200
# { "data" => { "message" => "password recovery was successfully requested" } }

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


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

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

.resend_account_confirmation_email(app_token, email) ⇒ Object

Resend email for account confirmation.

Examples

Eli.("App token", "user@example.com")
# 200
# { "data" => { "message" => "account confirmation email was successfully sent" } }

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


249
250
251
252
253
254
255
256
257
258
# File 'lib/eli/client.rb', line 249

def (app_token, email)
  url = Eli::Config.base_url + "/rest/accounts/confirm/resend"

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

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

.sign_in(app_token, email, password) ⇒ Object

Sign in.

Examples

Eli.("app token", "user.email@domain.com", "secret.password")
# 200
# { "data" => { "token" => "JWT session token" } }

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


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

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

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

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

.sign_out(session_token) ⇒ Object

Signs user out closing and deleting session.

Examples

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

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


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

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

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

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

.signed_in(session_token) ⇒ Object

Checks whether the user is signed in or not.

Examples

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


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

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

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

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

.unlock(unlock_token) ⇒ Object

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

Examples

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

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


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

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

  options = {
    params: { token: unlock_token }
  }

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

.update_password(session_token, passwords) ⇒ Object

Updates the password of the signed in user.

Examples

passwords = {
  current_password: "Secret.123",
  new_password: "NewSecret.1234",
  new_password_confirmation: "NewSecret.1234"
}
Eli.update_password("JWT session token", passwords)
# 200
# { "data" => { "message" => "password was successfully changed" } }

# 400 or 404
# { "errors" => { "detail" => "Error message" } }


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

def update_password(session_token, passwords)
  url = Eli::Config.base_url + "/rest/accounts/password/update"

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

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