Class: Spacebunny::Device::Base
- Inherits:
-
Object
- Object
- Spacebunny::Device::Base
- Defined in:
- lib/spacebunny/device/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#api_endpoint ⇒ Object
Returns the value of attribute api_endpoint.
-
#auto_configs(force_reload = false) ⇒ Object
readonly
Retrieve configs from APIs endpoint.
-
#auto_connection_configs ⇒ Object
readonly
Returns the value of attribute auto_connection_configs.
-
#channels ⇒ Object
Returns the value of attribute channels.
-
#connection_configs ⇒ Object
(also: #auto_configure!)
readonly
Returns the value of attribute connection_configs.
-
#custom_connection_configs ⇒ Object
readonly
Returns the value of attribute custom_connection_configs.
-
#host ⇒ Object
Returns the value of attribute host.
-
#id ⇒ Object
Returns the value of attribute id.
-
#key ⇒ Object
Returns the value of attribute key.
-
#log_level ⇒ Object
readonly
Returns the value of attribute log_level.
-
#log_to ⇒ Object
readonly
Returns the value of attribute log_to.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#name ⇒ Object
Returns the value of attribute name.
-
#raise_on_error ⇒ Object
Returns the value of attribute raise_on_error.
-
#secret ⇒ Object
Returns the value of attribute secret.
-
#tls ⇒ Object
readonly
Returns the value of attribute tls.
-
#tls_ca_certificates ⇒ Object
readonly
Returns the value of attribute tls_ca_certificates.
-
#tls_cert ⇒ Object
readonly
Returns the value of attribute tls_cert.
-
#tls_key ⇒ Object
readonly
Returns the value of attribute tls_key.
-
#verify_peer ⇒ Object
readonly
Returns the value of attribute verify_peer.
-
#vhost ⇒ Object
(also: #organization_id)
Returns the value of attribute vhost.
Instance Method Summary collapse
- #connect ⇒ Object
- #connection_options=(options) ⇒ Object
- #disconnect ⇒ Object
-
#initialize(protocol, *args) ⇒ Base
constructor
A new instance of Base.
-
#on_receive(options = {}, &block) ⇒ Object
Stub method: must be implemented on the class responsible to handle the protocol.
-
#publish(channel, message, options = {}) ⇒ Object
Stub method: must be implemented on the class responsible to handle the protocol.
Constructor Details
#initialize(protocol, *args) ⇒ Base
Returns a new instance of Base.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/spacebunny/device/base.rb', line 17 def initialize(protocol, *args) @protocol = protocol @custom_connection_configs = {} @auto_connection_configs = {} = args..deep_symbolize_keys key = args.first @key = key || [:key] @api_endpoint = [:api_endpoint] || {} @raise_on_error = [:raise_on_error] @log_to = [:log_to] || STDOUT @log_level = [:log_level] || ::Logger::ERROR @logger = [:logger] || build_logger extract_and_normalize_custom_connection_configs_from set_channels [:channels] end |
Instance Attribute Details
#api_endpoint ⇒ Object
Returns the value of attribute api_endpoint.
13 14 15 |
# File 'lib/spacebunny/device/base.rb', line 13 def api_endpoint @api_endpoint end |
#auto_configs(force_reload = false) ⇒ Object (readonly)
Retrieve configs from APIs endpoint
44 45 46 |
# File 'lib/spacebunny/device/base.rb', line 44 def auto_configs @auto_configs end |
#auto_connection_configs ⇒ Object (readonly)
Returns the value of attribute auto_connection_configs.
14 15 16 |
# File 'lib/spacebunny/device/base.rb', line 14 def auto_connection_configs @auto_connection_configs end |
#channels ⇒ Object
Returns the value of attribute channels.
13 14 15 |
# File 'lib/spacebunny/device/base.rb', line 13 def channels @channels end |
#connection_configs ⇒ Object (readonly) Also known as: auto_configure!
Returns the value of attribute connection_configs.
14 15 16 |
# File 'lib/spacebunny/device/base.rb', line 14 def connection_configs @connection_configs end |
#custom_connection_configs ⇒ Object (readonly)
Returns the value of attribute custom_connection_configs.
14 15 16 |
# File 'lib/spacebunny/device/base.rb', line 14 def custom_connection_configs @custom_connection_configs end |
#host ⇒ Object
Returns the value of attribute host.
13 14 15 |
# File 'lib/spacebunny/device/base.rb', line 13 def host @host end |
#id ⇒ Object
Returns the value of attribute id.
13 14 15 |
# File 'lib/spacebunny/device/base.rb', line 13 def id @id end |
#key ⇒ Object
Returns the value of attribute key.
13 14 15 |
# File 'lib/spacebunny/device/base.rb', line 13 def key @key end |
#log_level ⇒ Object (readonly)
Returns the value of attribute log_level.
14 15 16 |
# File 'lib/spacebunny/device/base.rb', line 14 def log_level @log_level end |
#log_to ⇒ Object (readonly)
Returns the value of attribute log_to.
14 15 16 |
# File 'lib/spacebunny/device/base.rb', line 14 def log_to @log_to end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
14 15 16 |
# File 'lib/spacebunny/device/base.rb', line 14 def logger @logger end |
#name ⇒ Object
Returns the value of attribute name.
13 14 15 |
# File 'lib/spacebunny/device/base.rb', line 13 def name @name end |
#raise_on_error ⇒ Object
Returns the value of attribute raise_on_error.
13 14 15 |
# File 'lib/spacebunny/device/base.rb', line 13 def raise_on_error @raise_on_error end |
#secret ⇒ Object
Returns the value of attribute secret.
13 14 15 |
# File 'lib/spacebunny/device/base.rb', line 13 def secret @secret end |
#tls ⇒ Object (readonly)
Returns the value of attribute tls.
14 15 16 |
# File 'lib/spacebunny/device/base.rb', line 14 def tls @tls end |
#tls_ca_certificates ⇒ Object (readonly)
Returns the value of attribute tls_ca_certificates.
14 15 16 |
# File 'lib/spacebunny/device/base.rb', line 14 def tls_ca_certificates @tls_ca_certificates end |
#tls_cert ⇒ Object (readonly)
Returns the value of attribute tls_cert.
14 15 16 |
# File 'lib/spacebunny/device/base.rb', line 14 def tls_cert @tls_cert end |
#tls_key ⇒ Object (readonly)
Returns the value of attribute tls_key.
14 15 16 |
# File 'lib/spacebunny/device/base.rb', line 14 def tls_key @tls_key end |
#verify_peer ⇒ Object (readonly)
Returns the value of attribute verify_peer.
14 15 16 |
# File 'lib/spacebunny/device/base.rb', line 14 def verify_peer @verify_peer end |
#vhost ⇒ Object Also known as: organization_id
Returns the value of attribute vhost.
13 14 15 |
# File 'lib/spacebunny/device/base.rb', line 13 def vhost @vhost end |
Instance Method Details
#connect ⇒ Object
66 67 68 |
# File 'lib/spacebunny/device/base.rb', line 66 def connect logger.warn "connect method must be implemented on class responsibile to handle protocol '#{@protocol}'" end |
#connection_options=(options) ⇒ Object
70 71 72 73 74 75 |
# File 'lib/spacebunny/device/base.rb', line 70 def () unless .is_a? Hash raise ArgumentError, 'connection_options must be an Hash. See doc for further info' end extract_and_normalize_custom_connection_configs_from .with_indifferent_access end |
#disconnect ⇒ Object
77 78 79 |
# File 'lib/spacebunny/device/base.rb', line 77 def disconnect @connection_configs = nil end |
#on_receive(options = {}, &block) ⇒ Object
Stub method: must be implemented on the class responsible to handle the protocol
87 88 89 |
# File 'lib/spacebunny/device/base.rb', line 87 def on_receive( = {}, &block) logger.warn "on_receive method must be implemented on class responsibile to handle protocol '#{@protocol}'" end |
#publish(channel, message, options = {}) ⇒ Object
Stub method: must be implemented on the class responsible to handle the protocol
82 83 84 |
# File 'lib/spacebunny/device/base.rb', line 82 def publish(channel, , = {}) logger.warn "publish method must be implemented on class responsibile to handle protocol '#{@protocol}'" end |