Class: GridCLI::FriendsCommand

Inherits:
BaseCommand show all
Defined in:
lib/gridcli/commands/friends.rb

Instance Attribute Summary

Attributes inherited from BaseCommand

#cmd, #desc

Instance Method Summary collapse

Methods inherited from BaseCommand

#add_format_option, #add_option, #error, #log, #output_format, #parse_dates, #parse_opts, #pop_arg, #pprint

Constructor Details

#initializeFriendsCommand

Returns a new instance of FriendsCommand.



3
4
5
6
# File 'lib/gridcli/commands/friends.rb', line 3

def initialize
  super "friends", "List your friends or the friends of a friend"
  add_format_option
end

Instance Method Details

#run(args) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/gridcli/commands/friends.rb', line 12

def run(args)
  # handle options
  username = (args.length == 0 or args.first.start_with?('-')) ? @config['username'] : args.shift
  parse_opts args

  begin
    log "Getting all friends of '#{username}'"
    friends = Friendship.find(:all, :params => { :id => username })
    friends.each { |f|
      pprint f.user.to_json
    }
    puts "#{username} has no friends :(" if friends.length == 0
  rescue ActiveResource::ForbiddenAccess
    puts "Looks like '#{username}' isn't one of your friends, so you can't view #{username}'s friends."
  rescue ActiveResource::ClientError
    puts "Sorry, can't find a user with name '#{username}'"
  end
end

#usageObject



8
9
10
# File 'lib/gridcli/commands/friends.rb', line 8

def usage
  super "[<username>]"
end