cassia-ruby 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +17 -17
  3. data/README.md +17 -13
  4. data/bin/console +3 -0
  5. data/cassia-ruby.gemspec +3 -3
  6. data/lib/cassia.rb +1 -0
  7. data/lib/cassia/access_controller.rb +5 -3
  8. data/lib/cassia/api.rb +22 -2
  9. data/lib/cassia/characteristic.rb +1 -1
  10. data/lib/cassia/configuration.rb +5 -2
  11. data/lib/cassia/descriptor.rb +11 -0
  12. data/lib/cassia/requests/close_ap_state.rb +1 -8
  13. data/lib/cassia/requests/close_connection_state.rb +1 -8
  14. data/lib/cassia/requests/close_notify.rb +1 -8
  15. data/lib/cassia/requests/close_scan.rb +1 -8
  16. data/lib/cassia/requests/combined_sse.rb +1 -8
  17. data/lib/cassia/requests/connect_device.rb +1 -8
  18. data/lib/cassia/requests/connect_local.rb +1 -8
  19. data/lib/cassia/requests/disconnect_device.rb +1 -8
  20. data/lib/cassia/requests/disconnect_local.rb +1 -8
  21. data/lib/cassia/requests/discover_all_char.rb +1 -8
  22. data/lib/cassia/requests/discover_all_services.rb +1 -8
  23. data/lib/cassia/requests/discover_all_services_and_chars.rb +1 -8
  24. data/lib/cassia/requests/discover_char_of_service.rb +1 -8
  25. data/lib/cassia/requests/discover_descriptor_of_char.rb +1 -8
  26. data/lib/cassia/requests/get_all_routers_status.rb +1 -8
  27. data/lib/cassia/requests/get_connected_devices_router.rb +1 -8
  28. data/lib/cassia/requests/open_ap_state.rb +1 -8
  29. data/lib/cassia/requests/open_connection_state.rb +1 -8
  30. data/lib/cassia/requests/open_notify.rb +1 -8
  31. data/lib/cassia/requests/open_scan.rb +1 -8
  32. data/lib/cassia/requests/switch_autoselect.rb +1 -8
  33. data/lib/cassia/requests/write_char_by_handle.rb +1 -8
  34. data/lib/cassia/response_handlers/get_token.rb +3 -0
  35. data/lib/cassia/response_handlers/write_char_by_handle.rb +14 -1
  36. data/lib/cassia/ruby/version.rb +1 -1
  37. metadata +8 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2d229db9bae35ba77cf6fb4602c2d84fdc24de4f1492f123efffb4f498b97e11
4
- data.tar.gz: b7f499a5a965da624cf360374924be9d0f48511677dcaec2d85ccd786fc6b560
3
+ metadata.gz: 67cf9d7de85d1b13bac64ce5531e38c5e6073ae833ff23b1fe6921c7d3495ed3
4
+ data.tar.gz: a463007325aa41a42d533beca800f4daecdcb70b623264f836320b7f89297cf2
5
5
  SHA512:
6
- metadata.gz: 2b9c21b633672555da4a1ea7a1db12d91d6147010e608ea879b962455189e64ecad39b0cd8f5733eed5b7a249b837d3f5455bab6370567810c26bdeee3f9973d
7
- data.tar.gz: 990cf7d2d97cc891c138f4a94a50a1b4c02b11c78c58777c27fdb8024d66be5dcddf45c5905652373f087243a6f8d2c16d991ff3938a051cf0081a4d71de65f4
6
+ metadata.gz: 3d57ddf288d141da8e9851d1699abb696ba8c45ff6b614d86a468dbfc41b2783d6d8bee0c25843b891177d49c5a2296c80b14271cd7c7942e47921b4e99bb1c6
7
+ data.tar.gz: 9fb9ccea39859e9c25fd7c5cf29306ec1132fd38fc0b28d1b57113c455e59f2f8baca4441786b356d014f9a2b4b480e0bb9877f4ec949a440f4547ff8fb85932
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cassia-ruby (1.0.0)
4
+ cassia-ruby (1.0.1)
5
5
  faraday
6
6
  faraday_middleware
7
7
  ld-eventsource
@@ -21,16 +21,16 @@ GEM
21
21
  descendants_tracker (0.0.4)
22
22
  thread_safe (~> 0.3, >= 0.3.1)
23
23
  diff-lcs (1.3)
24
- dotenv (2.7.2)
24
+ dotenv (2.7.5)
25
25
  equalizer (0.0.11)
