Skip to content

Commit

Permalink
Added more data to some of the exceptions to help with debugging.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnunemaker committed Apr 5, 2009
1 parent 6d7706c commit 72d46c4
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pkg
log
doc
twitter-*.gem
rdoc
6 changes: 5 additions & 1 deletion History
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
8 changes: 3 additions & 5 deletions examples/connect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions examples/helpers/config_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 16 additions & 6 deletions lib/twitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions lib/twitter/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 72d46c4

Please sign in to comment.