Sha256: 44c02af722e708a0f61b2a9747dd6a32d1b357b28a955f6221d1a637f25fc3d6

Contents?: true

Size: 910 Bytes

Versions: 12

Compression:

Stored size: 910 Bytes

Contents

require 'faraday'

class Dataset::Adaptors::Iqvoc::HTTPAdaptor
  attr_reader :url

  def initialize(url)
    @url = url
    @conn = Faraday.new(url: url) do |conn|
      #conn.use Faraday::Response::Logger if Rails.env.development?
      conn.adapter Faraday.default_adapter
    end
  end

  def http_get(path, redirect_count = 0)
    begin
      response = @conn.get(path)
    rescue Faraday::Error::ConnectionFailed,
        Faraday::Error::ResourceNotFound,
        Faraday::Error::TimeoutError => e
      return failed_request(path)
    end

    if response.status == 404
      return failed_request(path)
    end

    if response.status == 302 && redirect_count < 3
      response = http_get(response.headers['location'], redirect_count + 1)
    end

    response
  end

  private
  def failed_request(path)
    Rails.logger.warn "HTTP error while querying remote source #{path}"
    return nil
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
iqvoc-4.10.0 app/models/dataset/adaptors/iqvoc/http_adaptor.rb
iqvoc-4.9.0 app/models/dataset/adaptors/iqvoc/http_adaptor.rb
iqvoc-4.8.2 app/models/dataset/adaptors/iqvoc/http_adaptor.rb
iqvoc-4.8.1 app/models/dataset/adaptors/iqvoc/http_adaptor.rb
iqvoc-4.8.0 app/models/dataset/adaptors/iqvoc/http_adaptor.rb
iqvoc-4.7.0 app/models/dataset/adaptors/iqvoc/http_adaptor.rb
iqvoc-4.6.1 app/models/dataset/adaptors/iqvoc/http_adaptor.rb
iqvoc-4.5.2 app/models/dataset/adaptors/iqvoc/http_adaptor.rb
iqvoc-4.6.0 app/models/dataset/adaptors/iqvoc/http_adaptor.rb
iqvoc-4.5.1 app/models/dataset/adaptors/iqvoc/http_adaptor.rb
iqvoc-4.5.0 app/models/dataset/adaptors/iqvoc/http_adaptor.rb
iqvoc-4.4.0 app/models/dataset/adaptors/iqvoc/http_adaptor.rb