Class: Facebooker::Service::CurlService
Instance Method Summary
collapse
Methods inherited from BaseService
#parse_results?, #post_params
Instance Method Details
#multipart_post_file?(object) ⇒ Boolean
Net::HTTP::MultipartPostFile
18
19
20
21
22
|
# File 'lib/facebooker/service/curl_service.rb', line 18
def multipart_post_file?(object)
object.respond_to?(:content_type) &&
object.respond_to?(:data) &&
object.respond_to?(:filename)
end
|
#post_form(url, params, multipart = false) ⇒ Object
4
5
6
7
8
9
10
11
|
# File 'lib/facebooker/service/curl_service.rb', line 4
def post_form(url,params,multipart=false)
curl = Curl::Easy.new(url.to_s) do |c|
c.multipart_form_post = multipart
c.timeout = Facebooker.timeout
end
curl.http_post(*to_curb_params(params))
curl.body_str
end
|
#post_multipart_form(url, params) ⇒ Object
13
14
15
|
# File 'lib/facebooker/service/curl_service.rb', line 13
def post_multipart_form(url,params)
post_form(url,params,true)
end
|
#to_curb_params(params) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/facebooker/service/curl_service.rb', line 24
def to_curb_params(params)
parray = []
params.each_pair do |k,v|
if multipart_post_file?(v)
field = Curl::PostField.file((k.blank? ? 'xxx' : k.to_s), nil, File.basename(v.filename))
field.content_type = v.content_type
field.content = v.data
parray << field
else
parray << Curl::PostField.content(
k.to_s,
(Array === v || Hash===v) ? Facebooker.json_encode(v) : v.to_s
)
end
end
parray
end
|