Module: Authentise::API::Users
- Defined in:
- lib/authentise/api/users.rb
Overview
Calls to create a user and authenticate over the API
Class Method Summary collapse
-
.create_session(params) ⇒ Object
Create a new session to use in other API calls.
-
.create_user(params) ⇒ Object
Create a new user to use the API.
Class Method Details
.create_session(params) ⇒ Object
Create a new session to use in other API calls.
Params:
-
username
-
password
Returns a hash with:
-
token: cookie token to add to the following API cooke calls
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/authentise/api/users.rb', line 49 def create_session(params) url = "https://users.authentise.com/sessions/" = { content_type: :json, accept: :json, open_timeout: 2, timeout: 2, } RestClient.post(url, params, ) do |response, _request, _result| if response.code == 201 { token: response.["session"], } else fail UnknownResponseCodeError.new(response.code, response) end end end |
.create_user(params) ⇒ Object
Create a new user to use the API.
Params:
-
email
-
name
-
username
-
password
Returns a hash with:
-
url: URL to the new user
-
uuid: unique id for this user
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/authentise/api/users.rb', line 20 def create_user(params) url = "https://users.authentise.com/users/" = { content_type: :json, accept: :json, open_timeout: 2, timeout: 2, } RestClient.post(url, params, ) do |response, _request, _result| json = JSON.parse(response) if response.code == 201 { url: json["uri"], uuid: json["uuid"], } else fail UnknownResponseCodeError.new(response.code, response) end end end |