Module: Brivo::API::Credentials

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

Constant Summary collapse

FORMAT_NAME =
'Standard 26 Bit'

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_credential(id, facility_code) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/brivo/api/credentials.rb', line 29

def create_credential id, facility_code
  @credential_formats ||= http_request('credentials/formats')['data']
  credential_format = @credential_formats.find do |format|
    format['name'] == FORMAT_NAME
  end

  credential_json = http_request(
    'credentials',
    params: {
      credentialFormat: {
        id: credential_format['id']
      },
      referenceId: id,
      fieldValues: [
        {id: 1, value: id},
        {id: 2, value: facility_code}
      ]
    },
    method: :post
  )

  credential_class.new(credential_json)
end

#credential(id = nil) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/brivo/api/credentials.rb', line 20

def credential id = nil
  if id
    credential_json = http_request("credentials/#{id}")
    credential_class.new(credential_json)
  else
    credential_class
  end
end

#credentials(status: nil) ⇒ Object



10
11
12
13
14
# File 'lib/brivo/api/credentials.rb', line 10

def credentials(status: nil)
  path = 'credentials'
  path += "?filter=status__eq:#{status}" if status
  Brivo::Collection.new(self, path, credential_class)
end

#delete_credential(id) ⇒ Object



53
54
55
# File 'lib/brivo/api/credentials.rb', line 53

def delete_credential id
  http_request "credentials/#{id}", method: :delete
end

#user_credentials(user_id) ⇒ Object



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

def user_credentials(user_id)
  Brivo::Collection.new(self, "users/#{user_id}/credentials", credential_class)
end