Module: Brivo::API::Users

Includes:
HTTP
Included in:
Brivo::Application
Defined in:
lib/brivo/api/users.rb

Constant Summary

Constants included from HTTP

HTTP::API_URL, HTTP::DEFAULT_HTTPS_SETTINGS, HTTP::MAX_RETRIES, HTTP::PAGE_SIZE

Instance Method Summary collapse

Methods included from HTTP

#http_request, #set_access_token

Instance Method Details

#create_user(first_name, last_name, external_id, suspended = false) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/brivo/api/users.rb', line 33

def create_user first_name, last_name, external_id, suspended = false
  user_json = http_request(
    'users',
    params: {
      firstName: first_name,
      lastName: last_name,
      externalId: external_id,
      suspended: suspended
    },
    method: :post
  )

  user_class.new(user_json)
end

#credential_user(credential_id) ⇒ Object



16
17
18
19
# File 'lib/brivo/api/users.rb', line 16

def credential_user credential_id
  user_json = http_request("credentials/#{credential_id}/user")
  user_class.new(user_json)
end

#delete_user(id) ⇒ Object



48
49
50
# File 'lib/brivo/api/users.rb', line 48

def delete_user id
  http_request "users/#{id}", method: :delete
end

#group_users(group_id) ⇒ Object



12
13
14
# File 'lib/brivo/api/users.rb', line 12

def group_users group_id
  Brivo::Collection.new(self, "groups/#{group_id}/users", user_class)
end

#user(id = nil, external_id: nil) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/brivo/api/users.rb', line 21

def user id = nil, external_id: nil
  if id
    user_json = http_request "users/#{id}"
    user_class.new(user_json)
  elsif external_id
    user_json = http_request "users/#{external_id}/external"
    user_class.new(user_json)
  else
    user_class
  end
end

#user_assign_credential(user_id, credential_id, effective_from, effective_to) ⇒ Object



52
53
54
55
56
57
58
59
60
61
# File 'lib/brivo/api/users.rb', line 52

def user_assign_credential user_id, credential_id, effective_from, effective_to
  http_request(
    "users/#{user_id}/credentials/#{credential_id}",
    method: :put,
    params: {
      effectiveFrom: effective_from,
      effectiveTo: effective_to
    }
  )
end

#user_remove_credential(user_id, credential_id) ⇒ Object



63
64
65
# File 'lib/brivo/api/users.rb', line 63

def user_remove_credential user_id, credential_id
  http_request "users/#{user_id}/credentials/#{credential_id}", method: :delete
end

#usersObject



8
9
10
# File 'lib/brivo/api/users.rb', line 8

def users
  Brivo::Collection.new(self, 'users', user_class)
end