12
13
14
15
16
17
18
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/afmotion/patch/NSURLRequest_params.rb', line 12
def parameters=(params = {})
method = self.HTTPMethod
af_encoding = params[:__encoding__] || AFFormURLParameterEncoding
string_encoding = params[:__string_encoding__] || NSUTF8StringEncoding
params.delete :__encoding__
params.delete :__string_encoding__
if ["GET", "HEAD", "DELETE", "PUT"].member? method
url_string = String.new(self.url.absoluteString)
has_query = url_string.rangeOfString("?").location == NSNotFound
format = has_query ? "?" : "&"
encoded = AFQueryStringFromParametersWithEncoding(params, string_encoding)
self.url = (url_string << format) << encoded
else
charset = CFStringConvertEncodingToIANACharSetName(CFStringConvertNSStringEncodingToEncoding(string_encoding))
error = Pointer.new(:object)
case af_encoding
when AFFormURLParameterEncoding
self.content_type = "application/x-www-form-urlencoded; charset=%@" << charset
self.HTTPBody = AFQueryStringFromParametersWithEncoding(params, string_encoding).dataUsingEncoding(string_encoding)
when AFJSONParameterEncoding
self.content_type = "application/json; charset=%@" << charset
self.HTTPBody = NSJSONSerialization.dataWithJSONObject(params, options: 0, error: error)
when AFPropertyListParameterEncoding
self.content_type = "application/x-plist; charset=%@" << charset
self.HTTPBody = NSPropertyListSerialization.dataWithPropertyList(params, format: NSPropertyListXMLFormat_v1_0, options: 0, error: error)
end
if error[0]
p "NSURLRequest #{self.inspect}#parameters=#{params.inspect} ERROR: #{error.localizedDescription}"
end
end
end
|