Permalink
Browse files

Updated examples and moved into README

  • Loading branch information...
1 parent c845b6e commit 96600cb5611965788c41b3788668188d37e16803 @sferik committed Oct 27, 2010
View
@@ -1,22 +1,58 @@
= The twitter Ruby gem
==== A Ruby wrapper for the Twitter REST and Search APIs.
== Examples
-See the examples directory.
-http://github.com/jnunemaker/twitter/tree/master/examples
+ require 'rubygems'
+ require 'twitter'
+
+ # Register an app at http://dev.twitter.com/apps to get your Twitter OAuth credentials
+ Twitter.configure do |config|
+ config.consumer_key = YOUR_CONSUMER_KEY
+ config.consumer_secret = YOUR_CONSUMER_SECRET
+ config.oauth_token = YOUR_OAUTH_TOKEN
+ config.oauth_token_secret = YOUR_OAUTH_TOKEN_SECRET
+ end
+
+ # Initialize a Twitter client
+ client = Twitter::Client.new
+ # Post a status update
+ client.update("I just posted a status update via the Twitter Ruby Gem!")
+ # Read the latest tweet in your home timeline
+ puts client.home_timeline.first.text
+ # Get a user's location
+ puts client.user("sferik").location
+ # Get a status update by id
+ puts client.status(27558893223).text
+ # Get your most popular friend
+ puts client.friends.sort{|a, b| a.followers_count <=> b.followers_count}.reverse.first.name
+ # Get your most popular follower
+ puts client.followers.sort{|a, b| a.followers_count <=> b.followers_count}.reverse.first.name
+ # Get your rate limit status
+ puts client.rate_limit_status.remaining_hits.to_s + " Twitter API request(s) remaining this hour"
+
+ # Initialize a Twitter search client
+ search = Twitter::Search.new(:endpoint => "http://search.twitter.com/")
+ # Find the 3 most recent proposals to @justinbieber
+ search.to('justinbieber').containing('marry me').result_type('recent').per_page(3).each{|s| puts "#{s.from_user}: #{s.text}"}
+ # Reset the search client
+ search.clear
+ # Find a Japanese-language status update tagged #ruby
+ puts search.hashtag('ruby').language('ja').no_retweets.per_page(1).fetch.results.first.text
+ # Find another
+ puts search.fetch_next_page.results.first.text
+
== Docs
-http://rdoc.info/projects/jnunemaker/twitter
+http://rdoc.info/github/jnunemaker/twitter
== Submitting Bugs/Features
-We use the GitHub issue tracker for bugs and feature requests. If you want to report a bug or missing feature, please make sure it hasn't already been reported, then create a new issue. When submitting a bug report, please include a Gist[http://gist.github.com/] of the stack trace and any details that may be necessary to reproduce the bug, including the version of the gem you're using, your Ruby version, and your operating system. Ideally, bug reports should be submitted with failing tests, but this is not necessary.
+We use the GitHub issue tracker for bugs and feature requests. If you want to report a bug or missing feature, please make sure it hasn't already been reported, then create a new issue. When submitting a bug report, please include a Gist[http://gist.github.com/] of the stack trace and any details that may be necessary to reproduce the bug, including the version of the gem you're using, your Ruby version, and your operating system. Ideally, bug reports should be submitted with failing/pending specs.
http://github.com/jnunemaker/twitter/issues
== Submitting Patches
1. Fork the project.
2. Create a topic branch.
3. Commit your feature or bug fix.
-4. Add specs for feature or bug fix. This is important so it doesn't break in the future.
-5. Run `bundle exec rake spec:rcov`. If your changes are not covered, go back to 4.
-6. Please do not include changes to the gemspec, version, or history file. (If you want to create your own version, please do so in a separate commit.)
-7. Submit a pull request.
+4. Add specs for your feature or bug fix. This is important so it doesn't break in the future.
+5. Run `bundle exec rake spec:rcov`. If your changes are not 100% covered, go back to step 4.
+6. Submit a pull request. Please do not include changes to the gemspec, version, or history file. (If you want to create your own version for some reason, please do so in a separate commit.)
== Copyright
Copyright (c) 2010 John Nunemaker, Wynn Netherland, Erik Michaels-Ober, Steve Richert. See LICENSE for details.
View
@@ -1,30 +0,0 @@
-require File.join(File.dirname(__FILE__), '..', 'lib', 'twitter')
-require File.join(File.dirname(__FILE__), 'helpers', 'config_store')
-require 'pp'
-
-config = ConfigStore.new("#{ENV['HOME']}/.twitter")
-oauth = Twitter::OAuth.new(config['token'], config['secret'])
-
-if config['atoken'] && config['asecret']
- oauth.authorize_from_access(config['atoken'], config['asecret'])
- twitter = Twitter::Authenticated.new(oauth)
- pp twitter.friends_timeline
-
-elsif config['rtoken'] && config['rsecret']
- oauth.authorize_from_request(config['rtoken'], config['rsecret'], 'PIN')
- twitter = Twitter::Authenticated.new(oauth)
- pp twitter.friends_timeline
-
- config.update({
- 'atoken' => oauth.access_token.token,
- 'asecret' => oauth.access_token.secret,
- }).delete('rtoken', 'rsecret')
-else
- config.update({
- 'rtoken' => oauth.request_token.token,
- 'rsecret' => oauth.request_token.secret,
- })
-
- # authorize in browser
- %x(open #{oauth.request_token.authorize_url})
-end
@@ -1,14 +0,0 @@
-require File.join(File.dirname(__FILE__), '..', 'lib', 'twitter')
-require File.join(File.dirname(__FILE__), 'helpers', 'config_store')
-require 'pp'
-
-config = ConfigStore.new("#{ENV['HOME']}/.twitter")
-oauth = Twitter::OAuth.new(config['token'], config['secret'])
-oauth.authorize_from_access(config['atoken'], config['asecret'])
-client = Twitter::Authenticated.new(oauth)
-
-puts "Friends List, sorted by followers"
-client.friends.sort {|a, b| a.followers_count <=> b.followers_count}.reverse.each {|f| puts "#{f.name} (@#{f.screen_name}) - #{f.followers_count}"}
-
-puts "\n\nFollowers List, sorted by followers"
-client.followers.sort {|a, b| a.followers_count <=> b.followers_count}.reverse.each {|f| puts "#{f.name} (@#{f.screen_name}) - #{f.followers_count}"}
@@ -1,11 +0,0 @@
-require File.join(File.dirname(__FILE__), '..', 'lib', 'twitter')
-require File.join(File.dirname(__FILE__), 'helpers', 'config_store')
-require 'pp'
-
-config = ConfigStore.new("#{ENV['HOME']}/.twitter")
-oauth = Twitter::OAuth.new(config['token'], config['secret'])
-oauth.authorize_from_access(config['atoken'], config['asecret'])
-client = Twitter::Authenticated.new(oauth)
-
-puts client.friendship_exists?('jnunemaker', 'orderedlist')
-puts client.friendship_exists?('jnunemaker', 'biz')
@@ -1,38 +0,0 @@
-class ConfigStore
- attr_reader :file
-
- def initialize(file)
- @file = file
- end
-
- def load
- @config ||= YAML::load(open(file))
- self
- end
-
- def [](key)
- load
- @config[key]
- end
-
- def []=(key, value)
- @config[key] = value
- end
-
- def delete(*keys)
- keys.each { |key| @config.delete(key) }
- save
- self
- end
-
- def update(c={})
- @config.merge!(c)
- save
- self
- end
-
- def save
- File.open(file, 'w') { |f| f.write(YAML.dump(@config)) }
- self
- end
-end
View
@@ -1,11 +0,0 @@
-require File.join(File.dirname(__FILE__), '..', 'lib', 'twitter')
-require File.join(File.dirname(__FILE__), 'helpers', 'config_store')
-require 'pp'
-
-config = ConfigStore.new("#{ENV['HOME']}/.twitter")
-oauth = Twitter::OAuth.new(config['token'], config['secret'])
-oauth.authorize_from_access(config['atoken'], config['asecret'])
-client = Twitter::Authenticated.new(oauth)
-
-puts client.friend_ids
-puts client.follower_ids
View
@@ -1,11 +0,0 @@
-require File.join(File.dirname(__FILE__), '..', 'lib', 'twitter')
-require File.join(File.dirname(__FILE__), 'helpers', 'config_store')
-require 'pp'
-
-config = ConfigStore.new("#{ENV['HOME']}/.twitter")
-oauth = Twitter::OAuth.new(config['token'], config['secret'])
-oauth.authorize_from_access(config['atoken'], config['asecret'])
-client = Twitter::Authenticated.new(oauth)
-
-pp client.lists('pengwynn')
-pp client.list_members('pengwynn', 'rubyists')
View
@@ -1,27 +0,0 @@
-require 'pp'
-require 'pathname'
-dir = Pathname(__FILE__).dirname.expand_path
-require (dir + '..' + 'lib' + 'twitter').expand_path
-require dir + 'helpers' + 'config_store'
-
-config = ConfigStore.new("#{ENV['HOME']}/.twitter")
-oauth = Twitter::OAuth.new(config['token'], config['secret'])
-rtoken = oauth.request_token.token
-rsecret = oauth.request_token.secret
-
-puts "> redirecting you to twitter to authorize..."
-%x(open #{oauth.request_token.authorize_url})
-
-print "> what was the PIN twitter provided you with? "
-pin = gets.chomp
-
-begin
- oauth.authorize_from_request(rtoken, rsecret, pin)
-
- twitter = Twitter::Authenticated.new(oauth)
- twitter.user_timeline.each do |tweet|
- puts "#{tweet.user.screen_name}: #{tweet.text}"
- end
-rescue OAuth::Unauthorized
- puts "> FAIL!"
-end
View
@@ -1,15 +0,0 @@
-require File.join(File.dirname(__FILE__), '..', 'lib', 'twitter')
-require 'pp'
-
-search = Twitter::Search.new.from('jnunemaker')
-
-puts '*'*50, 'First Run', '*'*50
-search.each { |result| pp result }
-
-puts '*'*50, 'Second Run', '*'*50
-search.each { |result| pp result }
-
-puts '*'*50, 'Parameter Check', '*'*50
-pp Twitter::Search.new('#austineats').fetch.results.first
-pp Twitter::Search.new('#austineats').page(2).fetch.results.first
-pp Twitter::Search.new('#austineats').since(1412737343).fetch.results.first
View
@@ -1,17 +0,0 @@
-require File.join(File.dirname(__FILE__), '..', 'lib', 'twitter')
-require File.join(File.dirname(__FILE__), 'helpers', 'config_store')
-require 'pp'
-
-config = ConfigStore.new("#{ENV['HOME']}/.twitter")
-oauth = Twitter::OAuth.new(config['token'], config['secret'])
-oauth.authorize_from_access(config['atoken'], config['asecret'])
-client = Twitter::Authenticated.new(oauth)
-
-pp client.friends_timeline
-puts '*'*50
-
-pp client.user_timeline
-puts '*'*50
-
-pp client.mentions
-puts '*'*50
View
@@ -1,16 +0,0 @@
-require File.join(File.dirname(__FILE__), '..', 'lib', 'twitter')
-require 'pp'
-
-puts 'User', '*'*50
-pp Twitter.user('jnunemaker')
-pp Twitter.user('snitch_test')
-
-puts 'Status', '*'*50
-pp Twitter.status(1533815199)
-
-puts 'Friend Ids', '*'*50
-pp Twitter.friend_ids('jnunemaker')
-
-puts 'Follower Ids', '*'*50
-pp Twitter.follower_ids('jnunemaker')
-
View
@@ -1,10 +0,0 @@
-require File.join(File.dirname(__FILE__), '..', 'lib', 'twitter')
-require File.join(File.dirname(__FILE__), 'helpers', 'config_store')
-require 'pp'
-
-config = ConfigStore.new("#{ENV['HOME']}/.twitter")
-oauth = Twitter::OAuth.new(config['token'], config['secret'])
-oauth.authorize_from_access(config['atoken'], config['asecret'])
-client = Twitter::Authenticated.new(oauth)
-
-pp client.update('This is an update from the twitter gem')
View
@@ -1,5 +0,0 @@
-require File.join(File.dirname(__FILE__), '..', 'lib', 'twitter')
-require 'pp'
-
-pp Twitter.user('jnunemaker')
-pp Twitter.user('snitch_test')

0 comments on commit 96600cb

Please sign in to comment.