Class: Willpower::Projects

Inherits:
Thor
  • Object
show all
Defined in:
lib/willpower/commands/projects.rb

Instance Method Summary collapse

Instance Method Details

#create(project_name) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/willpower/commands/projects.rb', line 4

def create(project_name)
  error_checking_projects
  response = RestClient.post "#{CONFIG['current_remote']}/api/v1/projects/",
                             name: project_name, current_user: CONFIG["current_user"]
  if response.body
    say "Successfully created project #{project_name}"
  else
    say "Try again"
  end
end

#listObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/willpower/commands/projects.rb', line 16

def list
  error_checking_projects
  response = RestClient.get "#{CONFIG['current_remote']}/api/v1/userproject/#{CONFIG['current_user']}"
  say Rainbow("<<Your Projects>>").cornflower
  JSON.parse(response).each do |proj|
    if proj["name"] == CONFIG["current_project"]
      say "* #{proj['name']}"
    else
      say proj["name"]
    end
  end
end

#show(project) ⇒ Object



30
31
32
33
34
35
# File 'lib/willpower/commands/projects.rb', line 30

def show(project)
  response = RestClient.get "#{CONFIG['current_remote']}/api/v1/projects/#{project}"
  row = JSON.parse(response)
  say "Project: #{row['data']['attributes']['name']}"
  say "Description: #{row['data']['attributes']['description']}"
end

#update(project) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/willpower/commands/projects.rb', line 45

def update(project)
  error_checking_projects
  choice = HighLine.new
  answer = choice.ask("Choose what you want to edit: name or description (N or D): ", String)
  if answer == "N"
    update_name(project)
  elsif answer == "D"
    update_description(project)
  else
    say "Try again"
  end
end

#use(project) ⇒ Object



38
39
40
41
42
# File 'lib/willpower/commands/projects.rb', line 38

def use(project)
  error_checking_projects
  response = RestClient.get "#{CONFIG['current_remote']}/api/v1/projects/"
  project_search(response, project)
end