apiotics_aws_client 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. checksums.yaml +7 -0
  2. data/CODE_OF_CONDUCT.md +13 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE +201 -0
  5. data/README.md +207 -0
  6. data/Rakefile +6 -0
  7. data/apiotics-aws-iot-client-1.0.0.gem +0 -0
  8. data/apiotics_aws_client.gemspec +40 -0
  9. data/bin/console +11 -0
  10. data/bin/setup +7 -0
  11. data/codeclimate.yml +6 -0
  12. data/lib/aws_iot_device.rb +8 -0
  13. data/lib/aws_iot_device/mqtt_adapter.rb +31 -0
  14. data/lib/aws_iot_device/mqtt_adapter/client.rb +207 -0
  15. data/lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb +207 -0
  16. data/lib/aws_iot_device/mqtt_adapter/ruby_mqtt_adapter.rb +183 -0
  17. data/lib/aws_iot_device/mqtt_shadow_client.rb +7 -0
  18. data/lib/aws_iot_device/mqtt_shadow_client/json_payload_parser.rb +34 -0
  19. data/lib/aws_iot_device/mqtt_shadow_client/mqtt_manager.rb +201 -0
  20. data/lib/aws_iot_device/mqtt_shadow_client/shadow_action_manager.rb +318 -0
  21. data/lib/aws_iot_device/mqtt_shadow_client/shadow_client.rb +118 -0
  22. data/lib/aws_iot_device/mqtt_shadow_client/shadow_topic_manager.rb +75 -0
  23. data/lib/aws_iot_device/mqtt_shadow_client/token_creator.rb +36 -0
  24. data/lib/aws_iot_device/mqtt_shadow_client/topic_builder.rb +35 -0
  25. data/lib/aws_iot_device/version.rb +3 -0
  26. data/samples/config_shadow.rb +72 -0
  27. data/samples/mqtt_client_samples/mqtt_client_samples.rb +38 -0
  28. data/samples/shadow_action_samples/sample_shadow_action_update.rb +25 -0
  29. data/samples/shadow_client_samples/samples_shadow_client_block.rb +25 -0
  30. data/samples/shadow_client_samples/samples_shadow_client_delete.rb +24 -0
  31. data/samples/shadow_client_samples/samples_shadow_client_description.rb +64 -0
  32. data/samples/shadow_client_samples/samples_shadow_client_get.rb +23 -0
  33. data/samples/shadow_client_samples/samples_shadow_client_getting_started.rb +22 -0
  34. data/samples/shadow_client_samples/samples_shadow_client_update.rb +30 -0
  35. data/samples/shadow_topic_samples/sample_topic_manager.rb +26 -0
  36. metadata +216 -0
