Class: Spacebunny::Device::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/spacebunny/device/base.rb

Direct Known Subclasses

Amqp

Instance Attribute Summary collapse

Instance Method Summary collapse

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 = {}
  options = args.extract_options.deep_symbolize_keys
  key = args.first

  @key = key || options[:key]
  @api_endpoint = options[:api_endpoint] || {}

  @raise_on_error = options[:raise_on_error]
  @log_to = options[:log_to] || STDOUT
  @log_level = options[:log_level] || ::Logger::ERROR
  @logger = options[:logger] || build_logger

  extract_and_normalize_custom_connection_configs_from options
  set_channels options[:channels]
end

Instance Attribute Details

#api_endpointObject

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_configsObject (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

#channelsObject

Returns the value of attribute channels.



13
14
15
# File 'lib/spacebunny/device/base.rb', line 13

def channels
  @channels
end

#connection_configsObject (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_configsObject (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

#hostObject

Returns the value of attribute host.



13
14
15
# File 'lib/spacebunny/device/base.rb', line 13

def host
  @host
end

#idObject

Returns the value of attribute id.



13
14
15
# File 'lib/spacebunny/device/base.rb', line 13

def id
  @id
end

#keyObject

Returns the value of attribute key.



13
14
15
# File 'lib/spacebunny/device/base.rb', line 13

def key
  @key
end

#log_levelObject (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_toObject (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

#loggerObject (readonly)

Returns the value of attribute logger.



14
15
16
# File 'lib/spacebunny/device/base.rb', line 14

def logger
  @logger
end

#nameObject

Returns the value of attribute name.



13
14
15
# File 'lib/spacebunny/device/base.rb', line 13

def name
  @name
end

#raise_on_errorObject

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

#secretObject

Returns the value of attribute secret.



13
14
15
# File 'lib/spacebunny/device/base.rb', line 13

def secret
  @secret
end

#tlsObject (readonly)

Returns the value of attribute tls.



14
15
16
# File 'lib/spacebunny/device/base.rb', line 14

def tls
  @tls
end

#tls_ca_certificatesObject (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_certObject (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_keyObject (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_peerObject (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

#vhostObject 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

#connectObject



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 connection_options=(options)
  unless options.is_a? Hash
    raise ArgumentError, 'connection_options must be an Hash. See doc for further info'
  end
  extract_and_normalize_custom_connection_configs_from options.with_indifferent_access
end

#disconnectObject



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(options = {}, &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, message, options = {})
  logger.warn "publish method must be implemented on class responsibile to handle protocol '#{@protocol}'"
end