Class: Seam::Clients::AccessCodes

Inherits:
BaseClient show all
Defined in:
lib/seam/clients/access_codes.rb

Instance Attribute Summary

Attributes inherited from BaseClient

#client

Instance Method Summary collapse

Methods inherited from BaseClient

#initialize, #request_seam, #request_seam_object

Constructor Details

This class inherits a constructor from Seam::Clients::BaseClient

Instance Method Details

#create(device_id: nil, name: nil, code: nil, starts_at: nil, ends_at: nil, use_backup_access_code_pool: nil, allow_external_modification: nil) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/seam/clients/access_codes.rb', line 28

def create(device_id: nil, name: nil, code: nil, starts_at: nil, ends_at: nil, use_backup_access_code_pool: nil, allow_external_modification: nil)
  action_attempt = request_seam_object(
    :post,
    "/access_codes/create",
    Seam::ActionAttempt,
    "action_attempt",
    body: {device_id: device_id, code: code, starts_at: starts_at, ends_at: ends_at, name: name,
           use_backup_access_code_pool: use_backup_access_code_pool, allow_external_modification: allow_external_modification}.compact
  )
  action_attempt.wait_until_finished
  # TODO: check if failed
  Seam::AccessCode.new(action_attempt.result["access_code"], @client)
end

#delete(access_code_id) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/seam/clients/access_codes.rb', line 42

def delete(access_code_id)
  action_attempt = request_seam_object(
    :post,
    "/access_codes/delete",
    Seam::ActionAttempt,
    "action_attempt",
    body: {access_code_id: access_code_id}
  )
  action_attempt.wait_until_finished
  action_attempt
end

#get(access_code_id) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/seam/clients/access_codes.rb', line 6

def get(access_code_id)
  request_seam_object(
    :post,
    "/access_codes/get",
    Seam::AccessCode,
    "access_code",
    body: {access_code_id: access_code_id}
  )
end

#list(device_or_id = nil, access_code_ids: nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/seam/clients/access_codes.rb', line 16

def list(device_or_id = nil, access_code_ids: nil)
  device_id = device_or_id.is_a?(Seam::Device) ? device_or_id.device_id : device_or_id

  request_seam_object(
    :post,
    "/access_codes/list",
    Seam::AccessCode,
    "access_codes",
    body: {device_id: device_id, access_code_ids: access_code_ids}.compact
  )
end

#pull_backup_access_code(access_code_id) ⇒ Object



74
75
76
77
78
79
80
81
82
# File 'lib/seam/clients/access_codes.rb', line 74

def pull_backup_access_code(access_code_id)
  request_seam_object(
    :post,
    "/access_codes/pull_backup_access_code",
    Seam::AccessCode,
    "backup_access_code",
    body: {access_code_id: access_code_id}
  )
end

#update(access_code_id: nil, name: nil, code: nil, starts_at: nil, ends_at: nil, type: nil, allow_external_modification: nil) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/seam/clients/access_codes.rb', line 54

def update(access_code_id: nil, name: nil, code: nil, starts_at: nil, ends_at: nil, type: nil, allow_external_modification: nil)
  action_attempt = request_seam_object(
    :post,
    "/access_codes/update",
    Seam::ActionAttempt,
    "action_attempt",
    body: {
      access_code_id: access_code_id,
      name: name,
      code: code,
      starts_at: starts_at,
      ends_at: ends_at,
      type: type,
      allow_external_modification: allow_external_modification
    }.compact
  )
  action_attempt.wait_until_finished
  action_attempt
end