Class: Twilio::Request
- Inherits:
-
Object
- Object
- Twilio::Request
- Defined in:
- lib/twilio-ruby/framework/request.rb
Instance Attribute Summary collapse
-
#auth ⇒ Object
readonly
Returns the value of attribute auth.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(host, port, method, url, params = {}, data = {}, headers = {}, auth = nil, timeout = nil) ⇒ Request
constructor
A new instance of Request.
- #to_s ⇒ Object
Constructor Details
#initialize(host, port, method, url, params = {}, data = {}, headers = {}, auth = nil, timeout = nil) ⇒ Request
Returns a new instance of Request.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/twilio-ruby/framework/request.rb', line 7 def initialize(host, port, method, url, params = {}, data = {}, headers = {}, auth = nil, timeout = nil) @host = host @port = port @url = url @method = method @params = params @data = data @headers = headers @auth = auth @timeout = timeout end |
Instance Attribute Details
#auth ⇒ Object (readonly)
Returns the value of attribute auth.
5 6 7 |
# File 'lib/twilio-ruby/framework/request.rb', line 5 def auth @auth end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
5 6 7 |
# File 'lib/twilio-ruby/framework/request.rb', line 5 def data @data end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
5 6 7 |
# File 'lib/twilio-ruby/framework/request.rb', line 5 def headers @headers end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
5 6 7 |
# File 'lib/twilio-ruby/framework/request.rb', line 5 def host @host end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
5 6 7 |
# File 'lib/twilio-ruby/framework/request.rb', line 5 def method @method end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
5 6 7 |
# File 'lib/twilio-ruby/framework/request.rb', line 5 def params @params end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
5 6 7 |
# File 'lib/twilio-ruby/framework/request.rb', line 5 def port @port end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
5 6 7 |
# File 'lib/twilio-ruby/framework/request.rb', line 5 def timeout @timeout end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
5 6 7 |
# File 'lib/twilio-ruby/framework/request.rb', line 5 def url @url end |
Instance Method Details
#to_s ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/twilio-ruby/framework/request.rb', line 19 def to_s auth = @auth.nil? ? '' : '(' + @auth.join(',') + ')' params = '' unless @params.nil? || @params.empty? params = '?' + @params.each.map { |key, value| "#{CGI.escape(key)}=#{CGI.escape(value)}" }.join('&') end headers = '' unless @headers.nil? || @headers.empty? headers = "\n" + @headers.each.map { |key, value| "-H \"#{key}\": \"#{value}\"" }.join("\n") end data = '' unless @data.nil? || @data.empty? data = @method.equal?('GET') ? "\n -G" : "\n" data += case @headers['Content-Type'] when 'application/x-www-form-urlencoded' @data.each.map { |key, value| "-d \"#{key}\"=\"#{value}\"" }.join("\n") when 'application/json' "-d '#{JSON.generate(@data)}'" else @data.each.map { |key, value| "-d \"#{key}\"=\"#{value}\"" }.join("\n") end end "#{auth} #{@method} #{@url}#{params}#{data}#{headers}" end |