class Gupshup::Request

Attributes

auth[R]
data[R]
headers[R]
host[R]
method[R]
params[R]
port[R]
timeout[R]
url[R]

Public Class Methods

new(host, port, method, url, params = {}, data = {}, headers = {}, auth = nil, timeout = nil) click to toggle source
# File lib/gupshup_whatsapp/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

Public Instance Methods

to_s() click to toggle source
# File lib/gupshup_whatsapp/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 += @data.each.map { |key, value| "-d \"#{key}\"=\"#{value}\"" }.join("\n")
  end
  "#{auth} #{@method} #{@url}#{params}#{data}#{headers}"
end