Exploring the Twitter gem

This morning I read a tweet from Dave Winer which mentioned he was working on a Twitter user timeline to RSS project, and it got me interested in what I could do in Ruby using the Twitter gem.

What follows is a code listing of the things I discovered, including how to:

Prerequisite

It is assumed you have already installed the Twitter gem, registered the client, and the client is authorised to use the Twitter API.

Code used

# browsing methods related to my username and more

(client.public_methods - Object.public_methods).sort.a2.each_slice(4)\
  .each {|row|  puts (row[0..-2].map{|x| x.to_s.ljust(32)} < row[-1]).join }

output:

access_token                    access_token=                   access_token_secret             access_token_secret=
add_list_member                 add_list_members                bearer_token                    bearer_token=
bearer_token?                   block                           block?                          blocked
blocked_ids                     blocking                        configuration                   connection
connection_options              connection_options=             consumer_key                    consumer_key=
consumer_secret                 consumer_secret=                contributees                    contributors
create_direct_message           create_favorite!                create_friendship               create_friendship!
create_list                     create_saved_search             credentials                     credentials?
current_user                    d                               destroy_direct_message          destroy_favorite
destroy_friendship              destroy_list                    destroy_saved_search            destroy_status
destroy_tweet                   direct_message                  direct_message_create           direct_message_destroy
direct_messages                 direct_messages_received        direct_messages_sent            dm
fav                             fav!                            fave                            fave!
favorite                        favorite!                       favorite_create                 favorite_create!
favorite_destroy                favorites                       follow                          follow!
follower_ids                    followers                       following                       following_followers_of
friend_ids                      friends                         friendship                      friendship?
friendship_create               friendship_create!              friendship_destroy              friendship_show
friendship_update               friendships                     friendships_incoming            friendships_outgoing
geo_search                      get                             home_timeline                   invalidate_token
languages                       list                            list_add_member                 list_add_members
list_create                     list_destroy                    list_member?                    list_members
list_remove_member              list_remove_members             list_subscribe                  list_subscriber?
list_subscribers                list_timeline                   list_unsubscribe                list_update
lists                           lists_owned                     lists_ownerships                lists_subscribed_to
local_trends                    m                               memberships                     mentions
mentions_timeline               middleware                      middleware=                     mute
muted                           muted_ids                       muting                          no_retweet_ids
no_retweets_ids                 oauth_token                     oauth_token=                    oauth_token_secret
oauth_token_secret=             oembed                          oembeds                         owned_lists
place                           places_nearby                   places_similar                  post
privacy                         profile_banner                  profile_banner_remove           proxy
proxy=                          relationship                    remove_list_member              remove_list_members
remove_profile_banner           report_spam                     retweet                         retweet!
retweeted_by                    retweeted_by_me                 retweeted_by_user               retweeted_to_me
retweeters_ids                  retweeters_of                   retweets                        retweets_of_me
reverse_geocode                 reverse_token                   saved_search                    saved_search_create
saved_search_destroy            saved_searches                  search                          settings
similar_places                  status                          status_destroy                  statuses
subscriptions                   suggest_users                   suggestions                     token
tos                             trend_locations                 trends                          trends_available
trends_closest                  trends_place                    tweet_count                     tweet_destroy
unblock                         unfavorite                      unfollow                        unmute
update                          update!                         update_delivery_device          update_profile
update_profile_background_image update_profile_banner           update_profile_colors           update_profile_image
update_with_media               upload                          user                            user?
user_agent                      user_agent=                     user_search                     user_timeline
user_token?                     users                           verify_credentials


  client.lists  #=> [#<Twitter::List id=54448940>, #<Twitter::List ....
  client.user_timeline #=> 

output:

[]                                   attrs                                connections
connections?                         contributors_enabled                 contributors_enabled?
created?                             created_at                           default_profile
default_profile?                     default_profile_image                default_profile_image?
description                          description?                         description_uris
description_uris?                    description_urls                     description_urls?
entities?                            favorites_count                      favourites_count
favourites_count?                    follow_request_sent                  follow_request_sent?
followers_count                      followers_count?                     following
following?                           friends_count                        friends_count?
geo_enabled                          geo_enabled?                         handle
id                                   id?                                  lang
lang?                                listed_count                         listed_count?
location                             location?                            memoize
muting                               muting?                              name?
needs_phone_verification             needs_phone_verification?            notifications
notifications?                       profile_background_color             profile_background_color?
profile_background_image_uri         profile_background_image_uri?        profile_background_image_uri_https
profile_background_image_uri_https?  profile_background_image_url         profile_background_image_url?
profile_background_image_url_https   profile_background_image_url_https?  profile_background_tile
profile_background_tile?             profile_banner_uri                   profile_banner_uri?
profile_banner_uri_https             profile_banner_uri_https?            profile_banner_url
profile_banner_url?                  profile_banner_url_https             profile_banner_url_https?
profile_image_uri                    profile_image_uri?                   profile_image_uri_https
profile_image_uri_https?             profile_image_url                    profile_image_url?
profile_image_url_https              profile_image_url_https?             profile_link_color
profile_link_color?                  profile_sidebar_border_color         profile_sidebar_border_color?
profile_sidebar_fill_color           profile_sidebar_fill_color?          profile_text_color
profile_text_color?                  profile_use_background_image         profile_use_background_image?
protected                            protected?                           screen_name
screen_name?                         status                               status?
statuses_count                       statuses_count?                      suspended
suspended?                           time_zone                            time_zone?
to_h                                 to_hash                              to_hsh
translation_enabled?                 translator?                          tweet
tweet?                               tweeted?                             tweets_count
uri                                  url                                  user_name
username                             utc_offset                           utc_offset?
verified                             verified?                            website
website?                             website_uris                         website_uris?
website_urls                         website_urls?

# selecting another user's latest tweet as an object

u.status #=> #<Twitter::Tweet id=556356673183703040> 
t = u.status

# browsing methods related to a tweet object

(t.public_methods - Object.public_methods).sort.each_slice(3)\
  .each {|row|  puts (row[0..-2].map{|x| x.to_s.ljust(26)} < row[-1]).join }

output:

[]                        attrs                     created?
created_at                entities?                 favorite_count
favorite_count?           favorited                 favorited?
favoriters_count          favorites_count           filter_level
filter_level?             full_text                 geo
geo?                      hashtags                  hashtags?
id                        id?                       in_reply_to_screen_name
in_reply_to_screen_name?  in_reply_to_status_id     in_reply_to_status_id?
in_reply_to_tweet_id      in_reply_to_user_id       in_reply_to_user_id?
lang                      lang?                     media
media?                    memoize                   metadata
metadata?                 place                     place?
possibly_sensitive        possibly_sensitive?       reply?
retweet?                  retweet_count             retweet_count?
retweeted                 retweeted?                retweeted_status
retweeted_status?         retweeted_tweet           retweeted_tweet?
retweeters_count          source                    source?
symbols                   symbols?                  text
text?                     to_h                      to_hash
to_hsh                    truncated                 truncated?
uri                       uris                      uris?
url                       urls                      urls?
user                      user?                     user_mentions

# viewing the text of the tweet

t.text #=> "RT @dagbrown: @mathie mp4art\", part of the mp4v2 tools" 
u.tweets_count #=> 18626 

# selecting another user's latest tweets

list = URI.parse('https://twitter.com/sferik/presidents')
client.list_timeline(list)
# => [#<Twitter::Tweet id=556229324643115008>, #<Twitter::Tweet ...

Resources

Tags:
Source:
1228hrs.txt
Published:
17-01-2015 12:28