Class: TwitterClone::Client
- Inherits:
-
Object
- Object
- TwitterClone::Client
- Defined in:
- lib/twitter_clone_client.rb
Constant Summary collapse
- SUB_COMMANDS =
%w(show create delete)
Instance Method Summary collapse
- #create ⇒ Object
- #delete ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #show ⇒ Object
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/twitter_clone_client.rb', line 22 def initialize @opts = Trollop:: do "Twitter clone RESTful client" version "0.0.1" stop_on SUB_COMMANDS end @cmd = ARGV.shift # get the subcommand @cmd_opts = case @cmd when "show" Trollop:: do opt :user, "User name or id that you want to show tweets for", :type => :string end when "create" Trollop:: do opt :login, "Login", :type => :string, :required => true opt :password, "Password", :type => :string, :required => true opt :text, "Your status", :type => :string, :required => true end when "delete" Trollop:: do opt :login, "Login", :type => :string, :required => true opt :password, "Password", :type => :string, :required => true opt :id, "ID of the tweet you want to delete", :type => :int, :required => true end else Trollop::die "unknown subcommand #{@cmd.inspect}" end self.send(@cmd) # execute the subcommand end |
Instance Method Details
#create ⇒ Object
67 68 69 70 71 |
# File 'lib/twitter_clone_client.rb', line 67 def create setup_credentials Status.create(:body => @cmd_opts[:text], :user_id => @cmd_opts[:login]) puts "Status created successfully" end |
#delete ⇒ Object
73 74 75 76 77 |
# File 'lib/twitter_clone_client.rb', line 73 def delete setup_credentials Status.delete(@cmd_opts[:id], :user_id => @cmd_opts[:login]) puts "Status destroy successfully" end |
#show ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/twitter_clone_client.rb', line 54 def show if @cmd_opts[:user] params = {:user_id => @cmd_opts[:user]} else params = {} Status.prefix = "/" end @statuses = Status.find(:all, :params => params) @statuses.each do |status| puts status end end |