@@ -0,0 +1,64 @@
1
+ require "aws_iot_device"
2
+
3
+ host = "AWS IoT endpoint"
4
+ port = 8883
5
+ thing = "Thing Name"
6
+ root_ca_path = "Path to your CA certificate"
7
+ private_key_path = "Path to your private key"
8
+ certificate_path = "Path to your certificate"
9
+
10
+ # Create a new client with empty arguments
11
+ shadow_client = AwsIotDevice::MqttShadowClient::ShadowClient.new
12
+
13
+ # Configure the endpoint and the port the client would connect
14
+ shadow_client.configure_endpoint(host, port)
15
+
16
+ # Configure the credentials to enable a connection over TLS/SSL encryption
17
+ shadow_client.configure_credentials(root_ca_path, private_key_path, certificate_path)
18
+
19
+ # Create an event handler to bind the client with the remote thing in a persistent mode
20
+ shadow_client.create_shadow_handler_with_name(thing, true)
21
+
22
+ # Local timeout used for operation
23
+ timeout = 4
24
+
25
+ # Send a connect request to the AWS IoT platform
26
+ shadow_client.connect
27
+
28
+ # Register a callback for the get action as a block
29
+ shadow_client.register_get_callback do
30
+ puts "generic callback for get action"
31
+ end
32
+
33
+ # Register a callback for the delete action as a proc
34
+ shadow_client.register_delete_callback(proc { puts "generic callback for delete action"})
35
+
36
+ # Register a callback for the update action as a lambda
37
+ shadow_client.register_update_callback(lambda {|_message| puts "generic callback for update action"})
38
+
39
+ # Register a callback for the delta events
40
+ shadow_client.register_delta_callback do
41
+ puts "delta have been catch in a callback"
42
+ end
43
+
44
+ # Send a get request with an associated callback in a block
45
+ shadow_client.get_shadow do
46
+ puts "get thing"
47
+ end
48
+
49
+ # Send a delete request with an associated callback in a proc
50
+ shadow_client.delete_shadow(timeout, proc {puts "delete thing"})
51
+
52
+ # Send a udpate request with an associated callback in a lambda
53
+ shadow_client.update_shadow("{\"state\":{\"desired\":{\"message\":\"Hello\"}}}", timeout, lambda {|_message| puts "update thing"})
54
+
55
+ # Sleep to assert all opereation have been processed
56
+ sleep timeout
57
+
58
+ # Clear out the previously registered callback for each action
59
+ shadow_client.remove_get_callback
60
+ shadow_client.remove_update_callback
61
+ shadow_client.remove_delete_callback
62
+
63
+ # Explicit disconnect from the AWS IoT platform
64
+ shadow_client.disconnect
@@ -0,0 +1,23 @@
1
+ $:.unshift(File.expand_path("../../../samples", __FILE__))
2
+
3
+ require 'aws_iot_device'
4
+ require 'config_shadow'
5
+
6
+ filter_callback = Proc.new do |message|
7
+ puts "Executing the specific callback for topic: #{message.topic}\n##########################################\n"
8
+ end
9
+
10
+ my_shadow_client = setting_shadow
11
+
12
+ puts "##### Starting test_shadow_client_get ######"
13
+ my_shadow_client.get_shadow(2, filter_callback)
14
+
15
+ puts "##### Starting test_shadow_client_get ######"
16
+ my_shadow_client.get_shadow do
17
+ puts "Block callback for a token"
18
+ end
19
+
20
+ puts "##### Starting test_shadow_client_get ######"
21
+ my_shadow_client.get_shadow(2, filter_callback)
22
+
23
+ sleep 3
@@ -0,0 +1,22 @@
1
+ require "aws_iot_device"
2
+
3
+ host = "AWS IoT endpoint"
4
+ port = 8883
5
+ thing = "Thing Name"
6
+ root_ca_path = "Path to your CA certificate"
7
+ private_key_path = "Path to your private key"
8
+ certificate_path = "Path to your certificate"
9
+
10
+ shadow_client = AwsIotDevice::MqttShadowClient::ShadowClient.new
11
+ shadow_client.configure_endpoint(host, port)
12
+ shadow_client.configure_credentials(root_ca_path, private_key_path, certificate_path)
13
+ shadow_client.create_shadow_handler_with_name(thing, true)
14
+
15
+ shadow_client.connect
16
+ shadow_client.get_shadow do |_message|
17
+ # Do what you want with the get_shadow's answer
18
+ p ":)"
19
+ end
20
+ sleep 2 #Timer to ensure that the answer is received
21
+
22
+ shadow_client.disconnect
@@ -0,0 +1,30 @@
1
+ $:.unshift(File.expand_path("../../../samples", __FILE__))
2
+
3
+ require 'aws_iot_device'
4
+ require 'config_shadow'
5
+
6
+ filter_callback = Proc.new do |message|
7
+ puts "Executing the specific callback for topic: #{message.topic}\n##########################################\n"
8
+ end
9
+
10
+ delta_callback = Proc.new do |delta|
11
+ message = JSON.parse(delta.payload)
12
+ puts "Catching a new message : #{message["state"]["message"]}\n##########################################\n"
13
+ end
14
+
15
+ my_shadow_client = setting_shadow
16
+ my_shadow_client.register_delta_callback(delta_callback)
17
+
18
+ n = 1
19
+ 3.times do
20
+ puts "Type the message that you want to register in the thing:"
21
+ entry = $stdin.readline()
22
+ json_payload = "{\"state\":{\"desired\":{\"message\":\"#{entry.delete!("\n")}\"}}}"
23
+ my_shadow_client.update_shadow(json_payload, 5, filter_callback)
24
+ puts "#{3 - n} Message(s) left"
25
+ n += 1
26
+ end
27
+
28
+ sleep 3
29
+
30
+ my_shadow_client.disconnect
@@ -0,0 +1,26 @@
1
+ $:.unshift(File.expand_path("../../../samples", __FILE__))
2
+
3
+ require 'aws_iot_device'
4
+ require 'config_shadow'
5
+
6
+ mqtt_client = setting_mqtt_client
7
+
8
+ topic_client = setting_topic_manager(mqtt_client)
9
+
10
+ filter_callback = Proc.new do |message|
11
+ puts "Received (through filtered callback) : "
12
+ puts "------------------- Topic: #{message.topic}"
13
+ puts "------------------- Payload: #{message.payload}"
14
+ puts "###################"
15
+ end
16
+
17
+ topic_client.shadow_topic_subscribe("get", filter_callback)
18
+
19
+ 4.times do
20
+ topic_client.shadow_topic_publish("get", "")
21
+ end
22
+
23
+ sleep 2
24
+
25
+ mqtt_client.disconnect
26
+
metadata ADDED
@@ -0,0 +1,216 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: apiotics_aws_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Mac Dougherty
8
+ - Pierre Goudet
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2018-05-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.10'
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: '1.10'
24
+ type: :development
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - "~>"
29
+ - !ruby/object:Gem::Version
30
+ version: '1.10'
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ - !ruby/object:Gem::Dependency
35
+ name: pry
36
+ requirement: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.10.4
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.10.4
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - "~>"
49
+ - !ruby/object:Gem::Version
50
+ version: 0.10.4
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 0.10.4
54
+ - !ruby/object:Gem::Dependency
55
+ name: rake
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '10.0'
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '1.10'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - "~>"
69
+ - !ruby/object:Gem::Version
70
+ version: '10.0'
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '1.10'
74
+ - !ruby/object:Gem::Dependency
75
+ name: rspec
76
+ requirement: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: 3.5.0
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: 3.5.0
84
+ type: :development
85
+ prerelease: false
86
+ version_requirements: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: 3.5.0
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: 3.5.0
94
+ - !ruby/object:Gem::Dependency
95
+ name: json
96
+ requirement: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - "~>"
99
+ - !ruby/object:Gem::Version
100
+ version: 2.0.2
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 2.0.2
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 2.0.2
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: 2.0.2
114
+ - !ruby/object:Gem::Dependency
115
+ name: apiotics-paho-mqtt
116
+ requirement: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - "~>"
119
+ - !ruby/object:Gem::Version
120
+ version: 1.0.0
121
+ type: :runtime
122
+ prerelease: false
123
+ version_requirements: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - "~>"
126
+ - !ruby/object:Gem::Version
127
+ version: 1.0.0
128
+ - !ruby/object:Gem::Dependency
129
+ name: timers
130
+ requirement: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - "~>"
133
+ - !ruby/object:Gem::Version
134
+ version: 4.1.1
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: 4.1.1
138
+ type: :runtime
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: 4.1.1
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: 4.1.1
148
+ description: The gem is using the MQTT protocol to execute the command defined by
149
+ the AWS IoT platform. A default MQTT client is included in the gem, however an adapter
150
+ system enables to plug another MQTT client.
151
+ email:
152
+ - info@apiotics.com
153
+ executables: []
154
+ extensions: []
155
+ extra_rdoc_files: []
156
+ files:
157
+ - CODE_OF_CONDUCT.md
158
+ - Gemfile
159
+ - LICENSE
160
+ - README.md
161
+ - Rakefile
162
+ - apiotics-aws-iot-client-1.0.0.gem
163
+ - apiotics_aws_client.gemspec
164
+ - bin/console
165
+ - bin/setup
166
+ - codeclimate.yml
167
+ - lib/aws_iot_device.rb
168
+ - lib/aws_iot_device/mqtt_adapter.rb
169
+ - lib/aws_iot_device/mqtt_adapter/client.rb
170
+ - lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb
171
+ - lib/aws_iot_device/mqtt_adapter/ruby_mqtt_adapter.rb
172
+ - lib/aws_iot_device/mqtt_shadow_client.rb
173
+ - lib/aws_iot_device/mqtt_shadow_client/json_payload_parser.rb
174
+ - lib/aws_iot_device/mqtt_shadow_client/mqtt_manager.rb
175
+ - lib/aws_iot_device/mqtt_shadow_client/shadow_action_manager.rb
176
+ - lib/aws_iot_device/mqtt_shadow_client/shadow_client.rb
177
+ - lib/aws_iot_device/mqtt_shadow_client/shadow_topic_manager.rb
178
+ - lib/aws_iot_device/mqtt_shadow_client/token_creator.rb
179
+ - lib/aws_iot_device/mqtt_shadow_client/topic_builder.rb
180
+ - lib/aws_iot_device/version.rb
181
+ - samples/config_shadow.rb
182
+ - samples/mqtt_client_samples/mqtt_client_samples.rb
183
+ - samples/shadow_action_samples/sample_shadow_action_update.rb
184
+ - samples/shadow_client_samples/samples_shadow_client_block.rb
185
+ - samples/shadow_client_samples/samples_shadow_client_delete.rb
186
+ - samples/shadow_client_samples/samples_shadow_client_description.rb
187
+ - samples/shadow_client_samples/samples_shadow_client_get.rb
188
+ - samples/shadow_client_samples/samples_shadow_client_getting_started.rb
189
+ - samples/shadow_client_samples/samples_shadow_client_update.rb
190
+ - samples/shadow_topic_samples/sample_topic_manager.rb
191
+ homepage: https://portal.apiotics.com
192
+ licenses:
193
+ - Apache-2.0
194
+ metadata: {}
195
+ post_install_message:
196
+ rdoc_options: []
197
+ require_paths:
198
+ - lib
199
+ required_ruby_version: !ruby/object:Gem::Requirement
200
+ requirements:
201
+ - - ">="
202
+ - !ruby/object:Gem::Version
203
+ version: '0'
204
+ required_rubygems_version: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ requirements: []
210
+ rubyforge_project:
211
+ rubygems_version: 2.2.2
212
+ signing_key:
213
+ specification_version: 4
214
+ summary: The ruby version of the AWS IoT Device SDK. It enables to connect to AWS
215
+ IoT platform and manage Things.
216
+ test_files: []