Sha256: a3f65bcea96e8715148d042e80721ff7e0c50f065e48a57424d26e42aec45cc1

Contents?: true

Size: 1.09 KB

Versions: 15

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

module Gupshup
  class Request
  attr_reader :host, :port, :method, :url, :params, :data, :headers, :auth, :timeout

  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

  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
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
gupshup_whatsapp-1.0.7 lib/gupshup_whatsapp/framework/request.rb
gupshup_whatsapp-1.0.6 lib/gupshup_whatsapp/framework/request.rb
gupshup_whatsapp-1.0.5 lib/gupshup_whatsapp/framework/request.rb
gupshup_whatsapp-1.0.4 lib/gupshup_whatsapp/framework/request.rb
gupshup_whatsapp-1.0.3 lib/gupshup_whatsapp/framework/request.rb
gupshup-rb-0.2.1 lib/gupshup-rb/framework/request.rb
gupshup-rb-0.2.0 lib/gupshup-rb/framework/request.rb
gupshup-rb-0.1.9 lib/gupshup-rb/framework/request.rb
gupshup_whatsapp-1.0.2 lib/gupshup_whatsapp/framework/request.rb
gupshup_whatsapp-1.0.1 lib/gupshup_whatsapp/framework/request.rb
gupshup_whatsapp-1.0.0 lib/gupshup_whatsapp/framework/request.rb
gupshup_whatsapp-0.2.5 lib/gupshup_whatsapp/framework/request.rb
gupshup_whatsapp-0.2.3 lib/gupshup_whatsapp/framework/request.rb
gupshup_whatsapp-0.2.1 lib/gupshup_whatsapp/framework/request.rb
gupshup_whatsapp-0.2.0 lib/gupshup_whatsapp/framework/request.rb