26
- faraday (0.15.4)
26
+ faraday (0.17.0)
27
27
  multipart-post (>= 1.2, < 3)
28
28
  faraday_middleware (0.13.1)
29
29
  faraday (>= 0.7.4, < 1.0)
30
30
  hitimes (1.3.1)
31
31
  http_tools (0.4.5)
32
32
  ice_nine (0.11.2)
33
- ld-eventsource (1.0.0)
33
+ ld-eventsource (1.0.1)
34
34
  concurrent-ruby (~> 1.0)
35
35
  http_tools (~> 0.4.5)
36
36
  socketry (~> 0.5.1)
@@ -39,20 +39,20 @@ GEM
39
39
  pry (0.12.2)
40
40
  coderay (~> 1.1.0)
41
41
  method_source (~> 0.9.0)
42
- rake (10.5.0)
43
- rspec (3.8.0)
44
- rspec-core (~> 3.8.0)
45
- rspec-expectations (~> 3.8.0)
46
- rspec-mocks (~> 3.8.0)
47
- rspec-core (3.8.0)
48
- rspec-support (~> 3.8.0)
49
- rspec-expectations (3.8.4)
42
+ rake (13.0.0)
43
+ rspec (3.9.0)
44
+ rspec-core (~> 3.9.0)
45
+ rspec-expectations (~> 3.9.0)
46
+ rspec-mocks (~> 3.9.0)
47
+ rspec-core (3.9.0)
48
+ rspec-support (~> 3.9.0)
49
+ rspec-expectations (3.9.0)
50
50
  diff-lcs (>= 1.2.0, < 2.0)
51
- rspec-support (~> 3.8.0)
52
- rspec-mocks (3.8.0)
51
+ rspec-support (~> 3.9.0)
52
+ rspec-mocks (3.9.0)
53
53
  diff-lcs (>= 1.2.0, < 2.0)
54
- rspec-support (~> 3.8.0)
55
- rspec-support (3.8.2)
54
+ rspec-support (~> 3.9.0)
55
+ rspec-support (3.9.0)
56
56
  socketry (0.5.1)
57
57
  hitimes (~> 1.2)
58
58
  thread_safe (0.3.6)
@@ -71,7 +71,7 @@ DEPENDENCIES
71
71
  cassia-ruby!
72
72
  dotenv
73
73
  pry
74
- rake (~> 10.0)
74
+ rake (~> 13.0)
75
75
  rspec
76
76
  vcr
