twitter_oauth-0.4.94/0000755000004100000410000000000012203704153014537 5ustar www-datawww-datatwitter_oauth-0.4.94/README.textile0000644000004100000410000001245112203704153017077 0ustar www-datawww-datah1. Twitter OAuth REST API client library for Ruby h2. Current Status Twitter turned off access to the v1 API so this project is currently migrating to v1.1. Unfortunately everything is not backward-compatible. The v.0.4.9x series of this gem is work in progress getting the library compatible with Twitter v1.1 - when complete we will push v0.5.0 of this library. h2. Install the gem gem 'twitter_oauth' h2. Using the gem To make authorized requests with the client library you'll need to "create a Twitter OAuth Application":http://twitter.com/oauth_clients/new. See "sinitter":http://github.com/moomerman/sinitter/tree/master for a full website integration example. h2. Unauthorized request example Since Twitter API v1.1 all requests are required to be authorized. h2. Authorized request example To use the full power of the Twitter API you need to authorize your application and a valid Twitter user via OAuth. An example showing how to update the status of an authorized user is below. Firstly we need to create an instance of the client with your application client credentials you have been given by Twitter when you set up your application.
client = TwitterOAuth::Client.new(
    :consumer_key => 'YOUR_APP_CONSUMER_KEY',
    :consumer_secret => 'YOUR_APP_CONSUMER_SECRET'
)
request_token = client.request_token(:oauth_callback => oauth_confirm_url)
#:oauth_callback required for web apps, since oauth gem by default force PIN-based flow
#( see http://groups.google.com/group/twitter-development-talk/browse_thread/thread/472500cfe9e7cdb9/848f834227d3e64d )


request_token.authorize_url
=> http://twitter.com/oauth/authorize?oauth_token=TOKEN
In your application your user would be redirected to Twitter to authorize the application at this point. You'll need to store the request token (usually in the session) for later. The code continues below assuming the user has authorized your application. NOTE: Above we called the client.request_token(...) method, this authorizes the application on every call. You can also use the client.authentication_request_token(...) method which automatically redirects back to your application if the user has previously authorized the app.
access_token = client.authorize(
  request_token.token,
  request_token.secret,
  :oauth_verifier => params[:oauth_verifier]
)

client.authorized?
=> true

client.update('checking out the twitter_oauth library') # sends a twitter status update
Now if you keep hold of the access_token (usually in the database) for this user you won't need to re-authorize them next time. When you create an instance of the client you can just pass in the access token and secret that you have stored.
access_token = @user.access_token # assuming @user
client = TwitterOAuth::Client.new(
    :consumer_key => 'YOUR_CONSUMER_KEY',
    :consumer_secret => 'YOUR_APP_CONSUMER_SECRET',
    :token => access_token.token,
    :secret => access_token.secret
)

client.authorized?
=> true
h2. PIN-based flow If you're writing a command line application or desktop app, you will probably want to use the PIN-based authorization method rather than the website redirect method.
client = TwitterOAuth::Client.new(
  :consumer_key => 'YOUR_CONSUMER_KEY',
  :consumer_secret => 'YOUR_APP_CONSUMER_SECRET'
)

request_token = client.authentication_request_token(
  :oauth_callback => 'oob'
)

puts request_token.authorize_url

print 'Please visit the URL and enter the code: '
code = gets.strip

access_token = client.authorize(
  request_token.token,
  request_token.secret,
  :oauth_verifier => code
)

client.authorized?
=> true
The special oauth callback value of oob tells Twitter you want to do the PIN-based authentication. The user goes to the authorization URL to get their unique code and they paste that into your application. Finally we authorize the user with this code. h2. Working with a Proxy Services such as "Apigee Analytics and API Management":http://apigee.com/ require you to proxy your API requests through their servers. The workflow is as follows. First you need to authorize the Twitter user via OAuth directly via the Twitter API (this part cannot be proxied)
client = TwitterOAuth::Client.new(
    :consumer_key => 'YOUR_APP_CONSUMER_KEY',
    :consumer_secret => 'YOURA_APP_CONSUMER_SECRET'
)
request_token = client.request_token(:oauth_callback => 'YOUR_CALLBACK_URL')

