Class: AwsIotDevice::MqttShadowClient::ShadowClient
- Inherits:
-
Object
- Object
- AwsIotDevice::MqttShadowClient::ShadowClient
- Defined in:
- lib/aws_iot_device/mqtt_shadow_client/shadow_client.rb
Instance Method Summary collapse
- #configure_credentials(ca_file, key, cert) ⇒ Object
- #configure_endpoint(host, port) ⇒ Object
- #connect(*args, &block) ⇒ Object
- #create_shadow_handler_with_name(shadow_name, persistent_subscribe = false) ⇒ Object
- #delete_shadow(timeout = 5, callback = nil, &block) ⇒ Object
- #disconnect ⇒ Object
- #get_shadow(timeout = 5, callback = nil, &block) ⇒ Object
-
#initialize(*args) ⇒ ShadowClient
constructor
A new instance of ShadowClient.
- #logger ⇒ Object
- #logger=(logger_path) ⇒ Object
- #logger? ⇒ Boolean
- #register_delete_callback(callback = nil, &block) ⇒ Object
- #register_delta_callback(callback = nil, &block) ⇒ Object
- #register_get_callback(callback = nil, &block) ⇒ Object
- #register_update_callback(callback = nil, &block) ⇒ Object
- #remove_delete_callback ⇒ Object
- #remove_delta_callback ⇒ Object
- #remove_get_callback ⇒ Object
- #remove_update_callback ⇒ Object
- #update_shadow(payload, timeout = 5, callback = nil, &block) ⇒ Object
Constructor Details
#initialize(*args) ⇒ ShadowClient
Returns a new instance of ShadowClient.
9 10 11 12 13 14 15 |
# File 'lib/aws_iot_device/mqtt_shadow_client/shadow_client.rb', line 9 def initialize(*args) unless args.last.nil? config_attr(args.last) else @mqtt_client = MqttManager.new end end |
Instance Method Details
#configure_credentials(ca_file, key, cert) ⇒ Object
100 101 102 |
# File 'lib/aws_iot_device/mqtt_shadow_client/shadow_client.rb', line 100 def configure_credentials(ca_file, key, cert) @mqtt_client.config_ssl_context(ca_file, key, cert) end |
#configure_endpoint(host, port) ⇒ Object
96 97 98 |
# File 'lib/aws_iot_device/mqtt_shadow_client/shadow_client.rb', line 96 def configure_endpoint(host, port) @mqtt_client.config_endpoint(host,port) end |
#connect(*args, &block) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/aws_iot_device/mqtt_shadow_client/shadow_client.rb', line 17 def connect(*args, &block) @mqtt_client.connect(*args) self.logger.info("Connected to the AWS IoT platform") if logger? if block_given? begin yield(self) ensure @mqtt_client.disconnect end end end |
#create_shadow_handler_with_name(shadow_name, persistent_subscribe = false) ⇒ Object
29 30 31 |
# File 'lib/aws_iot_device/mqtt_shadow_client/shadow_client.rb', line 29 def create_shadow_handler_with_name(shadow_name, persistent_subscribe=false) @action_manager = ShadowActionManager.new(shadow_name, @mqtt_client, persistent_subscribe) end |
#delete_shadow(timeout = 5, callback = nil, &block) ⇒ Object
56 57 58 |
# File 'lib/aws_iot_device/mqtt_shadow_client/shadow_client.rb', line 56 def delete_shadow(timeout=5, callback=nil, &block) @action_manager.shadow_delete(timeout, callback, &block) end |
#disconnect ⇒ Object
92 93 94 |
# File 'lib/aws_iot_device/mqtt_shadow_client/shadow_client.rb', line 92 def disconnect @mqtt_client.disconnect end |
#get_shadow(timeout = 5, callback = nil, &block) ⇒ Object
48 49 50 |
# File 'lib/aws_iot_device/mqtt_shadow_client/shadow_client.rb', line 48 def get_shadow(timeout=5, callback=nil, &block) @action_manager.shadow_get(timeout, callback, &block) end |
#logger ⇒ Object
40 41 42 |
# File 'lib/aws_iot_device/mqtt_shadow_client/shadow_client.rb', line 40 def logger @action_manager.logger end |
#logger=(logger_path) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/aws_iot_device/mqtt_shadow_client/shadow_client.rb', line 33 def logger=(logger_path) file = File.open(logger_path, "a+") log_file = Logger.new(file) log_file.level = Logger::DEBUG @action_manager.logger = log_file end |
#logger? ⇒ Boolean
44 45 46 |
# File 'lib/aws_iot_device/mqtt_shadow_client/shadow_client.rb', line 44 def logger? @action_manager.logger? end |
#register_delete_callback(callback = nil, &block) ⇒ Object
68 69 70 |
# File 'lib/aws_iot_device/mqtt_shadow_client/shadow_client.rb', line 68 def register_delete_callback(callback=nil, &block) @action_manager.register_delete_callback(callback, &block) end |
#register_delta_callback(callback = nil, &block) ⇒ Object
72 73 74 |
# File 'lib/aws_iot_device/mqtt_shadow_client/shadow_client.rb', line 72 def register_delta_callback(callback=nil, &block) @action_manager.register_shadow_delta_callback(callback, &block) end |
#register_get_callback(callback = nil, &block) ⇒ Object
60 61 62 |
# File 'lib/aws_iot_device/mqtt_shadow_client/shadow_client.rb', line 60 def register_get_callback(callback=nil, &block) @action_manager.register_get_callback(callback, &block) end |
#register_update_callback(callback = nil, &block) ⇒ Object
64 65 66 |
# File 'lib/aws_iot_device/mqtt_shadow_client/shadow_client.rb', line 64 def register_update_callback(callback=nil, &block) @action_manager.register_update_callback(callback, &block) end |
#remove_delete_callback ⇒ Object
88 89 90 |
# File 'lib/aws_iot_device/mqtt_shadow_client/shadow_client.rb', line 88 def remove_delete_callback @action_manager.remove_delete_callback end |
#remove_delta_callback ⇒ Object
76 77 78 |
# File 'lib/aws_iot_device/mqtt_shadow_client/shadow_client.rb', line 76 def remove_delta_callback @action_manager.remove_shadow_delta_callback end |
#remove_get_callback ⇒ Object
80 81 82 |
# File 'lib/aws_iot_device/mqtt_shadow_client/shadow_client.rb', line 80 def remove_get_callback @action_manager.remove_get_callback end |
#remove_update_callback ⇒ Object
84 85 86 |
# File 'lib/aws_iot_device/mqtt_shadow_client/shadow_client.rb', line 84 def remove_update_callback @action_manager.remove_update_callback end |
#update_shadow(payload, timeout = 5, callback = nil, &block) ⇒ Object
52 53 54 |
# File 'lib/aws_iot_device/mqtt_shadow_client/shadow_client.rb', line 52 def update_shadow(payload, timeout=5, callback=nil, &block) @action_manager.shadow_update(payload, timeout, callback, &block) end |