77
77
 
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
+ [![Maintainability](https://api.codeclimate.com/v1/badges/dd4bf18bcdf6b2bdc860/maintainability)](https://codeclimate.com/github/iteratelabs/cassia-ruby/maintainability) [![CircleCI](https://circleci.com/gh/iteratelabs/cassia-ruby/tree/master.svg?style=svg)](https://circleci.com/gh/iteratelabs/cassia-ruby/tree/master)
1
2
  # Cassia::Ruby
2
3
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/cassia/ruby`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+ This gem was created in order to allow Ruby developers to interact with the Cassia Bluetooth Gateway API's https://www.cassianetworks.com/download/docs/Cassia_SDK_Implementation_Guide.pdf.
4
5
 
5
- TODO: Delete this and the text above, and describe your gem
6
6
 
7
7
  ## Installation
8
8
 
@@ -23,11 +23,15 @@ Or install it yourself as:
23
23
  ## Configuration
24
24
  Here is a list of the available configuration options and their default values
25
25
 
26
- | Option | Description |
27
- |-----------------|:---------------------------------:|
28
- | `ac_url` | The URL of your AC server address |
29
- | `client_id` | Your Cassia API Developer Key |
30
- | `secret` | Your Cassia API Developer Secret |
26
+ | Option | Description | Optional|
27
+ |-----------------|:---------------------------------:|---------|
28
+ | `ac_url` | The URL of your AC server address | No |
29
+ | `client_id` | Your Cassia API Developer Key | No |
30
+ | `secret` | Your Cassia API Developer Secret | No |
31
+ | `client_cert` | Your SSL client cert | Yes |
32
+ | `client_key` | Your SSL client key | Yes |
33
+ | `ca_file` | Your SSL CA file | Yes |
34
+ | `ca_path` | The path to your SSL CA files | Yes |
31
35
 
32
36
  ### Setting your configuration
33
37
 
@@ -45,7 +49,7 @@ end
45
49
 
46
50
  ### AccessControllers
47
51
 
48
- In the following context, `access_controller` is a `Cassia::AccessController` object which contains attributes and structures of a Cassia access controller.
52
+ In the following context, `access_controller` is a `Cassia::AccessController` object which contains attributes and structures of a Cassia access controller.
49
53
 
50
54
  #### Retrieve An Access Token From the Cassia API
51
55
  ```ruby
@@ -53,7 +57,7 @@ access_controller.get_token
53
57
  access_controller.access_token
54
58
  ```
55
59
 
56
- `get_token` will make a request from `access_controller` to generate an access token encoded from `config.client_id` and `config.secret` using base64.
60
+ `get_token` will make a request from `access_controller` to generate an access token encoded from `config.client_id` and `config.secret` using base64.
57
61
 
58
62
  `access_token` will return the access token of `access_controller`.
59
63
 
@@ -88,7 +92,7 @@ access_controller.open_scan(aps: ["CC:1B:E0:E7:FE:F8", "CC:1B:E0:E7:FE:F8", "CC
88
92
  ```ruby
89
93
  access_controller.close_scan(aps: ["CC:1B:E0:E7:FE:F8", "CC:1B:E0:E7:FE:F8", "CC:1B:E0:E7:FE:F8"])
90
94
  ```
91
-
95
+
92
96
  `aps` is an array of one or multiple router's MAC address.
93
97
 
94
98
  #### Connect A Device to An Automatically Selected Router from the router list
@@ -147,7 +151,7 @@ access_controller.close_ap_state
147
151
  #### Create One Combined SSE Connection
148
152
  ```ruby
149
153
  access_controller.combined_sse do |client|
150
- client.on_event do |event|
154
+ client.on_event do |event|
151
155
  puts "I received an event: #{event.type}, #{event.data}"
152
156
  # put code here to act on events
153
157
  end
@@ -366,7 +370,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
366
370
 
367
371
  ## Contributing
368
372
 
369
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cassia-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
373
+ Bug reports and pull requests are welcome on GitHub at https://github.com/iteratelabs/cassia-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
370
374
 
371
375
  ## License
372
376
 
@@ -374,4 +378,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
374
378
 
375
379
  ## Code of Conduct
376
380
 
377
- Everyone interacting in the Cassia::Ruby project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/cassia-ruby/blob/master/CODE_OF_CONDUCT.md).
381
+ Everyone interacting in the Cassia::Ruby project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/iteratelabs/cassia-ruby/blob/master/CODE_OF_CONDUCT.md).
@@ -12,6 +12,9 @@ Cassia.configure do |config|
12
12
  config.ac_url = ENV['CASSIA_AC_URL']
13
13
  config.client_id = ENV['CASSIA_CLIENT_ID']
14
14
  config.secret = ENV['CASSIA_SECRET']
15
+ config.client_cert = ENV['CASSIA_CLIENT_CERT']
16
+ config.client_key = ENV['CASSIA_CLIENT_KEY']
17
+ config.ca_file = ENV['CASSIA_CA_FILE']
15
18
  end
16
19
 
17
20
  IRB.start(__FILE__)
@@ -6,8 +6,8 @@ require "cassia/ruby/version"
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "cassia-ruby"
8
8
  spec.version = Cassia::Ruby::VERSION
9
- spec.authors = ["adelinewang679"]
10
- spec.email = ["adelinewang679@gmail.com"]
9
+ spec.authors = ["Adeline Wang", "James Russo"]
10
+ spec.email = ["adelinewang679@gmail.com", "jdrusso1020@gmail.com"]
11
11
 
12
12
  spec.summary = "a ruby api client for the cassia router api"
13
13
  spec.description = "a ruby api client for the cassia router api"
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.add_dependency "ld-eventsource"
31
31
 
32
32
  spec.add_development_dependency "bundler", "~> 2.0"
33
- spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "rake", "~> 13.0"
34
34
  spec.add_development_dependency "rspec"
35
35
  spec.add_development_dependency "pry"
36
36
  spec.add_development_dependency "dotenv"
@@ -8,6 +8,7 @@ require "ld-eventsource"
8
8
  require "cassia/api"
9
9
  require "cassia/configuration"
10
10
  require "cassia/default_logger"
11
+ require "cassia/descriptor"
11
12
  require "cassia/characteristic"
12
13
  require "cassia/service"
13
14
  require "cassia/device"
@@ -3,6 +3,7 @@ module Cassia
3
3
  include Virtus.model
4
4
 
5
5
  attribute :access_token, String
