Class: Yodeler::Adapters::HttpAdapter
- Inherits:
-
Object
- Object
- Yodeler::Adapters::HttpAdapter
- Defined in:
- lib/yodeler/adapters/http_adapter.rb
Instance Attribute Summary collapse
-
#default_params ⇒ Object
Returns the value of attribute default_params.
-
#host ⇒ Object
Returns the value of attribute host.
-
#path ⇒ Object
Returns the value of attribute path.
-
#port ⇒ Object
Returns the value of attribute port.
-
#use_ssl ⇒ Object
Returns the value of attribute use_ssl.
Instance Method Summary collapse
- #dispatch(metric) ⇒ Object
- #handle(type, &block) ⇒ Object
-
#initialize(host = nil, port: nil, path: nil, use_ssl: false, params: {}) ⇒ HttpAdapter
constructor
A new instance of HttpAdapter.
- #url ⇒ Object
Constructor Details
#initialize(host = nil, port: nil, path: nil, use_ssl: false, params: {}) ⇒ HttpAdapter
Returns a new instance of HttpAdapter.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/yodeler/adapters/http_adapter.rb', line 11 def initialize(host = nil, port:nil, path:nil, use_ssl:false, params:{}) @host = host @port = port @path = path @use_ssl = use_ssl @default_params = params @handlers = {} handle(:default) do |url, metric, default_params| HTTP.post(url, json: default_params.merge(metric.to_hash)) end end |
Instance Attribute Details
#default_params ⇒ Object
Returns the value of attribute default_params.
9 10 11 |
# File 'lib/yodeler/adapters/http_adapter.rb', line 9 def default_params @default_params end |
#host ⇒ Object
Returns the value of attribute host.
5 6 7 |
# File 'lib/yodeler/adapters/http_adapter.rb', line 5 def host @host end |
#path ⇒ Object
Returns the value of attribute path.
7 8 9 |
# File 'lib/yodeler/adapters/http_adapter.rb', line 7 def path @path end |
#port ⇒ Object
Returns the value of attribute port.
6 7 8 |
# File 'lib/yodeler/adapters/http_adapter.rb', line 6 def port @port end |
#use_ssl ⇒ Object
Returns the value of attribute use_ssl.
8 9 10 |
# File 'lib/yodeler/adapters/http_adapter.rb', line 8 def use_ssl @use_ssl end |
Instance Method Details
#dispatch(metric) ⇒ Object
28 29 30 31 |
# File 'lib/yodeler/adapters/http_adapter.rb', line 28 def dispatch(metric) dispatcher = @handlers[metric.type] || @handlers[:default] dispatcher.call(url, metric, default_params) end |
#handle(type, &block) ⇒ Object
24 25 26 |
# File 'lib/yodeler/adapters/http_adapter.rb', line 24 def handle(type, &block) @handlers[type] = block end |
#url ⇒ Object
33 34 35 |
# File 'lib/yodeler/adapters/http_adapter.rb', line 33 def url "#{protocol}://#{host_with_port}#{path}" end |