class Agile::Projects

Public Instance Methods

create(project_name) click to toggle source
# File lib/agile/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
list() click to toggle source
# File lib/agile/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) click to toggle source
# File lib/agile/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) click to toggle source
# File lib/agile/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) click to toggle source
# File lib/agile/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

Private Instance Methods

error_checking_projects() click to toggle source
# File lib/agile/commands/projects.rb, line 78
def error_checking_projects
  abort "You haven't done init yet!" unless CONFIG["current_remote"]
  abort "Please, log in!" unless CONFIG["current_user"]
end
update_description(project) click to toggle source
# File lib/agile/commands/projects.rb, line 69
def update_description(project)
  choice = HighLine.new
  new_description = choice.ask("Enter new description for project: ", String)
  RestClient.put "#{CONFIG['current_remote']}/api/v1/projects/#{project}",
                 name: project, new_description: new_description,
                 current_user: CONFIG["current_user"]
  say "Updated description to #{new_description}"
end
update_name(project) click to toggle source
# File lib/agile/commands/projects.rb, line 60
def update_name(project)
  choice = HighLine.new
  new_project = choice.ask("Enter new name of project: ", String)
  RestClient.put "#{CONFIG['current_remote']}/api/v1/projects/#{project}",
                 name: project, new_name: new_project, type: 1,
                 current_user: CONFIG["current_user"]
  say "Updated from #{project} to #{new_project}"
end
write_to_config(id_pr, project) click to toggle source
# File lib/agile/commands/projects.rb, line 95
def write_to_config(id_pr, project)
  CONFIG["current_project_id"] = id_pr.first
  CONFIG["current_project"] = project
  File.write("#{GEM_PATH}.config.json", JSON.generate(CONFIG))
end