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

Instance Method Details

#create_project(name, description = '') ⇒ Project

Create a project

Examples:

client.create_project("Marketing Campaign")
client.create_project('Better Marketing Campaign', "For Client: XYZ")

Parameters:

  • name (String)

    name of the project to create

  • description (String) (defaults to: '')

    description of the project

Returns:

Raises:

See Also:



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

Examples:

client.delete_project(12324)
client.delete_project('157432')
client.delete_project(my_project)

Parameters:

  • project (Integer|String|Project)

    either a project object or a project id

Raises:

See Also:



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

Examples:

client.project(82564)
client.project('7364183')

Parameters:

  • id (Integet|String)

    id of the project to retrieve

Returns:

Raises:

See Also:



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

Examples:

client.projects
client.projects(status: 'trashed')

Parameters:

  • options (Hash) (defaults to: {})

    extra options to filter the list of todolist

Returns:

See Also:



18
19
20
# File 'lib/camper/api/projects.rb', line 18

def projects(options = {})
  get('/projects', query: options)
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

Examples:

client.update_project(12324, name: 'Retros')
client.update_project('157432', description: 'A new description')
client.update_project('157432', description: '')
client.update_project(my_project, name: 'A new name', description: 'A new description')

Parameters:

  • project (Integer|String|Project)

    either a project object or a project id

  • name (String) (defaults to: '')

    optional new name of the project

  • description (String) (defaults to: nil)

    optinal new description of the project

Returns:

Raises:

See Also:



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

  options = {}
  options[:name] = name unless name.blank?
  options[:description] = description unless description.nil?

  put("/projects/#{id}", body: { **options })
end