6
+ attribute :access_token_expiration, Time, default: Time.now.getutc + 100 # default for tests when we pass in access token
6
7
  attribute :error, String
7
8
  attribute :error_description, String
8
9
  attribute :autoselect_switch, Integer, default: 0
@@ -11,7 +12,8 @@ module Cassia
11
12
  attribute :sse
12
13
 
13
14
  def get_token
14
- Cassia::Requests::GetToken.new(self).perform
15
+ Cassia::Requests::GetToken.new(self).perform if access_token.nil? || Time.now.getutc > access_token_expiration
16
+ access_token
15
17
  end
16
18
 
17
19
  def get_all_routers_status
@@ -89,7 +91,7 @@ module Cassia
89
91
  def discover_all_services_and_chars(router: , device_mac: )
90
92
  Cassia::Requests::DiscoverAllServicesAndChars.new(self, router: router, device_mac: device_mac).perform
91
93
  end
92
-
94
+
93
95
  def write_char_by_handle(router: , device_mac:, handle: , value: )
94
96
  Cassia::Requests::WriteCharByHandle.new(self, router: router, device_mac: device_mac, handle: handle, value: value).perform
95
97
  end
@@ -97,7 +99,7 @@ module Cassia
97
99
  def open_char_notification(router: , device_mac: , handle: )
98
100
  Cassia::Requests::WriteCharByHandle.new(self, router: router, device_mac: device_mac, handle: handle, value: "0100").perform
99
101
  end
100
-
102
+
101
103
  def close_char_notification(router: , device_mac: , handle: )
102
104
  Cassia::Requests::WriteCharByHandle.new(self, router: router, device_mac: device_mac, handle: handle, value: "0000").perform
103
105
  end
@@ -12,7 +12,7 @@ module Cassia
12
12
  connection.get do |req|
13
13
  req.url request.path
14
14
  req.headers = request.headers
15
- end
15
+ end
16
16
  end
17
17
 
18
18
  def delete(request)
@@ -21,7 +21,7 @@ module Cassia
21
21
  req.headers = request.headers
22
22
  end
23
23
  end
24
-
24
+
25
25
  private
26
26
 
27
27
  def connection
@@ -29,11 +29,31 @@ module Cassia
29
29
  faraday.response :logger, Cassia.logger, bodies: true
30
30
  faraday.response :json, :content_type => /\bjson$/
31
31
  faraday.adapter Faraday.default_adapter
32
+ faraday.ssl.client_cert = OpenSSL::X509::Certificate.new(client_cert)if client_cert
33
+ faraday.ssl.client_key = OpenSSL::PKey::RSA.new(client_key) if client_key
34
+ faraday.ssl.ca_file = ca_file if ca_file
35
+ faraday.ssl.ca_path = ca_path if ca_path
32
36
  end
33
37
  end
34
38
 
35
39
  def ac_url
36
40
  Cassia.configuration.ac_url
37
41
  end
42
+
43
+ def client_cert
44
+ Cassia.configuration.client_cert
45
+ end
46
+
47
+ def client_key
48
+ Cassia.configuration.client_key
49
+ end
50
+
51
+ def ca_file
52
+ Cassia.configuration.ca_file
53
+ end
54
+
55
+ def ca_path
56
+ Cassia.configuration.ca_path
57
+ end
38
58
  end
39
59
  end
@@ -4,7 +4,7 @@ module Cassia
4
4
  attribute :uuid, String
5
5
  attribute :properties, Integer
6
6
  attribute :handle, Integer
7
- attribute :descriptors, Array
7
+ attribute :descriptors, Array[Cassia::Descriptor]
8
8
  attribute :notification_on, Boolean
9
9
 
10
10
  def ==(other)
@@ -1,7 +1,10 @@
1
1
  module Cassia
2
2
  class Configuration
3
- attr_accessor :client_id, :secret, :ac_url
4
-
3
+ attr_accessor :client_id, :secret,
4
+ :ac_url, :client_cert,
5
+ :client_key, :ca_file,
6
+ :ca_path
7
+
5
8
  def ac_url
6
9
  @ac_url ||= "http://demo.cassia.pro"
7
10
  end
@@ -0,0 +1,11 @@
1
+ module Cassia
2
+ class Descriptor
3
+ include Virtus.model
4
+ attribute :uuid, String
5
+ attribute :handle, Integer
6
+
7
+ def ==(other)
8
+ return self.uuid == other.uuid && self.handle == other.handle
9
+ end
10
+ end
11
+ end
@@ -11,7 +11,7 @@ module Cassia
11
11
 
