Sha256: 2a81656a41ffe58c36fc90bce8b6fd1044c8cd3a945004a51efe91f04a717843

Contents?: true

Size: 1.45 KB

Versions: 19

Compression:

Stored size: 1.45 KB

Contents

require 'faraday'

module Twilio
  module HTTP
    class Client
      attr_accessor :adapter

      def initialize(proxy_addr=nil, proxy_port=nil, proxy_user=nil, proxy_pass=nil, ssl_ca_file=nil)
        @proxy_addr = proxy_addr
        @proxy_port = proxy_port
        @proxy_user = proxy_user
        @proxy_pass = proxy_pass
        @ssl_ca_file = ssl_ca_file
        @adapter = Faraday.default_adapter

        # Set default params encoder
        Faraday::Utils.default_params_encoder = Faraday::FlatParamsEncoder
      end

      def request(host, port, method, url, params={}, data={}, headers={}, auth=nil, timeout=nil)
        @connection = Faraday.new(url: host + ":" + port.to_s, ssl: {verify: true}) do |f|
          f.request :url_encoded
          f.adapter @adapter
          f.headers = headers
          f.basic_auth(auth[0], auth[1])
          if @proxy_addr
            f.proxy "#{@proxy_user}:#{@proxy_pass}@#{@proxy_addr}:#{@proxy_port}"
          end
          f.options.open_timeout = timeout
          f.options.timeout = timeout
        end

        response = @connection.send(method.downcase.to_sym, url, method == 'GET' ? params : data)

        @last_response = response
        if response.body and !response.body.empty?
          object = response.body
        elsif response.status == 400
          object = { message: 'Bad request', code: 400 }.to_json
        end

        TwilioResponse.new(response.status, object)
      end
    end

  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
twilio-ruby-5.0.0.rc26 lib/twilio-ruby/http/http_client.rb
twilio-ruby-5.0.0.rc25 lib/twilio-ruby/http/http_client.rb
twilio-ruby-5.0.0.rc24 lib/twilio-ruby/http/http_client.rb
twilio-ruby-5.0.0.rc23 lib/twilio-ruby/http/http_client.rb
twilio-ruby-5.0.0.rc22 lib/twilio-ruby/http/http_client.rb
twilio-ruby-5.0.0.rc21 lib/twilio-ruby/http/http_client.rb
twilio-ruby-5.0.0.rc19 lib/twilio-ruby/http/http_client.rb
twilio-ruby-5.0.0.rc18 lib/twilio-ruby/http/http_client.rb
twilio-ruby-5.0.0.rc17 lib/twilio-ruby/http/http_client.rb
twilio-ruby-5.0.0.rc16 lib/twilio-ruby/http/http_client.rb
twilio-ruby-5.0.0.rc15 lib/twilio-ruby/http/http_client.rb
twilio-ruby-5.0.0.rc14 lib/twilio-ruby/http/http_client.rb
twilio-ruby-5.0.0.rc13 lib/twilio-ruby/http/http_client.rb
twilio-ruby-5.0.0.rc12 lib/twilio-ruby/http/http_client.rb
twilio-ruby-5.0.0.rc11 lib/twilio-ruby/http/http_client.rb
twilio-ruby-5.0.0.rc10 lib/twilio-ruby/http/http_client.rb
twilio-ruby-5.0.0.rc9 lib/twilio-ruby/http/http_client.rb
twilio-ruby-5.0.0.rc8 lib/twilio-ruby/http/http_client.rb
twilio-ruby-5.0.0.rc7 lib/twilio-ruby/http/http_client.rb