Class: TwitterAuth::Dispatcher::Basic
- Inherits:
-
Object
- Object
- TwitterAuth::Dispatcher::Basic
show all
- Includes:
- Shared
- Defined in:
- lib/twitter_auth/dispatcher/basic.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Shared
#append_extension_to, #handle_response, #post!
Constructor Details
#initialize(user) ⇒ Basic
Returns a new instance of Basic.
10
11
12
13
|
# File 'lib/twitter_auth/dispatcher/basic.rb', line 10
def initialize(user)
raise TwitterAuth::Error, 'Dispatcher must be initialized with a User.' unless user.is_a?(TwitterAuth::BasicUser)
self.user = user
end
|
Instance Attribute Details
#user ⇒ Object
Returns the value of attribute user.
8
9
10
|
# File 'lib/twitter_auth/dispatcher/basic.rb', line 8
def user
@user
end
|
Instance Method Details
#delete(path, *arguments) ⇒ Object
41
42
43
|
# File 'lib/twitter_auth/dispatcher/basic.rb', line 41
def delete(path, *arguments)
request(:delete, path, *arguments)
end
|
#get(path, *arguments) ⇒ Object
29
30
31
|
# File 'lib/twitter_auth/dispatcher/basic.rb', line 29
def get(path, *arguments)
request(:get, path, *arguments)
end
|
#post(path, body = '', *arguments) ⇒ Object
33
34
35
|
# File 'lib/twitter_auth/dispatcher/basic.rb', line 33
def post(path, body='', *arguments)
request(:post, path, body, *arguments)
end
|
#put(path, body = '', *arguments) ⇒ Object
37
38
39
|
# File 'lib/twitter_auth/dispatcher/basic.rb', line 37
def put(path, body='', *arguments)
request(:put, path, body, *arguments)
end
|
#request(http_method, path, body = nil, *arguments) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/twitter_auth/dispatcher/basic.rb', line 15
def request(http_method, path, body=nil, *arguments)
path = TwitterAuth.path_prefix + path
path = append_extension_to(path)
response = TwitterAuth.net.start{ |http|
req = "Net::HTTP::#{http_method.to_s.capitalize}".constantize.new(path, *arguments)
req.basic_auth user.login, user.password
req.set_form_data(body) unless body.nil?
http.request(req)
}
handle_response(response)
end
|