Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added more data to some of the exceptions to help with debugging.

  • Loading branch information...
commit 72d46c4804a30b28ab351a5a0d37d6bc664e577e 1 parent 6d7706c
@jnunemaker jnunemaker authored
View
1  .gitignore
@@ -3,3 +3,4 @@ pkg
log
doc
twitter-*.gem
+rdoc
View
6 History
@@ -1,4 +1,8 @@
-0.5.0 - March 3, 2009
+0.5.1 - April 5, 2009
+* 1 minor change
+ * Added data error hash returned from twitter to a few of the exceptions to help with debugging
+
+0.5.0 - April 3, 2009
* 1 major rewrite for OAuth
* Backwards compatibility thrown to the wind
* Proxy no longer supported (someone please add it back in, I never use proxies)
View
8 examples/connect.rb
@@ -7,20 +7,18 @@
if config['atoken'] && config['asecret']
oauth.authorize_from_access(config['atoken'], config['asecret'])
- # puts oauth.access_token.get("/statuses/friends_timeline.json")
twitter = Twitter::Base.new(oauth)
pp twitter.friends_timeline
elsif config['rtoken'] && config['rsecret']
oauth.authorize_from_request(config['rtoken'], config['rsecret'])
- puts oauth.access_token.get("/statuses/friends_timeline.json")
+ twitter = Twitter::Base.new(oauth)
+ pp twitter.friends_timeline
config.update({
'atoken' => oauth.access_token.token,
'asecret' => oauth.access_token.secret,
- 'rtoken' => nil,
- 'rsecret' => nil,
- })
+ }).delete('rtoken', 'rsecret')
else
config.update({
'rtoken' => oauth.request_token.token,
View
8 examples/helpers/config_store.rb
@@ -19,12 +19,20 @@ 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
22 lib/twitter.rb
@@ -7,12 +7,22 @@
end
module Twitter
- class RateLimitExceeded < StandardError; end
- class Unauthorized < StandardError; end
- class Unavailable < StandardError; end
- class InformTwitter < StandardError; end
- class NotFound < StandardError; end
- class General < StandardError; end
+ class TwitterError < StandardError
+ attr_reader :data
+
+ def initialize(data)
+ @data = data
+ super
+ end
+ end
+
+ class RateLimitExceeded < TwitterError; end
+ class Unauthorized < TwitterError; end
+ class General < TwitterError; end
+
+ class Unavailable < StandardError; end
+ class InformTwitter < StandardError; end
+ class NotFound < StandardError; end
def self.firehose
View
8 lib/twitter/request.rb
@@ -51,11 +51,13 @@ def make_friendly(response)
def raise_errors(response)
case response.code.to_i
when 400
- raise RateLimitExceeded, "(#{response.code}): #{response.message}"
+ raise RateLimitExceeded.new(parse(response)), "(#{response.code}): #{response.message} - #{data['error']}"
when 401
- raise Unauthorized, "(#{response.code}): #{response.message}"
+ data = parse(response)
+ raise Unauthorized.new(data), "(#{response.code}): #{response.message} - #{data['error']}"
when 403
- raise General, "(#{response.code}): #{response.message}"
+ data = parse(response)
+ raise General.new(data), "(#{response.code}): #{response.message} - #{data['error']}"
when 404
raise NotFound, "(#{response.code}): #{response.message}"
when 500
Please sign in to comment.
Something went wrong with that request. Please try again.