12
12
  def headers
13
13
  {
14
- 'Authorization' => "Bearer #{access_token}",
14
+ 'Authorization' => "Bearer #{@access_controller.get_token}",
15
15
  'Content-Type' => "application/json"
16
16
  }
17
17
  end
@@ -19,13 +19,6 @@ module Cassia
19
19
  def perform
20
20
  Cassia::ResponseHandlers::CloseApState.new(@access_controller).handle(Cassia.api.get(self))
21
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
22
  end
30
23
  end
31
24
  end
@@ -18,7 +18,7 @@ module Cassia
18
18
 
19
19
  def headers
20
20
  {
21
- 'Authorization' => "Bearer #{access_token}",
21
+ 'Authorization' => "Bearer #{@access_controller.get_token}",
22
22
  'Content-Type' => "application/json"
23
23
  }
24
24
  end
@@ -26,13 +26,6 @@ module Cassia
26
26
  def perform
27
27
  Cassia::ResponseHandlers::CloseConnectionState.new(@access_controller, aps: @aps).handle(Cassia.api.post(self))
28
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
29
  end
37
30
  end
38
31
  end
@@ -18,7 +18,7 @@ module Cassia
18
18
 
19
19
  def headers
20
20
  {
21
- 'Authorization' => "Bearer #{access_token}",
21
+ 'Authorization' => "Bearer #{@access_controller.get_token}",
22
22
  'Content-Type' => "application/json"
23
23
  }
24
24
  end
@@ -26,13 +26,6 @@ module Cassia
26
26
  def perform
27
27
  Cassia::ResponseHandlers::CloseNotify.new(@access_controller, aps: @aps).handle(Cassia.api.post(self))
28
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
29
  end
37
30
  end
38
31
  end
@@ -18,7 +18,7 @@ module Cassia
18
18
 
19
19
  def headers
20
20
  {
21
- 'Authorization' => "Bearer #{access_token}",
21
+ 'Authorization' => "Bearer #{@access_controller.get_token}",
22
22
  'Content-Type' => "application/json"
23
23
  }
24
24
  end
@@ -26,13 +26,6 @@ module Cassia
26
26
  def perform
27
27
  Cassia::ResponseHandlers::CloseScan.new(@access_controller, aps: @aps).handle(Cassia.api.post(self))
28
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
29
  end
37
30
  end
38
31
  end
@@ -11,17 +11,10 @@ module Cassia
11
11
 
12
12
  def headers
13
13
  {
14
- 'Authorization' => "Bearer #{access_token}",
14
+ 'Authorization' => "Bearer #{@access_controller.get_token}",
15
15
  'Content-Type' => "application/json"
16
16
  }
17
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
18
  end
26
19
  end
27
20
  end
@@ -18,7 +18,7 @@ module Cassia
18
18
 
19
19
  def headers
20
20
  {
21
- 'Authorization' => "Bearer #{access_token}",
21
+ 'Authorization' => "Bearer #{@access_controller.get_token}",
22
22
  'Content-Type' => "application/json"
23
23
  }
24
24
  end
@@ -26,13 +26,6 @@ module Cassia
26
26
  def perform
27
27
  Cassia::ResponseHandlers::ConnectDevice.new(@access_controller).handle(Cassia.api.post(self))
28
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
29
  end
37
30
  end
38
31
  end
@@ -24,7 +24,7 @@ module Cassia
24
24
 
25
25
  def headers
26
26
  {
27
- 'Authorization' => "Bearer #{access_token}",
27
+ 'Authorization' => "Bearer #{@access_controller.get_token}",
28
28
  'Content-Type' => "application/json"
29
29
  }
30
30
  end
@@ -32,13 +32,6 @@ module Cassia
32
32
  def perform
33
33
  Cassia::ResponseHandlers::ConnectLocal.new(@access_controller, router: @router, device_mac: @device_mac).handle(Cassia.api.post(self))
34
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
35
  end
43
36
  end
44
37
  end
@@ -16,7 +16,7 @@ module Cassia
16
16
 
17
17
  def headers
18
18
  {
19
- 'Authorization' => "Bearer #{access_token}",
19
+ 'Authorization' => "Bearer #{@access_controller.get_token}",
20
20
  'Content-Type' => "application/json"
21
21
  }
22
22
  end
@@ -24,13 +24,6 @@ module Cassia
24
24
  def perform
