Class: Cuiabout::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/cuiabout.rb

Constant Summary collapse

ROOT_PATH =
'http://cui-about.me'

Class Method Summary collapse

Class Method Details

.list(*args) ⇒ Object



27
28
29
# File 'lib/cuiabout.rb', line 27

def list *args
  system "curl #{ROOT_PATH}/users"
end

.method_missing(method_or_name, *args) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/cuiabout.rb', line 62

def method_missing method_or_name, *args
  if listed? method_or_name
    show method_or_name
  else
    abort 'ERROR: Unknown command'
  end
end

.run(*args) ⇒ Object



10
11
12
13
# File 'lib/cuiabout.rb', line 10

def run *args
  command = args.shift || 'usage'
  send(command, *args)
end

.show(*args) ⇒ Object



31
32
33
34
35
36
# File 'lib/cuiabout.rb', line 31

def show *args
  abort "ERROR: Please specify user's name" if args.empty?

  name = args.shift
  system "curl #{ROOT_PATH}/#{name}"
end

.signup(*args) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cuiabout.rb', line 38

def  *args
  abort 'ERROR: Please specify your name' if args.empty?

  name = args.shift
  password = ask_password
  data = "name=#{name}&password=#{password}"
  args.each do |arg|
    data += "&#{arg}"
  end
  system "curl -X POST -d '#{data}' #{ROOT_PATH}/signup"
end

.update(*args) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/cuiabout.rb', line 50

def update *args
  abort 'ERROR: Please specify your name' if args.empty?

  name = args.shift
  password = ask_password
  data = "password=#{password}"
  args.each do |arg|
    data += "&#{arg}"
  end
  system "curl -X PUT -d '#{data}' #{ROOT_PATH}/#{name}"
end

.usage(*args) ⇒ Object Also known as: help, me



15
16
17
18
19
20
21
22
23
# File 'lib/cuiabout.rb', line 15

def usage *args
  puts %(
Usage: cuiabout ACTION

  cuiabout [username]       # Prints user's profile
  cuiabout show [username]  # Prints user's profile
  cuiabout list             # Prints all user names
  )
end