Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #12 from benekastah/master

HTTP module: Adds payload as query string in GET requests
  • Loading branch information...
commit 08d6b85f561d4c5a5b8cd6692ae4b366f7c2515d 2 parents 28e8749 + d76c2cc
@mattetti mattetti authored
Showing with 11 additions and 3 deletions.
  1. +11 −3 lib/http.rb
View
14 lib/http.rb
@@ -112,6 +112,7 @@ def initialize(url, http_method = :get, options={})
@payload = options.delete(:payload)
@credentials = options.delete(:credentials) || {}
@credentials = {:username => '', :password => ''}.merge(@credentials)
+ @timeout = options.delete(:timeout) || 30.0
headers = options.delete(:headers)
if headers
@headers = {}
@@ -127,17 +128,24 @@ def initialize(url, http_method = :get, options={})
def initiate_request(url_string)
# http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/nsrunloop_Class/Reference/Reference.html#//apple_ref/doc/constant_group/Run_Loop_Modes
# NSConnectionReplyMode
+
+ unless @payload.nil?
+ @payload = @payload.map{|k,v| "#{k}=#{v}"}.join('&') if @payload.is_a?(Hash)
+ if @method == "GET"
+ url_string = "#{url_string}?#{@payload}"
+ end
+ end
+
p "HTTP building a NSRequest for #{url_string}"# if SETTINGS[:debug]
@url = NSURL.URLWithString(url_string)
@request = NSMutableURLRequest.requestWithURL(@url,
cachePolicy:NSURLRequestUseProtocolCachePolicy,
- timeoutInterval:30.0)
+ timeoutInterval:@timeout)
@request.setHTTPMethod @method
@request.setAllHTTPHeaderFields(@headers) if @headers
# @payload needs to be converted to data
- unless method == :get || @payload.nil?
- @payload = @payload.map{|k,v| "#{k}=#{v}"}.join('&') if @payload.is_a?(Hash)
+ unless @method == "GET" || @payload.nil?
@payload = @payload.to_s.dataUsingEncoding(NSUTF8StringEncoding)
@request.setHTTPBody @payload
end
Please sign in to comment.
Something went wrong with that request. Please try again.