Module: CurbFu::Request::Base
Instance Method Summary
collapse
Methods included from Common
#build_url, #timeout, #timeout=
Instance Method Details
#build(url_params, query_params = {}) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/curb-fu/request/base.rb', line 6
def build(url_params, query_params = {})
curb = Curl::Easy.new(build_url(url_params, query_params))
unless url_params.is_a?(String)
curb.userpwd = "#{url_params[:username]}:#{url_params[:password]}" if url_params[:username]
if url_params[:authtype]
curb.http_auth_types = url_params[:authtype]
elsif url_params[:username]
curb.http_auth_types = CurbFu::Authentication::BASIC
end
curb. = url_params[:headers] || {}
end
curb.timeout = @timeout
curb
end
|
#get(url, params = {}) ⇒ Object
24
25
26
27
28
|
# File 'lib/curb-fu/request/base.rb', line 24
def get(url, params = {})
curb = self.build(url, params)
curb.http_get
CurbFu::Response::Base.from_curb_response(curb)
end
|
#post(url, params = {}) ⇒ Object
38
39
40
41
42
43
44
45
|
# File 'lib/curb-fu/request/base.rb', line 38
def post(url, params = {})
fields = create_post_fields(params)
curb = self.build(url)
curb.["Expect:"] = ''
curb.http_post(*fields)
CurbFu::Response::Base.from_curb_response(curb)
end
|
#post_file(url, params = {}, filez = {}) ⇒ Object
47
48
49
50
51
52
53
54
55
|
# File 'lib/curb-fu/request/base.rb', line 47
def post_file(url, params = {}, filez = {})
fields = create_post_fields(params)
fields += create_file_fields(filez)
curb = self.build(url)
curb.multipart_form_post = true
curb.http_post(*fields)
CurbFu::Response::Base.from_curb_response(curb)
end
|
#put(url, params = {}) ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/curb-fu/request/base.rb', line 30
def put(url, params = {})
fields = create_put_fields(params)
curb = self.build(url)
curb.http_put(fields)
CurbFu::Response::Base.from_curb_response(curb)
end
|