codetocustomer-twitter 0.6.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/History +215 -0
  2. data/License +20 -0
  3. data/Notes +33 -0
  4. data/README.rdoc +19 -0
  5. data/Rakefile +103 -0
  6. data/VERSION.yml +4 -0
  7. data/examples/connect.rb +30 -0
  8. data/examples/friendship_existance.rb +13 -0
  9. data/examples/helpers/config_store.rb +38 -0
  10. data/examples/httpauth.rb +11 -0
  11. data/examples/ids.rb +13 -0
  12. data/examples/search.rb +15 -0
  13. data/examples/timeline.rb +19 -0
  14. data/examples/unauthorized.rb +16 -0
  15. data/examples/update.rb +11 -0
  16. data/examples/user.rb +5 -0
  17. data/lib/twitter.rb +63 -0
  18. data/lib/twitter/base.rb +165 -0
  19. data/lib/twitter/httpauth.rb +27 -0
  20. data/lib/twitter/oauth.rb +41 -0
  21. data/lib/twitter/request.rb +102 -0
  22. data/lib/twitter/search.rb +111 -0
  23. data/lib/twitter/trends.rb +29 -0
  24. data/test/fixtures/firehose.json +1 -0
  25. data/test/fixtures/follower_ids.json +1 -0
  26. data/test/fixtures/friend_ids.json +1 -0
  27. data/test/fixtures/friends_timeline.json +1 -0
  28. data/test/fixtures/rate_limit_exceeded.json +1 -0
  29. data/test/fixtures/replies.json +1 -0
  30. data/test/fixtures/search.json +1 -0
  31. data/test/fixtures/search_from_jnunemaker.json +1 -0
  32. data/test/fixtures/status.json +1 -0
  33. data/test/fixtures/status_show.json +1 -0
  34. data/test/fixtures/trends_current.json +1 -0
  35. data/test/fixtures/trends_current_exclude.json +1 -0
  36. data/test/fixtures/trends_daily.json +1 -0
  37. data/test/fixtures/trends_daily_date.json +1 -0
  38. data/test/fixtures/trends_daily_exclude.json +1 -0
  39. data/test/fixtures/trends_weekly.json +1 -0
  40. data/test/fixtures/trends_weekly_date.json +1 -0
  41. data/test/fixtures/trends_weekly_exclude.json +1 -0
  42. data/test/fixtures/user.json +1 -0
  43. data/test/fixtures/user_timeline.json +1 -0
  44. data/test/test_helper.rb +36 -0
  45. data/test/twitter/base_test.rb +95 -0
  46. data/test/twitter/httpauth_test.rb +76 -0
  47. data/test/twitter/oauth_test.rb +105 -0
  48. data/test/twitter/request_test.rb +217 -0
  49. data/test/twitter/search_test.rb +159 -0
  50. data/test/twitter/trends_test.rb +95 -0
  51. data/test/twitter_test.rb +38 -0
  52. metadata +200 -0
