Sha256: 87d52509fe82f483c847774b1796897147905a32b6b2dd0d6939dfad377a1e2e

Contents?: true

Size: 1.34 KB

Versions: 3

Compression:

Stored size: 1.34 KB

Contents

require "alephant/logger"

module Alephant
  module Publisher
    module Request
      class Connection
        include Logger
        attr_reader :driver

        def initialize(driver)
          @driver = driver
        end

        def get(uri)
          before   = Time.new
          response = driver.get(uri)
          logger.metric(:name => "PublisherRequestDataMapperRequestHTTPTime", :unit => 'Seconds', :value => Time.new - before)
          raise InvalidApiStatus, response.status unless response.status == 200
          JSON::parse(response.body, :symbolize_names => true)
        rescue Faraday::ConnectionFailed
          logger.metric(:name => "PublisherRequestDataMapperConnectionFailed", :unit => "Count", :value => 1)
          raise ConnectionFailed
        rescue JSON::ParserError
          logger.metric(:name => "PublisherRequestDataMapperInvalidApiResponse", :unit => "Count", :value => 1)
          raise InvalidApiResponse, "JSON parsing error: #{response.body}"
        rescue InvalidApiStatus => e
          logger.metric(:name => "PublisherRequestDataMapperInvalidStatus#{e.status}", :unit => "Count", :value => 1)
          raise e
        rescue StandardError => e
          logger.metric(:name => "PublisherRequestDataMapperApiError", :unit => "Count", :value => 1)
          raise ApiError, e.message
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
alephant-publisher-request-0.2.2 lib/alephant/publisher/request/connection.rb
alephant-publisher-request-0.2.1 lib/alephant/publisher/request/connection.rb
alephant-publisher-request-0.2.0 lib/alephant/publisher/request/connection.rb