request_token.authorize_url
=> http://twitter.com/oauth/authorize?oauth_token=TOKEN
The user is sent to Twitter to allow the application to access their account and then you need to obtain the access token for the user
access_token = client.authorize(
  request_token.token,
  request_token.secret,
  :oauth_verifier => params[:oauth_verifier]
)

client.authorized?
=> true
Now you can make all further API calls through the proxy of your choice:
access_token = @user.access_token # assuming @user
client = TwitterOAuth::Client.new(
    :proxy => 'http://XXX.YYY.apigee.com',
    :consumer_key => 'YOUR_CONSUMER_KEY',
    :consumer_secret => 'YOUR-CONSUMER-SECRET',
    :token => access_token.token,
    :secret => access_token.secret
)

client.authorized?
=> true

client.update('Proxy via Apigee is working')
twitter_oauth-0.4.94/LICENSE0000644000004100000410000000203512203704153015544 0ustar www-datawww-dataCopyright (c) Richard Taylor Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. twitter_oauth-0.4.94/checksums.yaml.gz0000444000004100000410000000041412203704153020024 0ustar www-datawww-dataQe9V0 "OeQRqzLJ8hv]^~^?#+}FUcbP{Uj}'ȯ'c읪.$.TkF _ rƈäX,q[o4 N2i1{e LEDP5>jOrSDcDK "`E3w# SVeT:L JA=9Yd)!eIP]kG6zA(U;@xtwitter_oauth-0.4.94/metadata.yml0000644000004100000410000000657412203704153017056 0ustar www-datawww-data--- !ruby/object:Gem::Specification name: twitter_oauth version: !ruby/object:Gem::Version version: 0.4.94 platform: ruby authors: - Richard Taylor autorequire: bindir: bin cert_chain: [] date: 2013-06-12 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: oauth requirement: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: 0.4.7 type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: 0.4.7 - !ruby/object:Gem::Dependency name: json requirement: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: 1.8.0 type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: 1.8.0 - !ruby/object:Gem::Dependency name: mime-types requirement: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: '1.16' type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: '1.16' - !ruby/object:Gem::Dependency name: shoulda requirement: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: mocha requirement: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: '0' description: twitter_oauth is a Ruby client for the Twitter API using OAuth. email: moomerman@gmail.com executables: [] extensions: [] extra_rdoc_files: [] files: - LICENSE - README.textile - lib/twitter_oauth.rb - lib/twitter_oauth/account.rb - lib/twitter_oauth/blocks.rb - lib/twitter_oauth/client.rb - lib/twitter_oauth/direct_messages.rb - lib/twitter_oauth/favorites.rb - lib/twitter_oauth/friendships.rb - lib/twitter_oauth/geo.rb - lib/twitter_oauth/help.rb - lib/twitter_oauth/lists.rb - lib/twitter_oauth/notifications.rb - lib/twitter_oauth/saved_searches.rb - lib/twitter_oauth/search.rb - lib/twitter_oauth/spam.rb - lib/twitter_oauth/status.rb - lib/twitter_oauth/timeline.rb - lib/twitter_oauth/trends.rb - lib/twitter_oauth/user.rb - lib/twitter_oauth/utils.rb homepage: http://github.com/moomerman/twitter_oauth licenses: [] metadata: {} post_install_message: rdoc_options: - --inline-source - --charset=UTF-8 require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: '0' required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: twitter_oauth rubygems_version: 2.0.0 signing_key: specification_version: 2 summary: twitter_oauth is a Ruby client for the Twitter API using OAuth. test_files: [] twitter_oauth-0.4.94/lib/0000755000004100000410000000000012203704153015305 5ustar www-datawww-datatwitter_oauth-0.4.94/lib/twitter_oauth/0000755000004100000410000000000012203704153020207 5ustar www-datawww-datatwitter_oauth-0.4.94/lib/twitter_oauth/lists.rb0000644000004100000410000000613212203704153021674 0ustar www-datawww-datamodule TwitterOAuth class Client # # List methods # # Creates a new list for the authenticated user. Accounts are limited to 20 lists. def create_list(user, list, options={}) post("/#{user}/lists.json", options.merge(:name => list)) end # Updates the specified list. def update_list(user, list, options={}) post("/#{user}/lists/#{list}.json", options) end # List the lists of the specified user. # Private lists will be included if the authenticated user is the same as the user whose lists are being returned. def get_lists(user) get("/#{user}/lists.json") end # Show the specified list. Private lists will only be shown if the authenticated user owns the specified list. def get_list(user, list) get("/#{user}/lists/#{list}.json") end # Deletes the specified list. Must be owned by the authenticated user. def delete_list(user, list) delete("/#{user}/lists/#{list}.json") end # Show tweet timeline for members of the specified list. def list_statuses(user, list) get("/#{user}/lists/#{list}/statuses.json") end # List the lists the specified user has been added to. def list_memberships(user) get("/#{user}/lists/memberships.json") end # List the lists the specified user follows. def list_subscriptions(user) get("/#{user}/lists/subscriptions.json") end # # List Members Methods # # Returns the members of the specified list. def list_members(user, list) get("/#{user}/#{list}/members.json") end # Add a member to a list. The authenticated user must own the list to be able to add members to it. # Lists are limited to having 500 members. def add_member_to_list(user, list, member_id, options={}) post("/#{user}/#{list}/members.json", options.merge(:id => member_id)) end # Removes the specified member from the list. # The authenticated user must be the list's owner to remove members from the list. def remove_member_from_list(user, list, member_id) delete("/#{user}/#{list}/members.json?id=#{member_id}") end # Check if a user is a member of the specified list. def get_member_of_list(user, list, member_id) get("/#{user}/#{list}/members/#{member_id}.json") end # # List Subscribers Methods # # Returns the subscribers of the specified list. def list_subscribers(user, list) get("/#{user}/#{list}/subscribers.json") end # Make the authenticated user follow the specified list. def subscribe_to_list(user, list, options={}) post("/#{user}/#{list}/subscribers.json") end # Unsubscribes the authenticated user form the specified list. def unsubscribe_from_list(user, list) delete("/#{user}/#{list}/subscribers.json") end # Check if the specified user is a subscriber of the specified list. def get_subscriber_of_list(user, list, subscriber_id) get("/#{user}/#{list}/subscribers/#{subscriber_id}.json") end end endtwitter_oauth-0.4.94/lib/twitter_oauth/search.rb0000644000004100000410000000040612203704153022001 0ustar www-datawww-datarequire 'open-uri' module TwitterOAuth class Client def search(q, options={}) options[:count] ||= 20 options[:q] = URI.escape(q) args = options.map{|k,v| "#{k}=#{v}"}.join('&') get("/search/tweets.json?#{args}") end end endtwitter_oauth-0.4.94/lib/twitter_oauth/geo.rb0000644000004100000410000000213412203704153021306 0ustar www-datawww-datamodule TwitterOAuth class Client # Search for places (cities and neighborhoods) that can be attached to a statuses/update. # Given a latitude and a longitude, return a list of all the valid places that can be used as a place_id when updating a status def reverse_geocode(lat, lng, options={}) options[:lat] = lat; options[:lng] = lng args = options.map{|k,v| "#{k}=#{v}"}.join('&') get "/geo/reverse_geocode.json?#{args}" end # Search for places (cities and neighborhoods) that can be attached to a statuses/update. # Given a latitude and a longitude pair, or an IP address, return a list of all the valid cities # and neighborhoods that can be used as a place_id when updating a status. def geo_search(options={}) options[:query] = URI.escape(options[:query]) if options[:query] args = options.map{|k,v| "#{k}=#{v}"}.join('&') get "/geo/search.json?#{args}" end # Find out more details of a place that was returned from the geo/reverse_geocode method. def geo(id) get "/geo/id/#{id}.json" end end endtwitter_oauth-0.4.94/lib/twitter_oauth/favorites.rb0000644000004100000410000000125712203704153022543 0ustar www-datawww-datamodule TwitterOAuth class Client # Returns the 20 most recent favorite statuses for the authenticating user or user specified by the ID parameter. def favorites(page=1) get("/favorites.json?page=#{page}") end # Favorites the status specified in the ID parameter as the authenticating user. # Returns the favorite status when successful. def favorite(id) post("/favorites/create/#{id}.json") end # Un-favorites the status specified in the ID parameter as the authenticating user. # Returns the un-favorited status when successful. def unfavorite(id) post("/favorites/destroy/#{id}.json") end end end twitter_oauth-0.4.94/lib/twitter_oauth/client.rb0000644000004100000410000000601212203704153022011 0ustar www-datawww-datarequire 'twitter_oauth/timeline' require 'twitter_oauth/status' require 'twitter_oauth/account' require 'twitter_oauth/direct_messages' require 'twitter_oauth/search' require 'twitter_oauth/notifications' require 'twitter_oauth/blocks' require 'twitter_oauth/friendships' require 'twitter_oauth/user' require 'twitter_oauth/favorites' require 'twitter_oauth/utils' require 'twitter_oauth/trends' require 'twitter_oauth/lists' require 'twitter_oauth/saved_searches' require 'twitter_oauth/spam' require 'twitter_oauth/geo' require 'twitter_oauth/help' module TwitterOAuth class Client def initialize(options = {}) @consumer_key = options[:consumer_key] @consumer_secret = options[:consumer_secret] @token = options[:token] @secret = options[:secret] @proxy = options[:proxy] @debug = options[:debug] @api_version = options[:api_version] || '1.1' @api_host = options[:api_host] || 'api.twitter.com' end def authorize(token, secret, options = {}) request_token = OAuth::RequestToken.new( consumer, token, secret ) @access_token = request_token.get_access_token(options) @token = @access_token.token @secret = @access_token.secret @access_token end def show(username) get("/users/show/#{username}.json") end def request_token(options={}) consumer.get_request_token(options) end def authentication_request_token(options={}) consumer.options[:authorize_path] = '/oauth/authenticate' request_token(options) end private def consumer(options={}) @consumer ||= OAuth::Consumer.new( @consumer_key, @consumer_secret, { :site => "https://#{@api_host}", :request_endpoint => @proxy } ) end def access_token @access_token ||= OAuth::AccessToken.new(consumer, @token, @secret) end def get(path, headers={}) puts "[Client] GET #{path}" if @debug headers.merge!("User-Agent" => "twitter_oauth gem v#{TwitterOAuth::VERSION}") oauth_response = access_token.get("/#{@api_version}#{path}", headers) parse(oauth_response.body) end def post(path, body='', headers={}) puts "[Client] POST #{path}" if @debug headers.merge!("User-Agent" => "twitter_oauth gem v#{TwitterOAuth::VERSION}") headers.merge!("Content-Type" => "application/x-www-form-urlencoded\r\n") oauth_response = access_token.post("/#{@api_version}#{path}", body, headers) parse(oauth_response.body) end def delete(path, headers={}) puts "[Client] DELETE #{path}" if @debug headers.merge!("User-Agent" => "twitter_oauth gem v#{TwitterOAuth::VERSION}") oauth_response = access_token.delete("/#{@api_version}#{path}", headers) parse(oauth_response.body) end def parse(response_body) begin JSON.parse(response_body) rescue JSON::ParserError {:response => response_body}.to_json end end end end twitter_oauth-0.4.94/lib/twitter_oauth/notifications.rb0000644000004100000410000000073312203704153023410 0ustar www-datawww-datamodule TwitterOAuth class Client # Enables device notifications for updates from the specified user. # Returns the specified user when successful. def follow(id) post("/notifications/follow/#{id}.json") end # Disables notifications for updates from the specified user to the authenticating user. # Returns the specified user when successful. def leave(id) post("/notifications/leave/#{id}.json") end end end twitter_oauth-0.4.94/lib/twitter_oauth/trends.rb0000644000004100000410000000230212203704153022030 0ustar www-datawww-datamodule TwitterOAuth class Client # Returns the top 10 trending topics for a specific WOEID, if trending # information is available for it. The response is an array of "trend" # objects that encode the name of the trending topic, the query parameter # that can be used to search for the topic on Twitter Search, and the # Twitter Search URL.... def place_trends get("/trends/place.json") end # Returns the locations that Twitter has trending topic information for. The # response is an array of "locations" that encode the location's WOEID and # some other human-readable information such as a canonical name and country # the location belongs in. A WOEID is a Yahoo! Where On Earth ID. def available_trends get("/trends/available.json") end # Returns the locations that Twitter has trending topic information for, # closest to a specified location. The response is an array of "locations" # that encode the location's WOEID and some other human-readable information # such as a canonical name and country the location belongs in. # A WOEID is a Yahoo... def closest_trends get("/trends/closest.json") end end endtwitter_oauth-0.4.94/lib/twitter_oauth/spam.rb0000644000004100000410000000035012203704153021472 0ustar www-datawww-datamodule TwitterOAuth class Client # The user specified in the id is blocked by the authenticated user and reported as a spammer. def report_spam(user) post("/report_spam.json", :id => user) end end endtwitter_oauth-0.4.94/lib/twitter_oauth/utils.rb0000644000004100000410000000223112203704153021672 0ustar www-datawww-datamodule TwitterOAuth class Client CRLF = "\r\n" private # Properly encodes images in form/multipart specification for upload via OAuth. def http_multipart_data(params) body = "" headers = {} boundary = Time.now.to_i.to_s(16) headers["Content-Type"] = "multipart/form-data; boundary=#{boundary}" params.each do |key,value| esc_key = OAuth::Helper.escape(key.to_s) body << "--#{boundary}#{CRLF}" if value.respond_to?(:read) mime_type = MIME::Types.type_for(value.path)[0] || MIME::Types["application/octet-stream"][0] body << "Content-Disposition: form-data; name=\"#{esc_key}\"; filename=\"#{File.basename(value.path)}\"#{CRLF}" body << "Content-Type: #{mime_type.simplified}#{CRLF*2}" body << value.read else body << "Content-Disposition: form-data; name=\"#{esc_key}\"#{CRLF*2}#{value}" end end body << "--#{boundary}--#{CRLF*2}" headers["Content-Length"] = body.size.to_s return [ body, headers ] end end endtwitter_oauth-0.4.94/lib/twitter_oauth/status.rb0000644000004100000410000000147112203704153022062 0ustar www-datawww-datamodule TwitterOAuth class Client # Returns a single status, specified by the id parameter below. def status(id) get("/statuses/show/#{id}.json") end # Updates the authenticating user's status. def update(message, options={}) post('/statuses/update.json', options.merge(:status => message)) end # Destroys the status specified by the required ID parameter def status_destroy(id) post("/statuses/destroy/#{id}.json") end # Retweets the tweet specified by the id parameter. Returns the original tweet with retweet details embedded. def retweet(id) post("/statuses/retweet/#{id}.json") end # Returns the 100 most recent retweets of the tweet. def retweets(id) get("/statuses/retweets/#{id}.json") end end end twitter_oauth-0.4.94/lib/twitter_oauth/timeline.rb0000644000004100000410000000420012203704153022336 0ustar www-datawww-datamodule TwitterOAuth class Client # Returns the 20 most recent statuses from non-protected users who have set a custom user icon. def public_timeline(options={}) args = options.map{|k,v| "#{k}=#{v}"}.join('&') get("/statuses/public_timeline.json?#{args}") end # Returns the 20 most recent statuses, including retweets, posted by the authenticating user and that user's friends. # This is the equivalent of /timeline/home on the Web. def home_timeline(options={}) args = options.map{|k,v| "#{k}=#{v}"}.join('&') get("/statuses/home_timeline.json?#{args}") end # Returns the 20 most recent statuses posted by the authenticating user and that user's friends. def friends_timeline(options={}) args = options.map{|k,v| "#{k}=#{v}"}.join('&') get("/statuses/friends_timeline.json?#{args}") end # Returns the 20 most recent statuses posted from the authenticating user. def user_timeline(options={}) args = options.map{|k,v| "#{k}=#{v}"}.join('&') get("/statuses/user_timeline.json?#{args}") end alias :user :user_timeline # Returns the 20 most recent @replies (status updates prefixed with @username) for the authenticating user. def mentions(options={}) args = options.map{|k,v| "#{k}=#{v}"}.join('&') get("/statuses/mentions_timeline.json?#{args}") end alias :replies :mentions # Returns the 20 most recent retweets posted by the authenticating user def retweeted_by_me(options={}) args = options.map{|k,v| "#{k}=#{v}"}.join('&') get("/statuses/retweeted_by_me.json?#{args}") end # Returns the 20 most recent retweets posted by the authenticating user's friends. def retweeted_to_me(options={}) args = options.map{|k,v| "#{k}=#{v}"}.join('&') get("/statuses/retweeted_to_me.json?#{args}") end # Returns the 20 most recent tweets of the authenticated user that have been retweeted by others. def retweets_of_me(options={}) args = options.map{|k,v| "#{k}=#{v}"}.join('&') get("/statuses/retweets_of_me.json?#{args}") end end end twitter_oauth-0.4.94/lib/twitter_oauth/help.rb0000644000004100000410000000070712203704153021470 0ustar www-datawww-datamodule TwitterOAuth class Client # Returns the current rate limits for methods belonging to the specified # resource families. Each 1.1 API resource belongs to a "resource family" # which is indicated in its method documentation. You can typically # determine a method's resource family from the first component of the path # after the... def rate_limit_status get('/application/rate_limit_status.json') end end endtwitter_oauth-0.4.94/lib/twitter_oauth/saved_searches.rb0000644000004100000410000000122012203704153023506 0ustar www-datawww-datamodule TwitterOAuth class Client # Returns the authenticated user's saved search queries. def saved_searches get("/saved_searches.json") end # Retrieve the data for a saved search owned by the authenticating user specified by the given id. def get_saved_search(search_id) get("/saved_searches/show/#{search_id}.json") end # Creates a saved search for the authenticated user. def create_saved_search(query) post("/saved_searches/create.json", :query => query) end def delete_saved_search(search_id) post("/saved_searches/destroy/#{search_id}.json") end end endtwitter_oauth-0.4.94/lib/twitter_oauth/friendships.rb0000644000004100000410000000453212203704153023056 0ustar www-datawww-datamodule TwitterOAuth class Client # Returns an array of numeric IDs for every user the specified user is following. def friends_ids(options={}) args = options.map{|k,v| "#{k}=#{v}"}.join('&') get("/friends/ids.json?#{args}") end # Returns an array of numeric IDs for every user following the specified user. def followers_ids(options={}) args = options.map{|k,v| "#{k}=#{v}"}.join('&') get("/followers/ids.json?#{args}") end # Allows the authenticating user to follow the specified user. Returns the befriended user when successful. def friend(id) post("/friendships/create/#{id}.json") end # Allows the authenticating users to unfollow the specified user. Returns the unfollowed user when successful. def unfriend(id) post("/friendships/destroy/#{id}.json") end # Tests for the existence of friendship between two users. Will return true if user_a follows user_b, otherwise will return false. # You are better off using get_friendship as it returns more extended information. def friends?(a, b) oauth_response = access_token.get("/friendships/exists.json?user_a=#{a}&user_b=#{b}") oauth_response.body.strip == 'true' end # Returns detailed information about the relationship between two users. def get_friendship(a, b) get("/friendships/show.json?source_screen_name=#{a}&target_screen_name=#{b}") end # Returns a cursored collection of user objects for every user the specified # user is following (otherwise known as their "friends") def friends(cursor=-1) get("/friends/list.json?cursor=#{cursor}") end # Helper to retrun all friends via multiple requests def all_friends(cursor=-1) users = [] while cursor != 0 do json = friends(cursor) cursor = json["next_cursor"] users += json["users"] end users end # Returns a cursored collection of user objects for users following the # specified user. def followers(cursor=-1) get("/followers/list.json?cursor=#{cursor}") end # Helper to retrun all followers via multiple requests def all_followers(cursor=-1) users = [] while cursor != 0 do json = followers(cursor) cursor = json["next_cursor"] users += json["users"] end users end end end twitter_oauth-0.4.94/lib/twitter_oauth/account.rb0000644000004100000410000000426412203704153022176 0ustar www-datawww-datamodule TwitterOAuth class Client # Returns an HTTP 200 OK response code and a representation of the requesting user if authentication was successful; # returns a 401 status code and an error message if not. def authorized? puts "[Client] GET /account/verify_credentials.json" if @debug oauth_response = access_token.get("/#{@api_version}/account/verify_credentials.json") return oauth_response.class == Net::HTTPOK end def info get('/account/verify_credentials.json') end # Updates profile background image. Takes a File object and optional tile argument. # Returns extended user info object. def update_profile_background_image(image, tile = false) body, headers = http_multipart_data({:image => image, :tile => tile}) post('/account/update_profile_background_image.json', body, headers) end # Updates profile avatar image. Takes a File object which should be an image. # Returns extended user info object. def update_profile_image(image) body, headers = http_multipart_data({:image => image}) post('/account/update_profile_image.json', body, headers) end # colors hash must contain at least one or more of the following keys :profile_background_color, :profile_text_color, :profile_link_color, :profile_sidebar_fill_color, :profile_sidebar_border_color # returns extended user info object. def update_profile_colors(colors) post('/account/update_profile_colors.json', colors) end # Sets values that users are able to set under the "Account" tab of their settings page. # Valid parameters are: # :name Full name associated with the profile. Maximum of 20 characters. # :url URL associated with the profile. Will be prepended with "http://" if not present. Maximum of 100 characters. # :location The city or country describing where the user of the account is located. The contents are not normalized # or geocoded in any way. Maximum of 30 characters. # :description A description of the user owning the account. Maximum of 160 characters. def update_profile(params) post('/account/update_profile', params) end end end twitter_oauth-0.4.94/lib/twitter_oauth/direct_messages.rb0000644000004100000410000000177012203704153023702 0ustar www-datawww-datamodule TwitterOAuth class Client # Return the most recent direct messages sent to the authenticating user. # By default, returns the last 20. See http://apiwiki.twitter.com/Twitter-REST-API-Method:-direct_messages # for other options def messages(options={}) args = options.map{|k,v| "#{k}=#{v}"}.join('&') get("/direct_messages.json?#{args}") end # By default, returns a list of the 20 most recent direct messages sent by the authenticating user. def sent_messages(options={}) args = options.map{|k,v| "#{k}=#{v}"}.join('&') get("/direct_messages/sent.json?#{args}") end # Sends a new direct message to the specified user from the authenticating user. def message(user, text) post('/direct_messages/new.json', :user => user, :text => text) end # Destroys the direct message specified in the required ID parameter. def message_destroy(id) post("/direct_messages/destroy/#{id}.json") end end end twitter_oauth-0.4.94/lib/twitter_oauth/user.rb0000644000004100000410000000106412203704153021513 0ustar www-datawww-datamodule TwitterOAuth class Client # Returns settings (including current trend, geo and sleep time information) # for the authenticating user. def settings get('/account/settings.json') end # Returns an HTTP 200 OK response code and a representation of the # requesting user if authentication was successful; returns a 401 status # code and an error message if not. Use this method to test if supplied user # credentials are valid. def verify_credentials get('/account/verify_credentials.json') end end end twitter_oauth-0.4.94/lib/twitter_oauth/blocks.rb0000644000004100000410000000176412203704153022021 0ustar www-datawww-datamodule TwitterOAuth class Client # Blocks the user specified in the ID parameter as the authenticating user. # Destroys a friendship to the blocked user if it exists. # Returns the blocked user in the requested format when successful. def block(id) post("/blocks/create/#{id}.json") end # Un-blocks the user specified in the ID parameter for the authenticating user. # Returns the un-blocked user in the requested format when successful. def unblock(id) post("/blocks/destroy/#{id}.json") end # Returns if the authenticating user is blocking a target user. def blocked?(id) get("/blocks/exists/#{id}.json") end # Returns an array of user objects that the authenticating user is blocking. def blocking get("/blocks/blocking.json") end # Returns an array of numeric user ids the authenticating user is blocking. def blocking_ids get("/blocks/blocking/ids.json") end end end twitter_oauth-0.4.94/lib/twitter_oauth.rb0000644000004100000410000000020212203704153020526 0ustar www-datawww-datarequire 'oauth' require 'json' require 'mime/types' require 'twitter_oauth/client' module TwitterOAuth VERSION = '0.4.94' end