class Conductor::Connection

Attributes

args[R]
connection[R]

Public Class Methods

new(args = {}) click to toggle source
# File lib/nf-conductor/http/connection.rb, line 7
def initialize(args = {})
  @connection ||= Faraday.new(url: Conductor.config.service_uri) do |c|
    c.request :json
    c.response :json, content_type: /\bjson$/, parser_options: { symbolize_names: true }
    c.adapter Faraday.default_adapter
  end

  args.each do |k,v|
    @connection.headers[k] = v
  end
end

Public Instance Methods

delete(url, args={}) click to toggle source
# File lib/nf-conductor/http/connection.rb, line 52
def delete(url, args={})
  Rails.logger.info("Conductor::Connection : DELETE #{url} with args #{args}") if Conductor.config.verbose
  connection.delete do |req|
    req.url url
    req.headers['Content-Type'] = ( args[:headers] && args[:headers]['Content-Type'] || 'application/json' )
    req.body = args[:body] if args[:body]
  end
rescue Faraday::ParsingError
  Struct.new(:status, :body).new(500, 'Conductor::Connection : Faraday failed to properly parse response.')
end
get(url, args={}) click to toggle source
# File lib/nf-conductor/http/connection.rb, line 19
def get(url, args={})
  Rails.logger.info("Conductor::Connection : GET #{url} with args #{args}") if Conductor.config.verbose
  connection.get do |req|
    req.url url
    req.headers['Content-Type'] = ( args[:headers] && args[:headers]['Content-Type'] || 'application/json' )
    req.body = args[:body] if args[:body]
  end
rescue Faraday::ParsingError
  Struct.new(:status, :body).new(500, 'Conductor::Connection : Faraday failed to properly parse response.')
end
post(url, args={}) click to toggle source
# File lib/nf-conductor/http/connection.rb, line 30
def post(url, args={})
  Rails.logger.info("Conductor::Connection : POST #{url} with args #{args}") if Conductor.config.verbose
  connection.post do |req|
    req.url url
    req.headers['Content-Type'] = ( args[:headers] && args[:headers]['Content-Type'] || 'application/json' )
    req.body = args[:body] if args[:body]
  end
rescue Faraday::ParsingError
  Struct.new(:status, :body).new(500, 'Conductor::Connection : Faraday failed to properly parse response.')
end
put(url, args={}) click to toggle source
# File lib/nf-conductor/http/connection.rb, line 41
def put(url, args={})
  Rails.logger.info("Conductor::Connection : PUT #{url} with args #{args}") if Conductor.config.verbose
  connection.put do |req|
    req.url url
    req.headers['Content-Type'] = ( args[:headers] && args[:headers]['Content-Type'] || 'application/json' )
    req.body = args[:body] if args[:body]
  end
rescue Faraday::ParsingError
  Struct.new(:status, :body).new(500, 'Conductor::Connection : Faraday failed to properly parse response.')
end