You will need to handle the exceptions that are raised by the API. If
you are new to Ruby you should refer to the following Ruby exception
handling documentation:
http://ruby.activeventure.com/programmingruby/book/tut_exceptions.html
For example, you might do something like this around authenticated
calls to the Twitter::Client object you create:
begin
client.status(:post, "Jane Eyre rocks!")
rescue Twitter::RESTError => re
puts re.inspect
# try to resolve error by inspecting the code of the RESTError or something
end
Of course, you can create a helper method that takes a block that will
clean up after common errors, so you do not need to open up
begin/rescue blocks all the time in your code. Something roughly
like:
def twitter_block(&block)
begin
rescue Twitter::RESTError => re
case re.code
when '400'
# usually means you made too many API calls in a time period and
Twitter.com blocked you, so report that appropriately to your
end-users
when '503'
# means that Twitter.com is down
when '401'
# means you have the wrong credentials - check your login/password combo
when '403'
# means you are trying to do something that Twitter.com will not allow
# e.g. direct messaging a user that isn't your friend or something
end
end
end
HTH,
Susan
> def twitter_block(&block)
> begin
> block.call if block_given? # line that was added to make sense
> rescue Twitter::RESTError => re
> case re.code
> when '400'
> # usually means you made too many API calls in a time period and
> Twitter.com blocked you, so report that appropriately to your
> end-users
> when '503'
> # means that Twitter.com is down
> when '401'
> # means you have the wrong credentials - check your login/password combo
> when '403'
> # means you are trying to do something that Twitter.com will not allow
> # e.g. direct messaging a user that isn't your friend or something
> end
> end
> end
--
mailto:m...@susanpotter.net
www:http://susanpotter.net
blog:http://snakesgemscoffee.susanpotter.net
linkedin:http://www.linkedin.com/in/susanpotter