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

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



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/authentise/api/users.rb', line 51

def create_session(params)
  url = "https://users.authentise.com/sessions/"
  options = {
    content_type: :json,
    accept: :json,
    open_timeout: 2,
    timeout: 2,
  }
  body = params.to_json

  RestClient.post(url, body, options) do |response, _request, _result|
    if response.code == 201
      {
        token: response.cookies["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
40
41
# File 'lib/authentise/api/users.rb', line 20

def create_user(params)
  url = "https://users.authentise.com/users/"
  options = {
    content_type: :json,
    accept: :json,
    open_timeout: 2,
    timeout: 2,
  }
  body = params.to_json

  RestClient.post(url, body, options) 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