Added v 0.3.1 snapshot.
[twitter4r-core.git] / lib / twitter / client / auth.rb
blobcbc858c207ed481095fb3b42b9c4cbd04c7be86b
1 class Twitter::Client
2   @@AUTHENTICATION_URIS = {
3     :verify => '/account/verify_credentials',
4   }
5   
6         # Provides access to the Twitter verify credentials API.
7         # 
8         # You can verify Twitter user credentials with minimal overhead using this method.
9   # 
10         # Example:
11         #  client.authenticate?("osxisforlightweights", "l30p@rd_s^cks!")
12         def authenticate?(login, password)
13     verify_credentials(login, password)
14         end
15         
16 private
17   def verify_credentials(username, passwd)
18         connection = create_http_connection
19         connection.start do |connection|
20           request = create_http_get_request("#{@@AUTHENTICATION_URIS[:verify]}.json")
21                 request.basic_auth(username, passwd)
22                 response = connection.request(request)
23                 response.is_a?(Net::HTTPSuccess) ? true : false
24     end
25   end
26 end