Class: Twilio::HTTP::Client
- Inherits:
-
Object
- Object
- Twilio::HTTP::Client
- Defined in:
- lib/twilio-ruby/http/http_client.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
Returns the value of attribute adapter.
Instance Method Summary collapse
-
#initialize(proxy_addr = nil, proxy_port = nil, proxy_user = nil, proxy_pass = nil, ssl_ca_file = nil) ⇒ Client
constructor
A new instance of Client.
- #request(host, port, method, url, params = {}, data = {}, headers = {}, auth = nil, timeout = nil) ⇒ Object
Constructor Details
#initialize(proxy_addr = nil, proxy_port = nil, proxy_user = nil, proxy_pass = nil, ssl_ca_file = nil) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 14 15 |
# File 'lib/twilio-ruby/http/http_client.rb', line 8 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 end |
Instance Attribute Details
#adapter ⇒ Object
Returns the value of attribute adapter.
6 7 8 |
# File 'lib/twilio-ruby/http/http_client.rb', line 6 def adapter @adapter end |
Instance Method Details
#request(host, port, method, url, params = {}, data = {}, headers = {}, auth = nil, timeout = nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/twilio-ruby/http/http_client.rb', line 17 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..params_encoder = Faraday::FlatParamsEncoder 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..open_timeout = timeout f..timeout = timeout end response = @connection.send(method.downcase.to_sym, url, method == 'GET' ? params : data) @last_response = response if response.body && !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 |