data/History ADDED
@@ -0,0 +1,215 @@
1
+ 0.6.13 - July 27, 2009
2
+ * 1 minor update
3
+ * Set oauth version to >= 0.3.5 so I don't have to release new gem for each oauth update, which seems to be frequent of late
4
+
5
+ 0.6.12 - June 26, 2009
6
+ * 2 minor additions
7
+ * fixed fakeweb test issue (obie fernandez)
8
+ * added user agent option to searches
9
+
10
+ 0.6.11 - May 18, 2009
11
+ * 1 minor addition
12
+ * Added the ability to sign in with twitter instead of authorizing
13
+
14
+ 0.6.10 - May 18, 2009
15
+ * 1 cool addition
16
+ * Added full support for trends - current, daily and weekly (even allowing excluding of hashtags and for specific dates)
17
+
18
+ 0.6.9 - May 17, 2009
19
+ * 1 minor tweak
20
+ * Bumped oauth dependency version to 0.3.4.
21
+
22
+ 0.6.8 - April 23, 2009
23
+ * 1 dependency fix
24
+ * forgot to update rakefile rendering previous 0.6.7 release useless. crap!
25
+
26
+ 0.6.7 - April 23, 2009
27
+ * 1 minor fix
28
+ * Bumped httparty version to 0.4.3 which allows response.message and fixes errors that the lack of response.message was causing to the twitter gem
29
+
30
+ 0.6.6 - April 16, 2009
31
+ * 1 minor enhancement
32
+ * added ability to pass query parameters to user method
33
+ * httpauth can now accept :ssl option to use https instead of http
34
+ * Added Twitter.status method for no auth calls to fetch status
35
+ * Added Twitter.friend_ids method for no auth calls to fetch status
36
+ * Added Twitter.follower_ids method for no auth calls to fetch status
37
+
38
+ 0.6.5 - April 15, 2009
39
+ * 1 bug fix
40
+ * fixed that friend_ids and follower_ids were bombing from trying to mash them. Added :mash option to Twitter::Request so I can specifically not mash certain responses from twitter
41
+
42
+ 0.6.4 - April 14, 2009
43
+ * 1 minor tweak
44
+ * More explicit about dependency versions in gemspec and when requiring.
45
+
46
+ 0.6.3 - April 14, 2009
47
+ * 1 minor addition
48
+ * Added Twitter.user method to get user's information without authenticating
49
+
50
+ 0.6.2 - April 14, 2009
51
+ * 1 minor addition
52
+ * added max to search so you can set the max id that should be used
53
+
54
+ 0.6.1 - April 12, 2009
55
+ * 1 minor fix
56
+ * Had two friend_ids functions. Renamed one of them to follower_ids.
57
+
58
+ 0.6.0 - April 11, 2009
59
+ * 1 feature addition
60
+ * Added http authentication back in. You can now use oauth or http auth as your client.
61
+
62
+ 0.5.3 - April 10, 2009
63
+ * 1 minor fix
64
+ * Twitter API assumed follow true whether true or false. Now only sending follow along to request if follow is true for calls to friendship_create.
65
+
66
+ 0.5.2 - April 8, 2009
67
+ * 4 minor fixes
68
+ * added mash as an install dependency, forgot it initially
69
+ * fixed that search wasn't taking into account a bunch of options duh!
70
+ * fixed some missing vars and stuff in exception raising
71
+ * added development dependencies to rake file to make that more explicit (technomancy)
72
+ * lame workaround for Mash#hash that allows using return objects in sets and such (technomancy)
73
+
74
+ 0.5.1 - April 5, 2009
75
+ * 1 minor change
76
+ * Added data error hash returned from twitter to a few of the exceptions to help with debugging
77
+ * Fixed friendship_exists?. Was throwing mash stringify keys error because it was returning true or false instead of hash or array.
78
+
79
+ 0.5.0 - April 3, 2009
80
+ * 1 major rewrite for OAuth
81
+ * Backwards compatibility thrown to the wind
82
+ * Proxy no longer supported (someone please add it back in, I never use proxies)
83
+ * Identica support killed with an axe (nothing against them but I don't use it)
84
+ * CLI shot to death (will be reborn at a later date using oauth and its own gem)
85
+
86
+ 0.4.3 - February 21, 2009
87
+ * 1 minor enhancement
88
+ * verify_credentials now returns a Twitter::User rather than an hpricot doc
89
+
90
+ 0.4.2 - February 10, 2009
91
+ * 1 minor enhancement
92
+ * Adding the Social Graph API methods (Josh Owens)
93
+
94
+ 0.4.1 - January 1, 2009
95
+ * 4 minor enhancements and 2 bug fixes:
96
+ * Added better exception handling (Billy Gray)
97
+ * Added page to search (Michael Ivey)
98
+ * Adding an option to display tweets on CLI in reverse order (oldest first). (Cameron Booth)
99
+ * Added in_reply_to_status_id option for replying to statuses (anthonycrumley)
100
+ * Fixed a bug where the @config was improperly set (K. Adam Christensen)
101
+ * Fix verify_credentials to include a format (breaks in laconica). (dustin)
102
+
103
+ 0.4.0 - December 23, 2008
104
+ * 3 major changes
105
+ * Removed active support as dependency
106
+ * Removed CLI dependencies from install dependency list
107
+ (they are now only installed by you manually)
108
+ * Switched to echoe for gem managment
109
+
110
+ 0.3.7 - August 26, 2008
111
+ * Fixed source param not getting through
112
+
113
+ 0.3.6 - August 11, 2008
114
+ * Fixed a few more methods that required post.
115
+ * Refactored the remaining methods that were not using #request to use it.
116
+
117
+ 0.3.5 - August 4, 2008
118
+ * Removed sqlite-ruby 1.2.2 as a dependency due to install issues on linux
119
+
120
+ 0.3.4 - August 3, 2008
121
+ * Added search support
122
+
123
+ 0.3.3 - August 3, 2008
124
+ * Now has option for host when initializing to support identi.ca (Dustin Sallings)
125
+ * Twitter changed a bunch of methods to POST only so I updated those to now work
126
+
127
+ 0.3.2 - July 26, 2008
128
+ * added the CLI gems as dependencies for now until I separate out the CLI from the API wrapper
129
+ * cleaner CLI errors for no active account or no accounts at all
130
+ * remove sets a new active account if there are none
131
+ * added username and password optional arguments to add
132
+ * added import attempt on install and on anything that uses #current_account helper
133
+
134
+ 0.3.1 - July 23, 2008
135
+ * added open to CLI twitter open jnunemaker would open default browser to http://twitter.com/jnunemaker
136
+ * added -f to timeline and replies which ignores the since_id and shows all results
137
+ * added clear_config to remove all cached since id's and such
138
+ * Majorly pimped the output of timelines and replies.
139
+
140
+ 0.3.0 - July 22, 2008
141
+ * complete rewrite of CLI. Now supports multiple accounts and changing between them.
142
+ * added source, truncated, in_reply_to_status_id, in_reply_to_user_id, and favorited to Twitter::Status
143
+ * added protected to Twitter::User
144
+ * d CLI method now takes standard input like post
145
+ * Rewrote several methods that had since parameter to now use a hash instead. This makes it more flexible as API updates.
146
+ * Rewrote the methods that took lite or since as an argument to instead take a hash.
147
+ * added Twitter::Base#friendship_exists?
148
+ * added Twitter::Base#update_location
149
+ * added Twitter::Base#update_delivery_device
150
+ * added Twitter::Base#favorites
151
+ * added Twitter::Base#create_favorite
152
+ * added Twitter::Base#destroy_favorite
153
+ * added Twitter::Base#block
154
+ * added Twitter::Base#unblock
155
+
156
+ BACKWORDS COMPATIBILITY BREAK:
157
+ Any method that you have using lite or since as an argument
158
+ will no longer work with this version. Simply change to a
159
+ hash and you'll be fine. For example:
160
+
161
+ friends(true) would now be friends(:lite => true)
162
+
163
+ 0.2.7 - June 29, 2008
164
+ * added #rate_limit_status (Daniel Morrison)
165
+ * added source parameter option to Base#post
166
+ * added twittergem as source when posting from command line
167
+ * Twitter::RateExceeded raised when you hit your limit (Jim O'Leary)
168
+ * Twitter::Unavailable raised when twitter returns 503
169
+ * Twitter::CantConnect is now more descriptive as to what is the problem when it is raised during a request
170
+ * quoting your message when using twitter post on the command line is now optional (Benoit Caccinolo)
171
+ * aliased post to p on command line so it's shorter (Benoit Caccinolo)
172
+ * unescaped html and added some color in command line view (Miles Z. Sterrett)
173
+ * added gemspec (technoweenie, Miles Z. Sterrett)
174
+ * Fixed stack trace error on first command line operation (Matt Rose)
175
+ 0.2.6 - April 2, 2008
176
+ * found a more simple way of doing stdin without any extra gem dependencies
177
+ 0.2.5 - April 2, 2008
178
+ * Command line interface can now use stdin for posting (ideas and example code from Jeremy Friesen)
179
+ $ twitter post 'test without stdin' # => twitters: test without stdin
180
+ $ echo 'test with stdin' | twitter post 'and an argv[1]' # => twitters: test with stdin and an argv[1]
181
+ $ echo 'test with stdin without any argv[1]' | twitter post # => twitters: test with stdin without any argv[1]
182
+ 0.2.4 - Mar 31, 2008
183
+ * Added lite option to friends and followers, which doesn't include the user's current status (Daniel Morrison)
184
+ * Updated since option to use HTTP header, and added the option on timeline() and replies(). (Daniel Morrison)
185
+ 0.2.3 - Jan 16, 2008
186
+ * added d to command line interface twitter d jnunemaker 'hola' (Humbucker)
187
+ * added progress dots when posting for confirmation when twitter is running slow (Hendy Irawan)
188
+ 0.2.2 - added leave and follow which are new twitter api methods for turning notifications on and off
189
+ 0.2.0 - Aug 4, 2007
190
+ * added sent_messages
191
+ * alias direct_messages to received_messages
192
+ * added create_friendship
193
+ * added destroy_friendship
194
+ * added featured to retrieve the featured twitter users
195
+ * added replies
196
+ * added destroy to destroy a status by id
197
+ * added status to find a status by id
198
+ * added active support as an extra dependency
199
+ * implemented d method to send direct messages (jnewland)
200
+ * fixed since argument in direct_messages method (jnewland)
201
+ 0.1.1 - May 20, 2007
202
+ * hpricot 0.5+ now supported; just a bug fix (Ryan Waldron is the man!)
203
+ 0.1.0 - March 31, 2007
204
+ * added d method for creating direct messages (waiting for it to work as documented)
205
+ * added featured method for getting featured users statuses (waiting for it to work as documented)
206
+ * added direct_messages method
207
+ * added friends_for method
208
+ * added a few tests
209
+ * removed relative_created_at as it is deprecated
210
+ * separated out the call method into call, request and parse methods
211
+ 0.0.5 - just a bit of code cleanup
212
+ 0.0.4 - added :location, :description, :url, :profile_image_url to user class (Alex Payne)
213
+ 0.0.3 - added a bit more informative message when things go wrong
214
+ 0.0.2 - added the command line options i forgot to add (friend and follower); improved some docs
215
+ 0.0.1 - initial release
data/License ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 John Nunemaker
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Notes ADDED
@@ -0,0 +1,33 @@
1
+ *****************************************************************
2
+ * From Twitter API Docs, so I don't have to keep going to them. *
3
+ *****************************************************************
4
+
5
+ http://apiwiki.twitter.com/REST+API+Documentation
6
+
7
+ 200 OK: everything went awesome.
8
+ 304 Not Modified: there was no new data to return.
9
+ 400 Bad Request: your request is invalid, and we'll return an error message that tells you why. This is the status code returned if you've exceeded the rate limit (see below).
10
+ 401 Not Authorized: either you need to provide authentication credentials, or the credentials provided aren't valid.
11
+ 403 Forbidden: we understand your request, but are refusing to fulfill it. An accompanying error message should explain why.
12
+ 404 Not Found: either you're requesting an invalid URI or the resource in question doesn't exist (ex: no such user).
13
+ 500 Internal Server Error: we did something wrong. Please post to the group about it and the Twitter team will investigate.
14
+ 502 Bad Gateway: returned if Twitter is down or being upgraded.
15
+ 503 Service Unavailable: the Twitter servers are up, but are overloaded with requests. Try again later.
16
+
17
+ **********
18
+ * Errors *
19
+ **********
20
+
21
+ <?xml version="1.0" encoding="UTF-8"?>
22
+ <hash>
23
+ <request>/direct_messages/destroy/456.xml</request>
24
+ <error>No direct message with that ID found.</error>
25
+ </hash>
26
+
27
+ **********************
28
+ * Rate Limit Headers *
29
+ **********************
30
+
31
+ X-RateLimit-Limit the current limit in effect
32
+ X-RateLimit-Remaining the number of hits remaining before you are rate limited
33
+ X-RateLimit-Reset the time the current rate limiting period ends (in epoch time, number of seconds since 1970-01-01 00:00:00)
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = twitter
2
+
3
+ The ruby twitter gem. The gem heard round the world and famous on the streets. Haha. This gem *works with both oauth and http auth*, if you care.
4
+
5
+ For now this is just an API wrapper. The command line interface is temporarily dead until I have time to make it work with oauth. At that point, I'll make it a new gem twitter-cli or something and it will depend on this gem to work. That will keep the separation of the api wrapper and cli and fix a lot of dependency issues.
6
+
7
+ == examples
8
+
9
+ See the examples directory.
10
+
11
+ http://github.com/jnunemaker/twitter/tree/master/examples
12
+
13
+ == docs
14
+
15
+ http://rdoc.info/projects/jnunemaker/twitter
16
+
17
+ == Copyright
18
+
19
+ Copyright (c) 2009 John Nunemaker. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,103 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "twitter"
8
+ gem.summary = %Q{wrapper for the twitter api (oauth only)}
9
+ gem.email = "nunemaker@gmail.com"
10
+ gem.homepage = "http://github.com/jnunemaker/twitter"
11
+ gem.authors = ["John Nunemaker"]
12
+ gem.rubyforge_project = "twitter"
13
+ gem.files = FileList["[A-Z]*", "{examples,lib,test}/**/*"]
14
+
15
+ gem.add_dependency('oauth', '>= 0.3.5')
16
+ gem.add_dependency('mash', '0.0.3')
17
+ gem.add_dependency('httparty', '0.4.3')
18
+
19
+ gem.add_development_dependency('thoughtbot-shoulda')
20
+ gem.add_development_dependency('jeremymcanally-matchy')
21
+ gem.add_development_dependency('mocha')
22
+ gem.add_development_dependency('fakeweb')
23
+ gem.add_development_dependency('mash')
24
+ end
25
+ rescue LoadError
26
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
27
+ end
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/*_test.rb'
33
+ test.verbose = false
34
+ end
35
+
36
+ begin
37
+ require 'rcov/rcovtask'
38
+ Rcov::RcovTask.new do |test|
39
+ test.libs << 'test'
40
+ test.pattern = 'test/**/*_test.rb'
41
+ test.verbose = true
42
+ end
43
+ rescue LoadError
44
+ task :rcov do
45
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
46
+ end
47
+ end
48
+
49
+
50
+ task :default => :test
51
+
52
+ require 'rake/rdoctask'
53
+ Rake::RDocTask.new do |rdoc|
54
+ if File.exist?('VERSION.yml')
55
+ config = YAML.load(File.read('VERSION.yml'))
56
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
57
+ else
58
+ version = ""
59
+ end
60
+
61
+ rdoc.rdoc_dir = 'rdoc'
62
+ rdoc.title = "twitter #{version}"
63
+ rdoc.rdoc_files.include('README*')
64
+ rdoc.rdoc_files.include('lib/**/*.rb')
65
+ end
66
+
67
+ begin
68
+ require 'rake/contrib/sshpublisher'
69
+ namespace :rubyforge do
70
+
71
+ desc "Release gem and RDoc documentation to RubyForge"
72
+ task :release => ["rubyforge:release:gem", "rubyforge:release:website", "rubyforge:release:docs"]
73
+
74
+ namespace :release do
75
+ desc "Publish RDoc to RubyForge."
76
+ task :docs => [:rdoc] do
77
+ config = YAML.load(
78
+ File.read(File.expand_path('~/.rubyforge/user-config.yml'))
79
+ )
80
+
81
+ host = "#{config['username']}@rubyforge.org"
82
+ remote_dir = "/var/www/gforge-projects/twitter/rdoc"
83
+ local_dir = 'rdoc'
84
+
85
+ Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
86
+ end
87
+
88
+ task :website do
89
+ config = YAML.load(
90
+ File.read(File.expand_path('~/.rubyforge/user-config.yml'))
91
+ )
92
+
93
+ host = "#{config['username']}@rubyforge.org"
94
+ remote_dir = "/var/www/gforge-projects/twitter/"
95
+ local_dir = 'website'
96
+
97
+ Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
98
+ end
99
+ end
100
+ end
101
+ rescue LoadError
102
+ puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
103
+ end
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 0
3
+ :minor: 6
4
+ :patch: 13
@@ -0,0 +1,30 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'twitter')
2
+ require File.join(File.dirname(__FILE__), 'helpers', 'config_store')
3
+ require 'pp'
4
+
5
+ config = ConfigStore.new("#{ENV['HOME']}/.twitter")
6
+ oauth = Twitter::OAuth.new(config['token'], config['secret'])
7
+
8
+ if config['atoken'] && config['asecret']
9
+ oauth.authorize_from_access(config['atoken'], config['asecret'])
10
+ twitter = Twitter::Base.new(oauth)
11
+ pp twitter.friends_timeline
12
+
13
+ elsif config['rtoken'] && config['rsecret']
14
+ oauth.authorize_from_request(config['rtoken'], config['rsecret'])
15
+ twitter = Twitter::Base.new(oauth)
16
+ pp twitter.friends_timeline
17
+
18
+ config.update({
19
+ 'atoken' => oauth.access_token.token,
20
+ 'asecret' => oauth.access_token.secret,
21
+ }).delete('rtoken', 'rsecret')
22
+ else
23
+ config.update({
24
+ 'rtoken' => oauth.request_token.token,
25
+ 'rsecret' => oauth.request_token.secret,
26
+ })
27
+
28
+ # authorize in browser
29
+ %x(open #{oauth.request_token.authorize_url})
30
+ end
@@ -0,0 +1,13 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'twitter')
2
+ require File.join(File.dirname(__FILE__), 'helpers', 'config_store')
3
+ require 'pp'
4
+
5
+ config = ConfigStore.new("#{ENV['HOME']}/.twitter")
6
+
7
+ oauth = Twitter::OAuth.new(config['token'], config['secret'])
8
+ oauth.authorize_from_access(config['atoken'], config['asecret'])
9
+
10
+ client = Twitter::Base.new(oauth)
11
+
12
+ puts client.friendship_exists?('jnunemaker', 'orderedlist')
13
+ puts client.friendship_exists?('jnunemaker', 'biz')