Sha256: e5781abaca6d5ce97d9da7f78a56981aed8a10cdbf15453e1555ea40800cc93a

Contents?: true

Size: 1.23 KB

Versions: 6

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

require 'faraday'

module Geminabox

  class TemplateFaradayAdapter < HttpAdapter

    def get(*args)
      adapter.get(*args)
    end

    def get_content(*args)
      response = adapter.get(*args)
      response.body
    end

    def post(*args)
      adapter.post(*args)
    end

    # Note that this configuration turns SSL certificate verification off.
    # To set up the adapter for your environment see:
    # https://github.com/lostisland/faraday/wiki/Setting-up-SSL-certificates
    def set_auth(uri, username = nil, password = nil)
      connection = Faraday.new url: uri, ssl: {verify: false} do |faraday|
        faraday.adapter http_engine
        faraday.proxy(ENV['http_proxy']) if ENV['http_proxy']
      end
      connection.basic_auth username, password if username
      connection
    end

    def adapter
      @adapter ||= Faraday.new do |faraday|
        faraday.adapter http_engine
        faraday.proxy(ENV['http_proxy']) if ENV['http_proxy']
      end
    end

    def http_engine
      :net_http  # make requests with Net::HTTP
    end

    def options
      lambda {|faraday|
        faraday.adapter http_engine
        faraday.proxy(ENV['http_proxy']) if ENV['http_proxy']
      }
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
geminabox-2.0.0 lib/geminabox/http_adapter/template_faraday_adapter.rb
geminabox-2.0.0.rc.1 lib/geminabox/http_adapter/template_faraday_adapter.rb
geminabox-1.5.0 lib/geminabox/http_adapter/template_faraday_adapter.rb
geminabox-1.5.0.rc.1 lib/geminabox/http_adapter/template_faraday_adapter.rb
geminabox-1.4.3 lib/geminabox/http_adapter/template_faraday_adapter.rb
geminabox-1.4.3.rc lib/geminabox/http_adapter/template_faraday_adapter.rb