Class: Sesame2::Sesame
- Inherits:
-
Object
show all
- Includes:
- Api
- Defined in:
- lib/sesame2/sesame.rb
Defined Under Namespace
Modules: CMD
Constant Summary
Constants included
from Api
Api::ENDPOINT_URL
Instance Attribute Summary collapse
Attributes included from Api
#api_key, #client_id
Instance Method Summary
collapse
Methods included from Api
#call, #client, #get, #parse_response, #post
Constructor Details
#initialize(sesame2_uuid:, key_secret_hex:) ⇒ Sesame
Returns a new instance of Sesame.
17
18
19
20
|
# File 'lib/sesame2/sesame.rb', line 17
def initialize(sesame2_uuid:, key_secret_hex:)
@sesame2_uuid = sesame2_uuid
@key_secret_hex = key_secret_hex
end
|
Instance Attribute Details
#key_secret_hex ⇒ Object
Returns the value of attribute key_secret_hex.
9
10
11
|
# File 'lib/sesame2/sesame.rb', line 9
def key_secret_hex
@key_secret_hex
end
|
#sesame2_uuid ⇒ Object
Returns the value of attribute sesame2_uuid.
9
10
11
|
# File 'lib/sesame2/sesame.rb', line 9
def sesame2_uuid
@sesame2_uuid
end
|
Instance Method Details
#cmd(command:, history: "") ⇒ Object
39
40
41
42
43
44
45
46
47
|
# File 'lib/sesame2/sesame.rb', line 39
def cmd(command:, history: "")
encoded_history = [history].pack("m")
post("#{@sesame2_uuid}/cmd", nil, {
cmd: command,
history: encoded_history,
sign: sign
})
end
|
#history(page: 1, lg: 20) ⇒ Object
26
27
28
|
# File 'lib/sesame2/sesame.rb', line 26
def history(page: 1, lg: 20)
get("#{@sesame2_uuid}/history", { page: page, lg: lg })
end
|
#lock(history: "") ⇒ Object
53
54
55
|
# File 'lib/sesame2/sesame.rb', line 53
def lock(history: "")
cmd(command: CMD::LOCK, history: history)
end
|
#sign ⇒ Object
30
31
32
33
34
35
36
37
|
# File 'lib/sesame2/sesame.rb', line 30
def sign
message = [Time.now.to_i].pack("i*").unpack1("H*")[2, 8]
key = [@key_secret_hex].pack("H*")
cmac = Digest::CMAC.new(OpenSSL::Cipher.new("aes-128-cbc"), key)
cmac.update([message].pack("H*"))
digest = cmac.digest
digest.unpack1("H*")
end
|
#status ⇒ Object
22
23
24
|
# File 'lib/sesame2/sesame.rb', line 22
def status
get(@sesame2_uuid)
end
|
#toggle(history: "") ⇒ Object
49
50
51
|
# File 'lib/sesame2/sesame.rb', line 49
def toggle(history: "")
cmd(command: CMD::TOGGLE, history: history)
end
|
#unlock(history: "") ⇒ Object
57
58
59
|
# File 'lib/sesame2/sesame.rb', line 57
def unlock(history: "")
cmd(command: CMD::UNLOCK, history: history)
end
|