Class: Basecamp::Services::ProjectsService

Inherits:
BaseService
  • Object
show all
Defined in:
lib/basecamp/generated/services/projects_service.rb

Overview

Service for Projects operations

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from Basecamp::Services::BaseService

Instance Method Details

#archive(project_id:) ⇒ void

This method returns an undefined value.

Archive a project, removing it from the active project list (returns 204 No Content).

Parameters:

  • project_id (Integer)

    project id ID



77
78
79
80
81
82
# File 'lib/basecamp/generated/services/projects_service.rb', line 77

def archive(project_id:)
  with_operation(service: "projects", operation: "archive", is_mutation: true, project_id: project_id) do
    http_put("/projects/#{project_id}/status/archived.json")
    nil
  end
end

#create(name:, description: nil) ⇒ Hash

Create a new project

Parameters:

  • name (String)

    name

  • description (String, nil) (defaults to: nil)

    description

Returns:

  • (Hash)

    response data



26
27
28
29
30
# File 'lib/basecamp/generated/services/projects_service.rb', line 26

def create(name:, description: nil)
  with_operation(service: "projects", operation: "create", is_mutation: true) do
    http_post("/projects.json", body: compact_params(name: name, description: description)).json
  end
end

#get(project_id:) ⇒ Hash

Get a single project by id

Parameters:

  • project_id (Integer)

    project id ID

Returns:

  • (Hash)

    response data



35
36
37
38
39
# File 'lib/basecamp/generated/services/projects_service.rb', line 35

def get(project_id:)
  with_operation(service: "projects", operation: "get", is_mutation: false, project_id: project_id) do
    http_get("/projects/#{project_id}", operation: "GetProject").json
  end
end

#list(status: nil, page: nil, max_items: nil) ⇒ ListEnumerator<Hash>

List projects (active by default; optionally archived/trashed)

Parameters:

  • status (String, nil) (defaults to: nil)

    active|archived|trashed

  • page (Integer, nil) (defaults to: nil)

    Page number for paginating through results. Defaults to 1. A positive value selects exactly that page, not a starting offset; see SPEC section 8.

  • max_items (Integer, nil) (defaults to: nil)

    cap on items yielded across pages; nil or non-positive means no cap

Returns:

  • (ListEnumerator<Hash>)

    lazily paginated results (#meta carries pagination metadata)



15
16
17
18
19
20
# File 'lib/basecamp/generated/services/projects_service.rb', line 15

def list(status: nil, page: nil, max_items: nil)
  wrap_paginated(service: "projects", operation: "list", is_mutation: false) do
    params = compact_query_params(status: status, page: page)
    paginate("/projects.json", params: params, operation: "ListProjects", max_items: max_items)
  end
end

#trash(project_id:) ⇒ void

This method returns an undefined value.

Trash a project (returns 204 No Content)

Parameters:

  • project_id (Integer)

    project id ID



57
58
59
60
61
62
# File 'lib/basecamp/generated/services/projects_service.rb', line 57

def trash(project_id:)
  with_operation(service: "projects", operation: "trash", is_mutation: true, project_id: project_id) do
    http_delete("/projects/#{project_id}")
    nil
  end
end

#unarchive(project_id:) ⇒ void

This method returns an undefined value.

Restore a project to active status from trash as well as from the archive (returns 204 No Content).

Parameters:

  • project_id (Integer)

    project id ID



67
68
69
70
71
72
# File 'lib/basecamp/generated/services/projects_service.rb', line 67

def unarchive(project_id:)
  with_operation(service: "projects", operation: "unarchive", is_mutation: true, project_id: project_id) do
    http_put("/projects/#{project_id}/status/active.json")
    nil
  end
end

#update(project_id:, name:, description: nil, admissions: nil, schedule_attributes: nil) ⇒ Hash

Update an existing project

Parameters:

  • project_id (Integer)

    project id ID

  • name (String)

    name

  • description (String, nil) (defaults to: nil)

    description

  • admissions (String, nil) (defaults to: nil)

    invite|employee|team

  • schedule_attributes (Hash, nil) (defaults to: nil)

    schedule attributes

Returns:

  • (Hash)

    response data



48
49
50
51
52
# File 'lib/basecamp/generated/services/projects_service.rb', line 48

def update(project_id:, name:, description: nil, admissions: nil, schedule_attributes: nil)
  with_operation(service: "projects", operation: "update", is_mutation: true, project_id: project_id) do
    http_put("/projects/#{project_id}", body: compact_params(name: name, description: description, admissions: admissions, schedule_attributes: schedule_attributes)).json
  end
end