cassia-ruby 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +50 -0
  3. data/.env.sample +3 -0
  4. data/.gitignore +12 -0
  5. data/.ruby-version +1 -0
  6. data/CODE_OF_CONDUCT.md +74 -0
  7. data/Gemfile +4 -0
  8. data/Gemfile.lock +79 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +377 -0
  11. data/Rakefile +2 -0
  12. data/bin/console +17 -0
  13. data/bin/setup +8 -0
  14. data/cassia-ruby.gemspec +38 -0
  15. data/lib/cassia/access_controller.rb +111 -0
  16. data/lib/cassia/api.rb +39 -0
  17. data/lib/cassia/characteristic.rb +14 -0
  18. data/lib/cassia/configuration.rb +9 -0
  19. data/lib/cassia/default_logger.rb +11 -0
  20. data/lib/cassia/device.rb +14 -0
  21. data/lib/cassia/requests/close_ap_state.rb +31 -0
  22. data/lib/cassia/requests/close_connection_state.rb +38 -0
  23. data/lib/cassia/requests/close_notify.rb +38 -0
  24. data/lib/cassia/requests/close_scan.rb +38 -0
  25. data/lib/cassia/requests/combined_sse.rb +27 -0
  26. data/lib/cassia/requests/connect_device.rb +38 -0
  27. data/lib/cassia/requests/connect_local.rb +44 -0
  28. data/lib/cassia/requests/disconnect_device.rb +36 -0
  29. data/lib/cassia/requests/disconnect_local.rb +33 -0
  30. data/lib/cassia/requests/discover_all_char.rb +33 -0
  31. data/lib/cassia/requests/discover_all_services.rb +33 -0
  32. data/lib/cassia/requests/discover_all_services_and_chars.rb +33 -0
  33. data/lib/cassia/requests/discover_char_of_service.rb +34 -0
  34. data/lib/cassia/requests/discover_descriptor_of_char.rb +34 -0
  35. data/lib/cassia/requests/get_all_routers_status.rb +33 -0
  36. data/lib/cassia/requests/get_connected_devices_router.rb +34 -0
  37. data/lib/cassia/requests/get_token.rb +34 -0
  38. data/lib/cassia/requests/open_ap_state.rb +31 -0
  39. data/lib/cassia/requests/open_connection_state.rb +38 -0
  40. data/lib/cassia/requests/open_notify.rb +38 -0
  41. data/lib/cassia/requests/open_scan.rb +50 -0
  42. data/lib/cassia/requests/switch_autoselect.rb +37 -0
  43. data/lib/cassia/requests/write_char_by_handle.rb +35 -0
  44. data/lib/cassia/response_handlers/close_ap_state.rb +31 -0
  45. data/lib/cassia/response_handlers/close_connection_state.rb +32 -0
  46. data/lib/cassia/response_handlers/close_notify.rb +32 -0
  47. data/lib/cassia/response_handlers/close_scan.rb +32 -0
  48. data/lib/cassia/response_handlers/connect_device.rb +29 -0
  49. data/lib/cassia/response_handlers/connect_local.rb +32 -0
  50. data/lib/cassia/response_handlers/disconnect_device.rb +28 -0
  51. data/lib/cassia/response_handlers/disconnect_local.rb +31 -0
  52. data/lib/cassia/response_handlers/discover_all_char.rb +33 -0
  53. data/lib/cassia/response_handlers/discover_all_services.rb +33 -0
  54. data/lib/cassia/response_handlers/discover_all_services_and_chars.rb +41 -0
  55. data/lib/cassia/response_handlers/discover_char_of_service.rb +37 -0
  56. data/lib/cassia/response_handlers/discover_descriptor_of_char.rb +23 -0
  57. data/lib/cassia/response_handlers/get_all_routers_status.rb +32 -0
  58. data/lib/cassia/response_handlers/get_connected_devices_router.rb +33 -0
  59. data/lib/cassia/response_handlers/get_token.rb +29 -0
  60. data/lib/cassia/response_handlers/open_ap_state.rb +31 -0
  61. data/lib/cassia/response_handlers/open_connection_state.rb +32 -0
  62. data/lib/cassia/response_handlers/open_notify.rb +32 -0
  63. data/lib/cassia/response_handlers/open_scan.rb +32 -0
  64. data/lib/cassia/response_handlers/switch_autoselect.rb +29 -0
  65. data/lib/cassia/response_handlers/write_char_by_handle.rb +28 -0
  66. data/lib/cassia/router.rb +75 -0
  67. data/lib/cassia/ruby/version.rb +5 -0
  68. data/lib/cassia/service.rb +13 -0
  69. data/lib/cassia.rb +82 -0
  70. metadata +252 -0
