Class: Basecamp::Services::TemplatesService

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

Overview

Service for Templates operations

Instance Method Summary collapse

Constructor Details

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

Instance Method Details

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

Create a new template

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/templates_service.rb', line 26

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

#create_project(template_id:, project:) ⇒ Hash

Create a project from a template (asynchronous)

Parameters:

  • template_id (Integer)

    template id ID

  • project (Hash)

    project

Returns:

  • (Hash)

    response data



66
67
68
69
70
# File 'lib/basecamp/generated/services/templates_service.rb', line 66

def create_project(template_id:, project:)
  with_operation(service: "templates", operation: "create_project", is_mutation: true, resource_id: template_id) do
    http_post("/templates/#{template_id}/project_constructions.json", body: compact_params(project: project)).json
  end
end

#delete(template_id:) ⇒ void

This method returns an undefined value.

Delete a template (trash it)

Parameters:

  • template_id (Integer)

    template id ID



55
56
57
58
59
60
# File 'lib/basecamp/generated/services/templates_service.rb', line 55

def delete(template_id:)
  with_operation(service: "templates", operation: "delete", is_mutation: true, resource_id: template_id) do
    http_delete("/templates/#{template_id}")
    nil
  end
end

#get(template_id:) ⇒ Hash

Get a single template by id

Parameters:

  • template_id (Integer)

    template id ID

Returns:

  • (Hash)

    response data



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

def get(template_id:)
  with_operation(service: "templates", operation: "get", is_mutation: false, resource_id: template_id) do
    http_get("/templates/#{template_id}", operation: "GetTemplate").json
  end
end

#get_construction(template_id:, construction_id:) ⇒ Hash

Get the status of a project construction

Parameters:

  • template_id (Integer)

    template id ID

  • construction_id (Integer)

    construction id ID

Returns:

  • (Hash)

    response data



76
77
78
79
80
# File 'lib/basecamp/generated/services/templates_service.rb', line 76

def get_construction(template_id:, construction_id:)
  with_operation(service: "templates", operation: "get_construction", is_mutation: false, resource_id: construction_id) do
    http_get("/templates/#{template_id}/project_constructions/#{construction_id}", operation: "GetProjectConstruction").json
  end
end

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

List all templates visible to the current user

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/templates_service.rb', line 15

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

#update(template_id:, name: nil, description: nil) ⇒ Hash

Update an existing template

Parameters:

  • template_id (Integer)

    template id ID

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

    name

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

    description

Returns:

  • (Hash)

    response data



46
47
48
49
50
# File 'lib/basecamp/generated/services/templates_service.rb', line 46

def update(template_id:, name: nil, description: nil)
  with_operation(service: "templates", operation: "update", is_mutation: true, resource_id: template_id) do
    http_put("/templates/#{template_id}", body: compact_params(name: name, description: description)).json
  end
end