Class: Thron::Gateway::Device

Inherits:
Session show all
Defined in:
lib/thron/gateway/device.rb

Constant Summary collapse

PACKAGE =
Package.new(:xdevice, :resources, self.service_name)

Constants inherited from Base

Base::NO_ACTIVE_SESSION

Instance Attribute Summary

Attributes inherited from Base

#token_id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Session

#initialize

Methods included from Pageable

included

Methods inherited from Base

#check_session, client_id, #client_id, service_name

Methods included from Routable

included, info, #route

Constructor Details

This class inherits a constructor from Thron::Gateway::Session

Class Method Details

.routesObject



11
12
13
14
15
16
17
# File 'lib/thron/gateway/device.rb', line 11

def self.routes
  @routes ||= {
    connect_device: Route::factory(name: 'connect', package: PACKAGE),
    disconnect_device: Route::factory(name: 'disconnect', package: PACKAGE),
    get_device: Route::factory(name: 'get', package: PACKAGE, verb: Route::Verbs::GET, params: [client_id])
  }
end

Instance Method Details

#connect_device(options = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/thron/gateway/device.rb', line 19

def connect_device(options = {})
  device_id = options[:device_id]
  ik = options[:ik]
  contact_name = options[:contact_name]
  body = { 
    clientId: client_id,
    deviceId: device_id,
    ik: ik,
    contactName: contact_name
  }
  route(to: __callee__, body: body, token_id: token_id) do |response|
    response.body = Entity::Base::factory(response.body)
  end
end

#disconnect_device(options = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/thron/gateway/device.rb', line 34

def disconnect_device(options = {})
  device_id = options[:device_id]
  contact_id = options[:contact_id]
  body = { 
    clientId: client_id,
    deviceId: device_id,
    contactId: contact_id
  }
  route(to: __callee__, body: body, token_id: token_id) do |response|
    response.body = Entity::Base::factory(response.body)
  end
end

#get_device(options = {}) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/thron/gateway/device.rb', line 47

def get_device(options = {})
  device_id = options[:device_id]
  query = { 
    deviceId: device_id,
  }
  route(to: __callee__, query: query, token_id: token_id) do |response|
    response.body = Entity::Base::factory(response.body)
  end
end