lib/twitter_clone_client.rb in SRUG-twitter-clone-client-0.1.2 vs lib/twitter_clone_client.rb in SRUG-twitter-clone-client-0.1.3

- old
+ new

@@ -5,12 +5,12 @@ require 'activeresource' module TwitterClone class Status < ActiveResource::Base - self.site = "http://localhost:3000/" - Status.prefix = "/users/:user_id/" + self.site = "http://localhost:3000/" + self.prefix = "/users/:user_id/" def to_s "#{user.login}:\t #{body} at #{created_at}" end end @@ -20,11 +20,10 @@ SUB_COMMANDS = %w(show create delete) def initialize @opts = Trollop::options do banner "Twitter clone RESTful client" - version "0.0.1" stop_on SUB_COMMANDS end @cmd = ARGV.shift # get the subcommand @cmd_opts = case @cmd @@ -64,17 +63,25 @@ end end def create setup_credentials - Status.create(:body => @cmd_opts[:text], :user_id => @cmd_opts[:login]) - puts "Status created successfully" + begin + Status.create(:body => @cmd_opts[:text], :user_id => @cmd_opts[:login]) + puts "Status created successfully" + rescue ActiveResource::UnauthorizedAccess => e + puts e.message and exit + end end def delete setup_credentials - Status.delete(@cmd_opts[:id], :user_id => @cmd_opts[:login]) - puts "Status destroy successfully" + begin + Status.delete(@cmd_opts[:id], :user_id => @cmd_opts[:login]) + puts "Status destroy successfully" + rescue ActiveResource::UnauthorizedAccess => e + puts e.message and exit + end end private def setup_credentials if @cmd_opts[:login] && @cmd_opts[:password]