Class: TwitterDispatch::Proxy::Basic
- Inherits:
-
Object
- Object
- TwitterDispatch::Proxy::Basic
show all
- Includes:
- Shared
- Defined in:
- lib/twitter_dispatch/proxy/basic.rb
Direct Known Subclasses
None
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Shared
#append_extension_to, #handle_response
Constructor Details
#initialize(dispatcher) ⇒ Basic
Returns a new instance of Basic.
10
11
12
|
# File 'lib/twitter_dispatch/proxy/basic.rb', line 10
def initialize(dispatcher)
self.dispatcher = dispatcher
end
|
Instance Attribute Details
#dispatcher ⇒ Object
Returns the value of attribute dispatcher.
8
9
10
|
# File 'lib/twitter_dispatch/proxy/basic.rb', line 8
def dispatcher
@dispatcher
end
|
Instance Method Details
#delete(path, *arguments) ⇒ Object
40
41
42
|
# File 'lib/twitter_dispatch/proxy/basic.rb', line 40
def delete(path, *arguments)
request(:delete, path, *arguments)
end
|
#get(path, *arguments) ⇒ Object
28
29
30
|
# File 'lib/twitter_dispatch/proxy/basic.rb', line 28
def get(path, *arguments)
request(:get, path, *arguments)
end
|
#post(path, body = '', *arguments) ⇒ Object
32
33
34
|
# File 'lib/twitter_dispatch/proxy/basic.rb', line 32
def post(path, body='', *arguments)
request(:post, path, body, *arguments)
end
|
#put(path, body = '', *arguments) ⇒ Object
36
37
38
|
# File 'lib/twitter_dispatch/proxy/basic.rb', line 36
def put(path, body='', *arguments)
request(:put, path, body, *arguments)
end
|
#request(http_method, path, body = nil, *arguments) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/twitter_dispatch/proxy/basic.rb', line 14
def request(http_method, path, body=nil, *arguments)
path = dispatcher.path_prefix + path
path = append_extension_to(path)
response = dispatcher.net.start{ |http|
req = eval("Net::HTTP::#{http_method.to_s.capitalize}").new(path, *arguments)
req.basic_auth dispatcher.screen_name, dispatcher.password if dispatcher.basic?
req.set_form_data(body) unless body.nil?
http.request(req)
}
handle_response(response)
end
|