Class: GridCLI::BefriendCommand

Inherits:
BaseCommand show all
Defined in:
lib/gridcli/commands/befriend.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

#initializeBefriendCommand

Returns a new instance of BefriendCommand.



3
4
5
6
7
8
# File 'lib/gridcli/commands/befriend.rb', line 3

def initialize
  super "befriend", "Request friendship with someone"
  add_option("--message message", "-m message", "Add a person message to the request.") { |m|
    @opts[:message] = m
  }
end

Instance Method Details

#run(args) ⇒ Object



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

def run(args)
  # handle options
  usage if args.length == 0
  username = args.shift
  parse_opts args

  begin
    log "Trying to create new friendship with '#{username}'"
    Friendship.new(:username => username).save
    puts "Friendship request sent."
  rescue ActiveResource::ForbiddenAccess
    puts "Looks like '#{username}' doesn't want to be your friend."
  rescue ActiveResource::ResourceConflict
    puts "You are already friends with '#{username}'"
  rescue ActiveResource::ResourceNotFound
    puts "Sorry, can't find a user with name '#{username}'"
  end
end

#usageObject



10
11
12
# File 'lib/gridcli/commands/befriend.rb', line 10

def usage
  super "<username>"
end