Class: SesameOs2::Client
- Inherits:
-
Object
- Object
- SesameOs2::Client
- Defined in:
- lib/sesame_os2/client.rb
Constant Summary collapse
- API_ENDPOINT =
'https://app.candyhouse.co/api/sesame2'- HISTORY_TYPES =
{ 0 => :none, 1 => :bleLock, 2 => :bleUnLock, 3 => :timeChanged, 4 => :autoLockUpdated, 5 => :mechSettingUpdated, 6 => :autoLock, 7 => :manualLocked, 8 => :manualUnlocked, 9 => :manualElse, 10 => :driveLocked, 11 => :driveUnlocked, 12 => :driveFailed, 13 => :bleAdvParameterUpdated, }
- COMMAND =
{ toggle: 88, lock: 82, unlock: 83 }.freeze
Instance Method Summary collapse
- #command(command:) ⇒ Object
- #histories(page: 0, lg: 50) ⇒ Object
-
#initialize(api_key: ENV['SESAME_API_KEY'], name:, ssm: ENV['SESAME_SSM']) ⇒ Client
constructor
A new instance of Client.
- #status ⇒ Object
Constructor Details
#initialize(api_key: ENV['SESAME_API_KEY'], name:, ssm: ENV['SESAME_SSM']) ⇒ Client
Returns a new instance of Client.
33 34 35 36 37 |
# File 'lib/sesame_os2/client.rb', line 33 def initialize(api_key: ENV['SESAME_API_KEY'], name:, ssm: ENV['SESAME_SSM']) @api_key = api_key @name = name @ssm = Ssm.new(ssm: ssm) end |
Instance Method Details
#command(command:) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/sesame_os2/client.rb', line 57 def command(command:) res = client.post("#{uuid}/cmd") do |req| req.body = { cmd: command, history: encoded64_name, sign: sign }.to_json end { status: res.status } end |
#histories(page: 0, lg: 50) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/sesame_os2/client.rb', line 44 def histories(page: 0, lg: 50) res = client.get("#{uuid}/history", { page: page, lg: lg }) parsed_body = JSON.parse(res.body) return parsed_body if res.status != 200 parsed_body.map do |body| body['cast_type'] = HISTORY_TYPES[body['type']] body['name'] = Base64.decode64(body['historyTag']) if body['historyTag'] body end end |
#status ⇒ Object
39 40 41 42 |
# File 'lib/sesame_os2/client.rb', line 39 def status res = client.get(uuid) JSON.parse(res.body) end |