/
request.rb
44 lines (38 loc) · 1.08 KB
/
request.rb
1
2
3
4
5
6
7
8
9
10
11
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
module Twitter
# Defines HTTP request methods
module Request
# Perform an HTTP GET request
def get(path, options={}, raw=false)
request(:get, path, options, raw)
end
# Perform an HTTP POST request
def post(path, options={}, raw=false)
request(:post, path, options, raw)
end
# Perform an HTTP PUT request
def put(path, options={}, raw=false)
request(:put, path, options, raw)
end
# Perform an HTTP DELETE request
def delete(path, options={}, raw=false)
request(:delete, path, options, raw)
end
private
# Perform an HTTP request
def request(method, path, options, raw=false)
response = connection(raw).send(method) do |request|
case method
when :get, :delete
request.url(formatted_path(path), options)
when :post, :put
request.path = formatted_path(path)
request.body = options unless options.empty?
end
end
raw ? response : response.body
end
def formatted_path(path)
[path, format].compact.join('.')
end
end
end