Sha256: 85ce658369fc4c3731591165e3d392e9d3f464093b8e3fb3ca42d447a42474f3

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

require 'faraday'
require 'faraday_middleware'
require 'faraday/conductivity'
require 'delegate'

module NewRelic
  module RestApi
    class Connection < SimpleDelegator
      def initialize
        require 'logger'
        @raw_connection = Faraday.new(http_options) do |faraday|
          faraday.request :json
          faraday.request :retry, max: config.retries
          faraday.request :user_agent,
                          app: 'NewRelic::RestApi gem',
                          version: NewRelic::RestApi::VERSION
          #faraday.response :logger, ::Logger.new(STDOUT), bodies: true
          faraday.response :json
          faraday.response :raise_error
          faraday.adapter Faraday.default_adapter
        end

        super(@raw_connection)
      end

      private

      def http_options
        options = {
          url: config.host,
          request: {
            timeout: config.timeout,
            open_timeout: config.open_timeout
          },
          headers: {
            'X-Api-Key' => config.key
          }
        }
        options[:ssl] = config.ssl_options unless config.ssl_options.empty?
        options
      end

      def config
        NewRelic::RestApi.config
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
new_relic-rest_api-0.1.0 lib/new_relic/rest_api/connection.rb