Class: PollEverywhere::HTTP::Request

Inherits:
Struct
  • Object
show all
Defined in:
lib/polleverywhere/http.rb

Overview

Simple HTTP request/response objects for our adapter and DSL

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bodyObject

Returns the value of attribute body

Returns:

  • (Object)

    the current value of body



12
13
14
# File 'lib/polleverywhere/http.rb', line 12

def body
  @body
end

#headersObject

Returns the value of attribute headers

Returns:

  • (Object)

    the current value of headers



12
13
14
# File 'lib/polleverywhere/http.rb', line 12

def headers
  @headers
end

#methodObject

Returns the value of attribute method

Returns:

  • (Object)

    the current value of method



12
13
14
# File 'lib/polleverywhere/http.rb', line 12

def method
  @method
end

#urlObject

Returns the value of attribute url

Returns:

  • (Object)

    the current value of url



12
13
14
# File 'lib/polleverywhere/http.rb', line 12

def url
  @url
end

Instance Method Details

#to_curlObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/polleverywhere/http.rb', line 13

def to_curl
  case method.to_s
  when /^put|post$/i
    %(curl -X #{method.to_s.upcase} #{headers.map{|h,v| %(-H "#{h}: #{v}")}.join(" ")} -d "#{body.gsub(/[!"`'\n]/){|m| "\\#{m}" }}" "#{url}")
  when /^get$/i
    %(curl #{headers.map{|h,v| %(-H "#{h}: #{v}")}.join(" ")} "#{url}")
  else
    %(curl -X #{method.to_s.upcase} #{headers.map{|h,v| %(-H "#{h}: #{v}")}.join(" ")} "#{url}")
  end
end