25
25
  Cassia::ResponseHandlers::DisconnectDevice.new(@access_controller).handle(Cassia.api.post(self))
26
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
27
  end
35
28
  end
36
29
  end
@@ -13,7 +13,7 @@ module Cassia
13
13
 
14
14
  def headers
15
15
  {
16
- 'Authorization' => "Bearer #{access_token}",
16
+ 'Authorization' => "Bearer #{@access_controller.get_token}",
17
17
  'Content-Type' => "application/json"
18
18
  }
19
19
  end
@@ -21,13 +21,6 @@ module Cassia
21
21
  def perform
22
22
  Cassia::ResponseHandlers::DisconnectLocal.new(@access_controller, router: @router, device_mac: @device_mac).handle(Cassia.api.delete(self))
23
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
24
  end
32
25
  end
33
26
  end
@@ -13,7 +13,7 @@ module Cassia
13
13
 
14
14
  def headers
15
15
  {
16
- 'Authorization' => "Bearer #{access_token}",
16
+ 'Authorization' => "Bearer #{@access_controller.get_token}",
17
17
  'Content-Type' => "application/json"
18
18
  }
19
19
  end
@@ -21,13 +21,6 @@ module Cassia
21
21
  def perform
22
22
  Cassia::ResponseHandlers::DiscoverAllChar.new(@access_controller, router: @router, device_mac: @device_mac).handle(Cassia.api.get(self))
23
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
24
  end
32
25
  end
33
26
  end
@@ -13,7 +13,7 @@ module Cassia
13
13
 
14
14
  def headers
15
15
  {
16
- 'Authorization' => "Bearer #{access_token}",
16
+ 'Authorization' => "Bearer #{@access_controller.get_token}",
17
17
  'Content-Type' => "application/json"
18
18
  }
19
19
  end
@@ -21,13 +21,6 @@ module Cassia
21
21
  def perform
22
22
  Cassia::ResponseHandlers::DiscoverAllServices.new(@access_controller, router: @router, device_mac: @device_mac).handle(Cassia.api.get(self))
23
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
24
  end
32
25
  end
33
26
  end
@@ -13,7 +13,7 @@ module Cassia
13
13
 
14
14
  def headers
15
15
  {
16
- 'Authorization' => "Bearer #{access_token}",
16
+ 'Authorization' => "Bearer #{@access_controller.get_token}",
17
17
  'Content-Type' => "application/json"
18
18
  }
19
19
  end
@@ -21,13 +21,6 @@ module Cassia
21
21
  def perform
22
22
  Cassia::ResponseHandlers::DiscoverAllServicesAndChars.new(@access_controller, router: @router, device_mac: @device_mac).handle(Cassia.api.get(self))
23
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
24
  end
32
25
  end
33
26
  end
@@ -14,7 +14,7 @@ module Cassia
14
14
 
15
15
  def headers
16
16
  {
17
- 'Authorization' => "Bearer #{access_token}",
17
+ 'Authorization' => "Bearer #{@access_controller.get_token}",
18
18
  'Content-Type' => "application/json"
19
19
  }
20
20
  end
@@ -22,13 +22,6 @@ module Cassia
22
22
  def perform
23
23
  Cassia::ResponseHandlers::DiscoverCharOfService.new(@access_controller, router: @router, device_mac: @device_mac, service_uuid: @service_uuid).handle(Cassia.api.get(self))
24
24
  end
25
-
26
- private
27
-
28
- def access_token
29
- @access_controller.get_token if @access_controller.access_token.nil?
30
- @access_controller.access_token
31
- end
32
25
  end
33
26
  end
34
27
  end
@@ -14,7 +14,7 @@ module Cassia
14
14
 
15
15
  def headers
16
16
  {
17
- 'Authorization' => "Bearer #{access_token}",
17
+ 'Authorization' => "Bearer #{@access_controller.get_token}",
18
18
  'Content-Type' => "application/json"
19
19
  }
20
20
  end
@@ -22,13 +22,6 @@ module Cassia
22
22
  def perform
23
23
  Cassia::ResponseHandlers::DiscoverDescriptorOfChar.new(@access_controller, router: @router, device_mac: @device_mac, char_uuid: @char_uuid).handle(Cassia.api.get(self))
24
24
  end
25
-
26
- private
27
-
28
- def access_token
29
- @access_controller.get_token if @access_controller.access_token.nil?
30
- @access_controller.access_token
31
- end
32
25
  end
33
26
  end
