aws_iot_device 0.1.5 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/README.md +155 -148
  4. data/aws_iot_device.gemspec +11 -11
  5. data/codeclimate.yml +6 -0
  6. data/lib/aws_iot_device.rb +2 -1
  7. data/lib/aws_iot_device/mqtt_adapter.rb +1 -2
  8. data/lib/aws_iot_device/mqtt_adapter/client.rb +74 -6
  9. data/lib/aws_iot_device/mqtt_adapter/paho_mqtt_adapter.rb +207 -0
  10. data/lib/aws_iot_device/mqtt_adapter/ruby_mqtt_adapter.rb +10 -4
  11. data/lib/aws_iot_device/mqtt_shadow_client.rb +1 -0
  12. data/lib/aws_iot_device/mqtt_shadow_client/mqtt_manager.rb +133 -67
  13. data/lib/aws_iot_device/mqtt_shadow_client/shadow_action_manager.rb +229 -146
  14. data/lib/aws_iot_device/mqtt_shadow_client/shadow_client.rb +78 -20
  15. data/lib/aws_iot_device/mqtt_shadow_client/shadow_topic_manager.rb +51 -26
  16. data/lib/aws_iot_device/mqtt_shadow_client/topic_builder.rb +15 -30
  17. data/lib/aws_iot_device/version.rb +1 -1
  18. data/samples/config_shadow.rb +72 -0
  19. data/samples/mqtt_client_samples/mqtt_client_samples.rb +7 -59
  20. data/samples/shadow_action_samples/sample_shadow_action_update.rb +7 -61
  21. data/samples/shadow_client_samples/samples_shadow_client_block.rb +25 -0
  22. data/samples/shadow_client_samples/samples_shadow_client_delete.rb +9 -58
  23. data/samples/shadow_client_samples/samples_shadow_client_description.rb +64 -0
  24. data/samples/shadow_client_samples/samples_shadow_client_get.rb +11 -62
  25. data/samples/shadow_client_samples/samples_shadow_client_getting_started.rb +22 -0
  26. data/samples/shadow_client_samples/samples_shadow_client_update.rb +7 -58
  27. data/samples/shadow_topic_samples/sample_topic_manager.rb +10 -61
  28. metadata +71 -16
  29. data/lib/aws_iot_device/mqtt_adapter/mqtt_adapter.rb +0 -139
@@ -1,139 +0,0 @@
1
- module AwsIotDevice
2
- module MqttAdapter
3
- class MqttAdapter
4
-
5
- attr_reader :client_id
6
-
7
- ### @adapter contains the name of the adapter that should be module as a third party librairy
8
- ### The method call by the shared client are implemented by the third party or the adapter module itself.
9
- ### @adapter default value is MqttShareLib::Adapters::RubyMqttAdapter
10
- attr_accessor :adapter
11
-
12
- ### @on_'event' contains the callback's [block, Proc, lambda] that should be called when 'event' is catched
13
- ### Callbacks should be customized in the higher level class (ex. MqttManger or upper)
14
- ### Callback should be called by some (private) handlers define in the third party librairy
15
-
16
- ### On a MqttAdapter's create, the client adapter is set as the previously define module adapter
17
- ### The client is then initialize with the client type of the third librairy of the adapter.
18
- ### @client default type is MQTT::Client
19
- def initialize(*args)
20
- @adapter = ::MqttAdapterLib.adapter.new(*args)
21
- end
22
-
23
- def client_id
24
- @adapter.client_id
25
- end
26
-
27
- ### The following method represent the basics common MQTT actions.
28
- ### As possible, they should be implemented in the third party librairy
29
- ### If not, the adpater should implement them or throw and excpetion
30
- def connect(*args, &block)
31
- @adapter.connect(*args, &block)
32
- end
33
-
34
- def publish(topic, payload='', retain=false, qos=0)
35
- @adapter.publish(topic, payload, retain, qos)
36
- end
37
-
38
- def loop_start
39
- @thread = @adapter.loop_start
40
- end
41
-
42
- def loop_stop
43
- @adapter.loop_stop(@thread)
44
- end
45
-
46
- def loop_forever
47
- @adapter.loop_forever
48
- end
49
-
50
- def mqtt_loop
51
- @adapter.loop
52
- end
53
-
54
- def loop_read
55
- @adapter.loop_read
56
- end
57
-
58
- def loop_write
59
- @adapter.loop_write
60
- end
61
-
62
- def loop_misc
63
- @adapter.loop_misc
64
- end
65
-
66
- def get(topic=nil, &block)
67
- @adapter.get(topic, &block)
68
- end
69
-
70
- def get_packet(topic=nil, &block)
71
- @adapter.get_packet(topic, &block)
72
- end
73
-
74
- def generate_client_id
75
- @adapter.generate_client_id
76
- end
77
-
78
- def disconnect(send_msg=true)
79
- @adapter.disconnect(send_msg)
80
- end
81
-
82
- def connected?
83
- @adapter.connected?
84
- end
85
-
86
- def subscribe(topic)
87
- @adapter.subscribe(topic)
88
- end
89
-
90
- def unsubscribe(topic)
91
- @adapter.unsubscribe(topic)
92
- end
93
-
94
- def set_tls_ssl_context(ca_cert, cert=nil, key=nil)
95
- @adapter.set_tls_ssl_context(ca_cert, cert, key)
96
- end
97
-
98
- def add_callback_filter_topic(topic, callback)
99
- @adapter.add_callback_filter_topic(topic, callback)
100
- end
101
-
102
- def remove_callback_filter_topic(topic)
103
- @adapter.remove_callback_filter_topic(topic)
104
- end
105
-
106
- def on_message=(callback)
107
- @adapter.on_message = callback
108
- end
109
-
110
- ### The following attributes should exists in every MQTT third party librairy.
111
- ### They are necessary (or really usefull and common) for the establishement of the connection and/or the basic Mqtt actions.
112
- ### The setter directely change the third party client value when the getter remote the actual SharedClient instance's attribute value
113
- def host
114
- @adapter.host
115
- end
116
-
117
- def host=(host)
118
- @adapter.host = host
119
- end
120
-
121
- def port
122
- @adapter.port
123
- end
124
-
125
- def port=(port)
126
- @adapter.port = port
127
- end
128
-
129
- # Boolean for the encrypted mode (true = ssl/tls | false = no encryption)
130
- def ssl
131
- @adapter.ssl
132
- end
133
-
134
- def ssl=(ssl)
135
- @adapter.ssl = ssl
136
- end
137
- end
138
- end
139
- end