@@ -0,0 +1,38 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "cassia/ruby/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cassia-ruby"
8
+ spec.version = Cassia::Ruby::VERSION
9
+ spec.authors = ["adelinewang679"]
10
+ spec.email = ["adelinewang679@gmail.com"]
11
+
12
+ spec.summary = "a ruby api client for the cassia router api"
13
+ spec.description = "a ruby api client for the cassia router api"
14
+ spec.homepage = "https://github.com/iteratelabs/cassia-ruby.git"
15
+ spec.license = "MIT"
16
+
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_dependency "faraday"
28
+ spec.add_dependency "faraday_middleware"
29
+ spec.add_dependency "virtus"
30
+ spec.add_dependency "ld-eventsource"
31
+
32
+ spec.add_development_dependency "bundler", "~> 2.0"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rspec"
35
+ spec.add_development_dependency "pry"
36
+ spec.add_development_dependency "dotenv"
37
+ spec.add_development_dependency "vcr"
38
+ end
@@ -0,0 +1,111 @@
1
+ module Cassia
2
+ class AccessController
3
+ include Virtus.model
4
+
5
+ attribute :access_token, String
6
+ attribute :error, String
7
+ attribute :error_description, String
8
+ attribute :autoselect_switch, Integer, default: 0
9
+ attribute :connected_devices, Array[Cassia::Device], default: []
10
+ attribute :routers, Array[Cassia::Router], default: []
11
+ attribute :sse
12
+
13
+ def get_token
14
+ Cassia::Requests::GetToken.new(self).perform
15
+ end
16
+
17
+ def get_all_routers_status
18
+ Cassia::Requests::GetAllRoutersStatus.new(self).perform
19
+ end
20
+
21
+ def switch_autoselect(flag: )
22
+ Cassia::Requests::SwitchAutoselect.new(self, flag: flag).perform
23
+ end
24
+
25
+ def open_scan(aps: , chip: nil, active: nil, filter_name: nil, filter_mac: nil, filter_uuid: nil)
26
+ Cassia::Requests::OpenScan.new(self, aps: aps, chip: chip, active: active, filter_name: filter_name, filter_mac: filter_mac, filter_uuid: filter_uuid).perform
27
+ end
28
+
29
+ def close_scan(aps: )
30
+ Cassia::Requests::CloseScan.new(self, aps: aps).perform
31
+ end
32
+
33
+ def connect_device(aps: '*', device_mac: )
34
+ Cassia::Requests::ConnectDevice.new(self, aps: aps, device_mac: device_mac).perform
35
+ end
36
+
37
+ def disconnect_device(device_mac: )
38
+ Cassia::Requests::DisconnectDevice.new(self, device_mac: device_mac).perform
39
+ end
40
+
41
+ def open_notify(aps: )
42
+ Cassia::Requests::OpenNotify.new(self, aps: aps).perform
43
+ end
44
+
45
+ def close_notify(aps: )
46
+ Cassia::Requests::CloseNotify.new(self, aps: aps).perform
47
+ end
48
+
49
+ def open_connection_state(aps: )
50
+ Cassia::Requests::OpenConnectionState.new(self, aps: aps).perform
51
+ end
52
+
53
+ def close_connection_state(aps: )
54
+ Cassia::Requests::CloseConnectionState.new(self, aps: aps).perform
55
+ end
56
+
57
+ def open_ap_state
58
+ Cassia::Requests::OpenApState.new(self).perform
59
+ end
60
+
61
+ def close_ap_state
62
+ Cassia::Requests::CloseApState.new(self).perform
63
+ end
64
+
65
+ def combined_sse
66
+ combined_sse = Cassia::Requests::CombinedSse.new(self)
67
+
68
+ self.sse = SSE::Client.new("#{ac_url}#{combined_sse.path}", headers: combined_sse.headers) do |client|
69
+ yield(client)
70
+ end
71
+ end
72
+
73
+ def discover_all_services(router: , device_mac: )
74
+ Cassia::Requests::DiscoverAllServices.new(self, router: router, device_mac: device_mac).perform
75
+ end
76
+
77
+ def discover_all_char(router: , device_mac: )
78
+ Cassia::Requests::DiscoverAllChar.new(self, router: router, device_mac: device_mac).perform
79
+ end
80
+
81
+ def discover_char_of_service(router: , device_mac: , service_uuid: )
82
+ Cassia::Requests::DiscoverCharOfService.new(self, router: router, device_mac: device_mac, service_uuid: service_uuid).perform
83
+ end
84
+
85
+ def discover_descriptor_of_char(router: , device_mac: , char_uuid: )
86
+ Cassia::Requests::DiscoverDescriptorOfChar.new(self, router: router, device_mac: device_mac, char_uuid: char_uuid).perform
87
+ end
88
+
89
+ def discover_all_services_and_chars(router: , device_mac: )
90
+ Cassia::Requests::DiscoverAllServicesAndChars.new(self, router: router, device_mac: device_mac).perform
91
+ end
92
+
93
+ def write_char_by_handle(router: , device_mac:, handle: , value: )
94
+ Cassia::Requests::WriteCharByHandle.new(self, router: router, device_mac: device_mac, handle: handle, value: value).perform
95
+ end
96
+
97
+ def open_char_notification(router: , device_mac: , handle: )
98
+ Cassia::Requests::WriteCharByHandle.new(self, router: router, device_mac: device_mac, handle: handle, value: "0100").perform
99
+ end
100
+
101
+ def close_char_notification(router: , device_mac: , handle: )
102
+ Cassia::Requests::WriteCharByHandle.new(self, router: router, device_mac: device_mac, handle: handle, value: "0000").perform
103
+ end
104
+
105
+ private
106
+
107
+ def ac_url
108
+ Cassia.configuration.ac_url
109
+ end
110
+ end
111
+ end
data/lib/cassia/api.rb ADDED
@@ -0,0 +1,39 @@
1
+ module Cassia
2
+ class Api
3
+ def post(request)
4
+ connection.post do |req|
5
+ req.url request.path
6
+ req.headers = request.headers
7
+ req.body = request.body
8
+ end
9
+ end
10
+
11
+ def get(request)
12
+ connection.get do |req|
13
+ req.url request.path
14
+ req.headers = request.headers
15
+ end
16
+ end
17
+
18
+ def delete(request)
19
+ connection.delete do |req|
20
+ req.url request.path
21
+ req.headers = request.headers
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def connection
28
+ @connection ||= Faraday.new(url: ac_url) do |faraday|
29
+ faraday.response :logger, Cassia.logger, bodies: true
30
+ faraday.response :json, :content_type => /\bjson$/
31
+ faraday.adapter Faraday.default_adapter
32
+ end
33
+ end
34
+
35
+ def ac_url
36
+ Cassia.configuration.ac_url
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,14 @@
1
+ module Cassia
2
+ class Characteristic
3
+ include Virtus.model
4
+ attribute :uuid, String
5
+ attribute :properties, Integer
6
+ attribute :handle, Integer
7
+ attribute :descriptors, Array
8
+ attribute :notification_on, Boolean
9
+
10
+ def ==(other)
11
+ return self.uuid == other.uuid && self.properties == other.properties && self.handle == other.handle && self.descriptors == other.descriptors
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ module Cassia
2
+ class Configuration
3
+ attr_accessor :client_id, :secret, :ac_url
4
+
5
+ def ac_url
6
+ @ac_url ||= "http://demo.cassia.pro"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ require 'logger'
2
+
3
+ module Cassia
4
+ class DefaultLogger
5
+ def self.build
6
+ Logger.new(STDOUT).tap do |logger|
7
+ logger.level = Logger::INFO
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ module Cassia
2
+ class Device
3
+ include Virtus.model
4
+ attribute :mac, String
5
+ attribute :type, String
6
+ attribute :bdaddrs
7
+ attribute :chipId, Integer
8
+ attribute :handle, String
9
+ attribute :name, String
10
+ attribute :connectionState, String
11
+ attribute :services, Array[Cassia::Service]
12
+ attribute :characteristics, Array[Cassia::Characteristic]
13
+ end
14
+ end
@@ -0,0 +1,31 @@
1
+ module Cassia
2
+ module Requests
3
+ class CloseApState
4
+ def initialize(access_controller)
5
+ @access_controller = access_controller
6
+ end
7
+
8
+ def path
9
+ '/api/aps/ap-state/close'
10
+ end
11
+
12
+ def headers
13
+ {
14
+ 'Authorization' => "Bearer #{access_token}",
15
+ 'Content-Type' => "application/json"
16
+ }
17
+ end
18
+
19
+ def perform
20
+ Cassia::ResponseHandlers::CloseApState.new(@access_controller).handle(Cassia.api.get(self))
21
+ end
22
+
23
+ private
24
+
25
+ def access_token
26
+ @access_controller.get_token if @access_controller.access_token.nil?
27
+ @access_controller.access_token
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,38 @@
1
+ module Cassia
2
+ module Requests
3
+ class CloseConnectionState
4
+ def initialize(access_controller, aps: )
5
+ @access_controller = access_controller
6
+ @aps = aps
7
+ end
8
+
9
+ def path
10
+ '/api/aps/connection-state/close'
11
+ end
12
+
13
+ def body
14
+ {
15
+ 'aps' => @aps
16
+ }.to_json
17
+ end
18
+
19
+ def headers
20
+ {
21
+ 'Authorization' => "Bearer #{access_token}",
22
+ 'Content-Type' => "application/json"
23
+ }
24
+ end
25
+
26
+ def perform
27
+ Cassia::ResponseHandlers::CloseConnectionState.new(@access_controller, aps: @aps).handle(Cassia.api.post(self))
28
+ end
29
+
30
+ private
31
+
32
+ def access_token
33
+ @access_controller.get_token if @access_controller.access_token.nil?
34
+ @access_controller.access_token
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,38 @@
1
+ module Cassia
2
+ module Requests
3
+ class CloseNotify
4
+ def initialize(access_controller, aps: )
5
+ @access_controller = access_controller
6
+ @aps = aps
7
+ end
8
+
9
+ def path
10
+ '/api/aps/notify/close'
11
+ end
12
+
13
+ def body
14
+ {
15
+ 'aps' => @aps
16
+ }.to_json
17
+ end
18
+
19
+ def headers
20
+ {
21
+ 'Authorization' => "Bearer #{access_token}",
22
+ 'Content-Type' => "application/json"
23
+ }
24
+ end
25
+
26
+ def perform
27
+ Cassia::ResponseHandlers::CloseNotify.new(@access_controller, aps: @aps).handle(Cassia.api.post(self))
28
+ end
29
+
30
+ private
31
+
32
+ def access_token
33
+ @access_controller.get_token if @access_controller.access_token.nil?
34
+ @access_controller.access_token
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,38 @@
1
+ module Cassia
2
+ module Requests
3
+ class CloseScan
4
+ def initialize(access_controller, aps: )
5
+ @access_controller = access_controller
6
+ @aps = aps
7
+ end
8
+
9
+ def path
10
+ '/api/aps/scan/close'
11
+ end
12
+
13
+ def body
14
+ {
15
+ 'aps' => @aps
16
+ }.to_json
17
+ end
18
+
19
+ def headers
20
+ {
21
+ 'Authorization' => "Bearer #{access_token}",
22
+ 'Content-Type' => "application/json"
23
+ }
24
+ end
25
+
26
+ def perform
27
+ Cassia::ResponseHandlers::CloseScan.new(@access_controller, aps: @aps).handle(Cassia.api.post(self))
28
+ end
29
+
30
+ private
31
+
32
+ def access_token
33
+ @access_controller.get_token if @access_controller.access_token.nil?
34
+ @access_controller.access_token
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,27 @@
1
+ module Cassia
2
+ module Requests
3
+ class CombinedSse
4
+ def initialize(access_controller)
5
+ @access_controller = access_controller
6
+ end
7
+
8
+ def path
9
+ "/api/aps/events"
10
+ end
11
+
12
+ def headers
13
+ {
14
+ 'Authorization' => "Bearer #{access_token}",
15
+ 'Content-Type' => "application/json"
16
+ }
17
+ end
18
+
19
+ private
20
+
21
+ def access_token
22
+ @access_controller.get_token if @access_controller.access_token.nil?
23
+ @access_controller.access_token
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,38 @@
1
+ module Cassia
2
+ module Requests
3
+ class ConnectDevice
4
+ def initialize(access_controller, aps: '*', device_mac: nil)
5
+ @access_controller = access_controller
6
+ @aps = aps
7
+ @device_mac = device_mac
8
+ end
9
+
10
+ def path
11
+ '/api/aps/connections/connect'
12
+ end
13
+
14
+ def body
15
+ { 'aps' => @aps,
16
+ 'devices' => [@device_mac] }.to_json
17
+ end
18
+
19
+ def headers
20
+ {
21
+ 'Authorization' => "Bearer #{access_token}",
22
+ 'Content-Type' => "application/json"
23
+ }
24
+ end
25
+
26
+ def perform
27
+ Cassia::ResponseHandlers::ConnectDevice.new(@access_controller).handle(Cassia.api.post(self))
28
+ end
29
+
30
+ private
31
+
32
+ def access_token
33
+ @access_controller.get_token if @access_controller.access_token.nil?
34
+ @access_controller.access_token
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,44 @@
1
+ module Cassia
2
+ module Requests
3
+ class ConnectLocal
4
+ def initialize(access_controller, router: , device_mac: nil, type: 'random', timeout: '5000', auto: '0', discovergatt: '1')
5
+ @access_controller = access_controller
6
+ @router = router
7
+ @device_mac = device_mac
8
+ @type = type
9
+ @timeout = timeout
10
+ @auto = auto
11
+ @discovergatt = discovergatt
12
+ end
13
+
14
+ def path
15
+ "/api/gap/nodes/#{@device_mac}/connection?mac=#{@router.mac}"
16
+ end
17
+
18
+ def body
19
+ { 'type' => @type,
20
+ 'timeout' => @timeout,
21
+ 'auto' => @auto,
22
+ 'discovergatt' => @discovergatt }.to_json
23
+ end
24
+
25
+ def headers
26
+ {
27
+ 'Authorization' => "Bearer #{access_token}",
28
+ 'Content-Type' => "application/json"
29
+ }
30
+ end
31
+
32
+ def perform
33
+ Cassia::ResponseHandlers::ConnectLocal.new(@access_controller, router: @router, device_mac: @device_mac).handle(Cassia.api.post(self))
34
+ end
35
+
36
+ private
37
+
38
+ def access_token
39
+ @access_controller.get_token if @access_controller.access_token.nil?
40
+ @access_controller.access_token
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,36 @@
1
+ module Cassia
2
+ module Requests
3
+ class DisconnectDevice
4
+ def initialize(access_controller, device_mac: nil)
5
+ @access_controller = access_controller
6
+ @device_mac = device_mac
7
+ end
8
+
9
+ def path
10
+ '/api/aps/connections/disconnect'
11
+ end
12
+
13
+ def body
14
+ { 'devices' => [@device_mac] }.to_json
15
+ end
16
+
17
+ def headers
18
+ {
19
+ 'Authorization' => "Bearer #{access_token}",
20
+ 'Content-Type' => "application/json"
21
+ }
22
+ end
23
+
24
+ def perform
25
+ Cassia::ResponseHandlers::DisconnectDevice.new(@access_controller).handle(Cassia.api.post(self))
26
+ end
27
+
28
+ private
29
+
30
+ def access_token
31
+ @access_controller.get_token if @access_controller.access_token.nil?
32
+ @access_controller.access_token
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,33 @@
1
+ module Cassia
2
+ module Requests
3
+ class DisconnectLocal
4
+ def initialize(access_controller, router: , device_mac: )
5
+ @access_controller = access_controller
6
+ @router = router
7
+ @device_mac = device_mac
8
+ end
9
+
10
+ def path
11
+ "/api/gap/nodes/#{@device_mac}/connection?mac=#{@router.mac}"
12
+ end
13
+
14
+ def headers
15
+ {
16
+ 'Authorization' => "Bearer #{access_token}",
17
+ 'Content-Type' => "application/json"
18
+ }
19
+ end
20
+
21
+ def perform
22
+ Cassia::ResponseHandlers::DisconnectLocal.new(@access_controller, router: @router, device_mac: @device_mac).handle(Cassia.api.delete(self))
23
+ end
24
+
25
+ private
26
+
27
+ def access_token
28
+ @access_controller.get_token if @access_controller.access_token.nil?
29
+ @access_controller.access_token
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,33 @@
1
+ module Cassia
2
+ module Requests
3
+ class DiscoverAllChar
4
+ def initialize(access_controller, router: , device_mac: )
5
+ @access_controller = access_controller
6
+ @router = router
7
+ @device_mac = device_mac
8
+ end
9
+
10
+ def path
11
+ "/api/gatt/nodes/#{@device_mac}/characteristics?mac=#{@router.mac}"
12
+ end
13
+
14
+ def headers
15
+ {
16
+ 'Authorization' => "Bearer #{access_token}",
17
+ 'Content-Type' => "application/json"
18
+ }
19
+ end
20
+
21
+ def perform
22
+ Cassia::ResponseHandlers::DiscoverAllChar.new(@access_controller, router: @router, device_mac: @device_mac).handle(Cassia.api.get(self))
23
+ end
24
+
25
+ private
26
+
27
+ def access_token
28
+ @access_controller.get_token if @access_controller.access_token.nil?
29
+ @access_controller.access_token
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,33 @@
1
+ module Cassia
2
+ module Requests
3
+ class DiscoverAllServices
4
+ def initialize(access_controller, router: , device_mac: )
5
+ @access_controller = access_controller
6
+ @router = router
7
+ @device_mac = device_mac
8
+ end
9
+
10
+ def path
11
+ "/api/gatt/nodes/#{@device_mac}/services?mac=#{@router.mac}"
12
+ end
13
+
14
+ def headers
15
+ {
16
+ 'Authorization' => "Bearer #{access_token}",
17
+ 'Content-Type' => "application/json"
18
+ }
19
+ end
20
+
21
+ def perform
22
+ Cassia::ResponseHandlers::DiscoverAllServices.new(@access_controller, router: @router, device_mac: @device_mac).handle(Cassia.api.get(self))
23
+ end
24
+
25
+ private
26
+
27
+ def access_token
28
+ @access_controller.get_token if @access_controller.access_token.nil?
29
+ @access_controller.access_token
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,33 @@
1
+ module Cassia
2
+ module Requests
3
+ class DiscoverAllServicesAndChars
4
+ def initialize(access_controller, router: , device_mac: )
5
+ @access_controller = access_controller
6
+ @router = router
7
+ @device_mac = device_mac
8
+ end
9
+
10
+ def path
11
+ "/api/gatt/nodes/#{@device_mac}/services/characteristics/descriptors?mac=#{@router.mac}"
12
+ end
13
+
14
+ def headers
15
+ {
16
+ 'Authorization' => "Bearer #{access_token}",
17
+ 'Content-Type' => "application/json"
18
+ }
19
+ end
20
+
21
+ def perform
22
+ Cassia::ResponseHandlers::DiscoverAllServicesAndChars.new(@access_controller, router: @router, device_mac: @device_mac).handle(Cassia.api.get(self))
23
+ end
24
+
25
+ private
26
+
27
+ def access_token
28
+ @access_controller.get_token if @access_controller.access_token.nil?
29
+ @access_controller.access_token
30
+ end
31
+ end
32
+ end
33
+ end