34
27
  end
@@ -13,7 +13,7 @@ module Cassia
13
13
 
14
14
  def headers
15
15
  {
16
- 'Authorization' => "Bearer #{access_token}",
16
+ 'Authorization' => "Bearer #{@access_controller.get_token}",
17
17
  'Content-Type' => "application/json"
18
18
  }
19
19
  end
@@ -21,13 +21,6 @@ module Cassia
21
21
  def perform
22
22
  Cassia::ResponseHandlers::GetAllRoutersStatus.new(@access_controller).handle(Cassia.api.get(self))
23
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
24
  end
32
25
  end
33
26
  end
@@ -14,7 +14,7 @@ module Cassia
14
14
 
15
15
  def headers
16
16
  {
17
- 'Authorization' => "Bearer #{access_token}",
17
+ 'Authorization' => "Bearer #{@access_controller.get_token}",
18
18
  'Content-Type' => "application/json"
19
19
  }
20
20
  end
@@ -22,13 +22,6 @@ module Cassia
22
22
  def perform
23
23
  Cassia::ResponseHandlers::GetConnectedDevicesRouter.new(@access_controller, router: @router).handle(Cassia.api.get(self))
24
24
  end
25
-
26
- private
27
-
28
- def access_token
29
- @access_controller.get_token if @access_controller.access_token.nil?
30
- @access_controller.access_token
31
- end
32
25
  end
33
26
  end
34
27
  end
@@ -11,7 +11,7 @@ module Cassia
11
11
 
12
12
  def headers
13
13
  {
14
- 'Authorization' => "Bearer #{access_token}",
14
+ 'Authorization' => "Bearer #{@access_controller.get_token}",
15
15
  'Content-Type' => "application/json"
16
16
  }
17
17
  end
@@ -19,13 +19,6 @@ module Cassia
19
19
  def perform
20
20
  Cassia::ResponseHandlers::OpenApState.new(@access_controller).handle(Cassia.api.get(self))
21
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
22
  end
30
23
  end
31
24
  end
@@ -18,7 +18,7 @@ module Cassia
18
18
 
19
19
  def headers
20
20
  {
21
- 'Authorization' => "Bearer #{access_token}",
21
+ 'Authorization' => "Bearer #{@access_controller.get_token}",
22
22
  'Content-Type' => "application/json"
23
23
  }
24
24
  end
@@ -26,13 +26,6 @@ module Cassia
26
26
  def perform
27
27
  Cassia::ResponseHandlers::OpenConnectionState.new(@access_controller, aps: @aps).handle(Cassia.api.post(self))
28
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
29
  end
37
30
  end
38
31
  end
@@ -18,7 +18,7 @@ module Cassia
18
18
 
19
19
  def headers
20
20
  {
21
- 'Authorization' => "Bearer #{access_token}",
21
+ 'Authorization' => "Bearer #{@access_controller.get_token}",
22
22
  'Content-Type' => "application/json"
23
23
  }
24
24
  end
@@ -26,13 +26,6 @@ module Cassia
26
26
  def perform
27
27
  Cassia::ResponseHandlers::OpenNotify.new(@access_controller, aps: @aps).handle(Cassia.api.post(self))
28
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
29
  end
37
30
  end
38
31
  end
@@ -30,7 +30,7 @@ module Cassia
30
30
 
31
31
  def headers
32
32
  {
33
- 'Authorization' => "Bearer #{access_token}",
33
+ 'Authorization' => "Bearer #{@access_controller.get_token}",
34
34
  'Content-Type' => "application/json"
35
35
  }
36
36
  end
@@ -38,13 +38,6 @@ module Cassia
38
38
  def perform
39
39
  Cassia::ResponseHandlers::OpenScan.new(@access_controller, aps: @aps).handle(Cassia.api.post(self))
40
40
  end
41
-
42
- private
43
-
44
- def access_token
45
- @access_controller.get_token if @access_controller.access_token.nil?
46
- @access_controller.access_token
47
- end
48
41
  end
49
42
  end
50
43
  end
@@ -17,7 +17,7 @@ module Cassia
17
17
 
18
18
  def headers
19
19
  {
20
- 'Authorization' => "Bearer #{access_token}",
20
+ 'Authorization' => "Bearer #{@access_controller.get_token}",
21
21
  'Content-Type' => "application/json"
22
22
  }
23
23
  end
@@ -25,13 +25,6 @@ module Cassia
25
25
  def perform
