Module: Camper::Client::ProjectsAPI
- Included in:
- Camper::Client
- Defined in:
- lib/camper/api/projects.rb
Overview
Defines methods related to projects.
Instance Method Summary collapse
-
#create_project(name, description = '') ⇒ Project
Create a project.
-
#delete_project(project) ⇒ Object
(also: #trash_project)
Delete a project.
-
#project(id) ⇒ Project
Get a project with a given id, granted they have access to it.
-
#projects(options = {}) ⇒ PaginatedResponse<Project>
Get the projects visible to the current user.
- #todoset(project) ⇒ Object
-
#update_project(project, name: '', description: nil) ⇒ Project
Update a project description can be set to empty by passing an empty string.
Instance Method Details
#create_project(name, description = '') ⇒ Project
Create a project
51 52 53 54 55 |
# File 'lib/camper/api/projects.rb', line 51 def create_project(name, description = '') raise Error::InvalidParameter, name if name.blank? post('/projects', body: { name: name, description: description }) end |
#delete_project(project) ⇒ Object Also known as: trash_project
Delete a project
104 105 106 107 108 109 110 |
# File 'lib/camper/api/projects.rb', line 104 def delete_project(project) raise Error::InvalidParameter, 'project cannot be blank' if project.blank? id = project.respond_to?(:id) ? project.id : project delete("/projects/#{id}") end |
#project(id) ⇒ Project
Get a project with a given id, granted they have access to it
33 34 35 36 37 |
# File 'lib/camper/api/projects.rb', line 33 def project(id) raise Error::InvalidParameter, id if id.blank? get("/projects/#{id}") end |
#projects(options = {}) ⇒ PaginatedResponse<Project>
Get the projects visible to the current user
18 19 20 |
# File 'lib/camper/api/projects.rb', line 18 def projects( = {}) get('/projects', query: ) end |
#todoset(project) ⇒ Object
114 115 116 117 |
# File 'lib/camper/api/projects.rb', line 114 def todoset(project) todoset = project.todoset get(todoset.url, override_path: true) end |
#update_project(project, name: '', description: nil) ⇒ Project
Update a project
description can be set to empty by passing an empty string
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/camper/api/projects.rb', line 75 def update_project(project, name: '', description: nil) # rubocop:disable Style/IfUnlessModifier: if name.blank? && description.blank? raise Error::InvalidParameter, 'name and description cannot both be blank' end # rubocop:enable Style/IfUnlessModifier id = project.respond_to?(:id) ? project.id : project = {} [:name] = name unless name.blank? [:description] = description unless description.nil? put("/projects/#{id}", body: { ** }) end |