CRLF | = | "\r\n" |
# File lib/twitter_oauth/client.rb, line 21 def initialize(options = {}) @consumer_key = options[:consumer_key] @consumer_secret = options[:consumer_secret] @token = options[:token] @secret = options[:secret] @proxy = options[:proxy] 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.
# File lib/twitter_oauth/lists.rb, line 60 def add_member_to_list(user, list, member_id, options={}) post("/#{user}/#{list}/members.json", options.merge(:id => member_id)) end
# File lib/twitter_oauth/client.rb, line 52 def authentication_request_token(options={}) consumer.options[:authorize_path] = '/oauth/authenticate' request_token(options) end
# File lib/twitter_oauth/client.rb, line 29 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
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.
# File lib/twitter_oauth/account.rb, line 6 def authorized? oauth_response = access_token.get('/1/account/verify_credentials.json') return oauth_response.class == Net::HTTPOK end
Returns the current top 10 trending topics on Twitter.
# File lib/twitter_oauth/search.rb, line 15 def current_trends search_get("/trends/current.json") end
Returns the top 20 trending topics for each hour in a given day.
# File lib/twitter_oauth/search.rb, line 20 def daily_trends search_get("/trends/daily.json") end
# File lib/twitter_oauth/saved_searches.rb, line 19 def delete_saved_search(search_id) post("/saved_searches/destroy/#{search_id}.json") end
Returns the 100 last followers
# File lib/twitter_oauth/user.rb, line 34 def followers(page=1) return get("/statuses/followers.json?page=#{page}") if page == 1 users = [] cursor = "-1" page.times do return [] if cursor == 0 json = get("/statuses/followers.json?cursor=#{cursor}") cursor = json["next_cursor"] users = json["users"] end users end
Returns the 100 last friends The page parameter is implemented for legacy reasons, but use of this is slow as passing page is no longer supported by the Twitter API as the use of cursors is now obligitory. It is recommended that you use all_friends instead
# File lib/twitter_oauth/user.rb, line 8 def friends(page=1) return get("/statuses/friends.json?page=#{page}") if page == 1 users = [] cursor = "-1" page.times do return [] if cursor == 0 json = get("/statuses/friends.json?cursor=#{cursor}") cursor = json["next_cursor"] users = json["users"] end users 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.
# File lib/twitter_oauth/friendships.rb, line 28 def friends?(a, b) oauth_response = access_token.get("/friendships/exists.json?user_a=#{a}&user_b=#{b}") oauth_response.body.strip == 'true' end
Find out more details of a place that was returned from the geo/reverse_geocode method.
# File lib/twitter_oauth/geo.rb, line 22 def geo(id) get "/geo/id/#{id}.json" 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.
# File lib/twitter_oauth/geo.rb, line 15 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
Returns detailed information about the relationship between two users.
# File lib/twitter_oauth/friendships.rb, line 34 def get_friendship(a, b) get("/friendships/show.json?source_screen_name=#{a}&target_screen_name=#{b}") 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.
# File lib/twitter_oauth/timeline.rb, line 12 def home_timeline(options={}) args = options.map{|k,v| "#{k}=#{v}"}.join('&') get("/statuses/home_timeline.json?#{args}") end
Returns the members of the specified list.
# File lib/twitter_oauth/lists.rb, line 54 def list_members(user, list) get("/#{user}/#{list}/members.json") end
Show tweet timeline for members of the specified list.
# File lib/twitter_oauth/lists.rb, line 35 def list_statuses(user, list) get("/#{user}/lists/#{list}/statuses.json") end
Returns the subscribers of the specified list.
# File lib/twitter_oauth/lists.rb, line 80 def list_subscribers(user, list) get("/#{user}/#{list}/subscribers.json") end
Return the most recent direct messages sent to the authenticating user. By default, returns the last 20. See apiwiki.twitter.com/Twitter-REST-API-Method:-direct_messages for other options
# File lib/twitter_oauth/direct_messages.rb, line 7 def messages(options={}) args = options.map{|k,v| "#{k}=#{v}"}.join('&') get("/direct_messages.json?#{args}") end
# File lib/twitter_oauth/client.rb, line 48 def request_token(options={}) consumer.get_request_token(options) end
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
# File lib/twitter_oauth/geo.rb, line 6 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
# File lib/twitter_oauth/search.rb, line 6 def search(q, options={}) options[:page] ||= 1 options[:rpp] ||= 20 options[:q] = URI.escape(q) args = options.map{|k,v| "#{k}=#{v}"}.join('&') search_get("/search.json?#{args}") end
# File lib/twitter_oauth/client.rb, line 39 def show(username) get("/users/show/#{username}.json") end
Returns the top ten topics that are currently trending on Twitter.
# File lib/twitter_oauth/trends.rb, line 5 def trends get("/trends.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 (a Yahoo! Where On Earth ID) and some other human-readable information such as a canonical name and country the location belongs in.
# File lib/twitter_oauth/trends.rb, line 12 def trends_available get("/trends/available.json") end
Returns the top 10 trending topics for a specific location Twitter has trending topic information for. 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 Search, and the direct URL that can be issued against Search. This information is cached for five minutes, and therefore users are discouraged from querying these endpoints faster than once every five minutes. Global trends information is also available from this API by using a WOEID of 1.
# File lib/twitter_oauth/trends.rb, line 21 def trends_for_location(woeid) get("/trends/woeid.json") end
Updates the specified list.
# File lib/twitter_oauth/lists.rb, line 14 def update_list(user, list, options={}) post("/#{user}/lists/#{list}.json", options) 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.
# File lib/twitter_oauth/account.rb, line 48 def update_profile(params) post('/account/update_profile', params) end
Updates profile background image. Takes a File object and optional tile argument. Returns extended user info object.
# File lib/twitter_oauth/account.rb, line 23 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
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.
# File lib/twitter_oauth/account.rb, line 37 def update_profile_colors(colors) post('/account/update_profile_colors.json', colors) end
Updates profile avatar image. Takes a File object which should be an image. Returns extended user info object.
# File lib/twitter_oauth/account.rb, line 30 def update_profile_image(image) body, headers = http_multipart_data({:image => image}) post('/account/update_profile_image.json', body, headers) end