26
26
  Cassia::ResponseHandlers::SwitchAutoselect.new(@access_controller).handle(Cassia.api.post(self))
27
27
  end
28
-
29
- private
30
-
31
- def access_token
32
- @access_controller.get_token if @access_controller.access_token.nil?
33
- @access_controller.access_token
34
- end
35
28
  end
36
29
  end
37
30
  end
@@ -15,7 +15,7 @@ module Cassia
15
15
 
16
16
  def headers
17
17
  {
18
- 'Authorization' => "Bearer #{access_token}",
18
+ 'Authorization' => "Bearer #{@access_controller.get_token}",
19
19
  'Content-Type' => "application/json"
20
20
  }
21
21
  end
@@ -23,13 +23,6 @@ module Cassia
23
23
  def perform
24
24
  Cassia::ResponseHandlers::WriteCharByHandle.new(@access_controller, router: @router, device_mac: @device_mac, handle: @handle, value: @value).handle(Cassia.api.get(self))
25
25
  end
26
-
27
- private
28
-
29
- def access_token
30
- @access_controller.get_token if @access_controller.access_token.nil?
31
- @access_controller.access_token
32
- end
33
26
  end
34
27
  end
35
28
  end
@@ -18,6 +18,9 @@ module Cassia
18
18
 
19
19
  def handle_success(response)
20
20
  @access_controller.access_token = response.body["access_token"]
21
+ # set the token expiration for 3500 seconds from now, the actual expiration is 3600
22
+ # but this gives some buffer
23
+ @access_controller.access_token_expiration = Time.now.getutc + 3500
21
24
  end
22
25
 
23
26
  def handle_failure(response)
@@ -10,8 +10,17 @@ module Cassia
10
10
  end
11
11
 
12
12
  def handle(response)
13
+ if response.success?
14
+ return handle_success
15
+ else
16
+ handle_failure(response)
17
+ end
18
+ response.success?
19
+ end
20
+
21
+ def handle_success
13
22
  device = @router.connected_devices.detect {|device| device.mac == @device_mac}
14
- char = device.characteristics.detect {|char| char.handle == @handle}
23
+ char = device.characteristics.detect {|char| char.handle == @handle || !char.descriptors.detect {|d| d.handle == @handle }.nil? }
15
24
  if char
16
25
  if @value == "0100"
17
26
  char.notification_on = true
@@ -23,6 +32,10 @@ module Cassia
23
32
  end
24
33
  !(char.nil?)
25
34
  end
35
+
36
+ def handle_failure(response)
37
+ @access_controller.error = response.body
38
+ end
26
39
  end
27
40
  end
28
41
  end
@@ -1,5 +1,5 @@
1
1
  module Cassia
2
2
  module Ruby
3
- VERSION = "1.0.0"
3
+ VERSION = "1.0.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cassia-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
- - adelinewang679
7
+ - Adeline Wang
8
+ - James Russo
8
9
  autorequire:
9
10
  bindir: exe
10
11
  cert_chain: []
11
- date: 2019-07-15 00:00:00.000000000 Z
12
+ date: 2019-10-11 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: faraday
@@ -86,14 +87,14 @@ dependencies:
86
87
  requirements:
87
88
  - - "~>"
88
89
  - !ruby/object:Gem::Version
89
- version: '10.0'
90
+ version: '13.0'
90
91
  type: :development
91
92
  prerelease: false
92
93
  version_requirements: !ruby/object:Gem::Requirement
93
94
  requirements:
94
95
  - - "~>"
95
96
  - !ruby/object:Gem::Version
96
- version: '10.0'
97
+ version: '13.0'
97
98
  - !ruby/object:Gem::Dependency
98
99
  name: rspec
99
100
  requirement: !ruby/object:Gem::Requirement
@@ -153,6 +154,7 @@ dependencies:
153
154
  description: a ruby api client for the cassia router api
154
155
  email:
155
156
  - adelinewang679@gmail.com
157
+ - jdrusso1020@gmail.com
156
158
  executables: []
157
159
  extensions: []
158
160
  extra_rdoc_files: []
@@ -176,6 +178,7 @@ files:
176
178
  - lib/cassia/characteristic.rb
177
179
  - lib/cassia/configuration.rb
178
180
  - lib/cassia/default_logger.rb
181
+ - lib/cassia/descriptor.rb
179
182
  - lib/cassia/device.rb
180
183
  - lib/cassia/requests/close_ap_state.rb
181
184
  - lib/cassia/requests/close_connection_state.rb