Module: Vayacondios::Client::Connection
Class Method Summary collapse
Instance Method Summary collapse
- #configure_connection(options) ⇒ Object
- #http_connection ⇒ Object
- #organization ⇒ Object
- #url(handler, topic = nil, id = nil) ⇒ Object
Class Method Details
.base_uri(options) ⇒ Object
4 5 6 7 8 |
# File 'lib/vayacondios/client/connection.rb', line 4 def self.base_uri host = [:host] || ConnectionOpts[:host] port = [:port] || ConnectionOpts[:port] "http://#{host}:#{port}/#{Vayacondios::API_VERSION}" end |
.factory(options = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/vayacondios/client/connection.rb', line 10 def self.factory( = {}) Faraday.new(base_uri ) do |setup| setup.request :json setup.adapter [:adapter] || ConnectionOpts[:adapter] setup.response :json, content_type: /\bjson$/ if logger = [:log] || ConnectionOpts[:log] setup.response :logger, logger end end end |
Instance Method Details
#configure_connection(options) ⇒ Object
30 31 32 |
# File 'lib/vayacondios/client/connection.rb', line 30 def configure_connection @connection = Connection.factory() end |
#http_connection ⇒ Object
34 35 36 |
# File 'lib/vayacondios/client/connection.rb', line 34 def http_connection @connection ||= Connection.factory end |
#organization ⇒ Object
21 22 23 |
# File 'lib/vayacondios/client/connection.rb', line 21 def organization 'vcd' end |
#url(handler, topic = nil, id = nil) ⇒ Object
25 26 27 28 |
# File 'lib/vayacondios/client/connection.rb', line 25 def url(handler, topic = nil, id = nil) segments = [organization, handler, topic, id].compact.map(&:to_s) File.join(*segments) end |