Module: Insightly2::DSL::Projects

Included in:
Insightly2::DSL
Defined in:
lib/insightly2/dsl/projects.rb

Instance Method Summary collapse

Instance Method Details

#create_project(project: nil) ⇒ Insightly2::Resources::Project?

POST /v2.1/Projects Create a project.

Parameters:

  • project (Hash) (defaults to: nil)

    The project to create.

Returns:

Raises:

  • (ArgumentError)

    If the method arguments are blank.



70
71
72
73
# File 'lib/insightly2/dsl/projects.rb', line 70

def create_project(project: nil)
  raise ArgumentError, "Project cannot be blank" if project.blank?
  Resources::Project.parse(request(:post, "Projects", project))
end

#create_project_image(id: nil, filename: nil) ⇒ Faraday::Response

POST /v2.1/Projects/c_id/Image/filename Create a project image.

Parameters:

  • id (String, Fixnum) (defaults to: nil)

    A project’s ID.

  • filename (String) (defaults to: nil)

    A Project image file name.

Returns:

  • (Faraday::Response)

    .

Raises:

  • (ArgumentError)

    If the method arguments are blank.



81
82
83
84
85
# File 'lib/insightly2/dsl/projects.rb', line 81

def create_project_image(id: nil, filename: nil)
  raise ArgumentError, "ID cannot be blank" if id.blank?
  raise ArgumentError, "Filename cannot be blank" if filename.blank?
  request(:post, "Projects/#{id}/Image/#{filename}")
end

#delete_project(id: nil) ⇒ Faraday::Response

DELETE /v2.1/Projects/id Delete a project.

Parameters:

  • id (String, Fixnum) (defaults to: nil)

    A project’s ID.

Returns:

  • (Faraday::Response)

    .

Raises:

  • (ArgumentError)

    If the method arguments are blank.



114
115
116
117
# File 'lib/insightly2/dsl/projects.rb', line 114

def delete_project(id: nil)
  raise ArgumentError, "ID cannot be blank" if id.blank?
  request(:delete, "Projects/#{id}")
end

#delete_project_image(id: nil) ⇒ Faraday::Response

DELETE /v2.1/Projects/c_id/Image Delete a project image.

Parameters:

  • id (String, Fixnum) (defaults to: nil)

    A project’s ID.

Returns:

  • (Faraday::Response)

    .

Raises:

  • (ArgumentError)

    If the method arguments are blank.



124
125
126
127
# File 'lib/insightly2/dsl/projects.rb', line 124

def delete_project_image(id: nil)
  raise ArgumentError, "ID cannot be blank" if id.blank?
  request(:delete, "Projects/#{id}/Image")
end

#get_project(id: nil) ⇒ Insightly2::Resources::Project?

GET /v2.1/Projects/id Get a project.

Parameters:

  • id (String, Fixnum) (defaults to: nil)

    A project’s ID.

Returns:

Raises:

  • (ArgumentError)

    If the method arguments are blank.



10
11
12
13
# File 'lib/insightly2/dsl/projects.rb', line 10

def get_project(id: nil)
  raise ArgumentError, "ID cannot be blank" if id.blank?
  Resources::Project.parse(request(:get, "Projects/#{id}"))
end

#get_project_emails(id: nil) ⇒ Array?

GET /v2.1/Projects/c_id/Emails Get a list of project emails.

Parameters:

  • id (String, Fixnum) (defaults to: nil)

    A project’s ID.

Returns:

  • (Array, nil)

    .

Raises:

  • (ArgumentError)

    If the method arguments are blank.



20
21
22
23
# File 'lib/insightly2/dsl/projects.rb', line 20

def get_project_emails(id: nil)
  raise ArgumentError, "ID cannot be blank" if id.blank?
  Resources::Email.parse(request(:get, "Projects/#{id}/Emails"))
end

#get_project_image(id: nil) ⇒ Faraday::Response

GET /v2.1/Projects/c_id/Image Get a project image.

Parameters:

  • id (String, Fixnum) (defaults to: nil)

    A project’s ID.

Returns:

  • (Faraday::Response)

    .

Raises:

  • (ArgumentError)

    If the method arguments are blank.



30
31
32
33
# File 'lib/insightly2/dsl/projects.rb', line 30

def get_project_image(id: nil)
  raise ArgumentError, "ID cannot be blank" if id.blank?
  request(:get, "Projects/#{id}/Image")
end

#get_project_notes(id: nil) ⇒ Array?

GET /v2.1/Projects/c_id/Notes Get a projects notes.

Parameters:

  • id (String, Fixnum) (defaults to: nil)

    A project’s ID.

Returns:

  • (Array, nil)

    .

Raises:

  • (ArgumentError)

    If the method arguments are blank.



40
41
42
43
# File 'lib/insightly2/dsl/projects.rb', line 40

def get_project_notes(id: nil)
  raise ArgumentError, "ID cannot be blank" if id.blank?
  Resources::Note.parse(request(:get, "Projects/#{id}/Notes"))
end

#get_project_tasks(id: nil) ⇒ Array?

GET /v2.1/Projects/c_id/Tasks Get a project tasks.

Parameters:

  • id (String, Fixnum) (defaults to: nil)

    A project’s ID.

Returns:

  • (Array, nil)

    .

Raises:

  • (ArgumentError)

    If the method arguments are blank.



50
51
52
53
# File 'lib/insightly2/dsl/projects.rb', line 50

def get_project_tasks(id: nil)
  raise ArgumentError, "ID cannot be blank" if id.blank?
  Resources::Task.parse(request(:get, "Projects/#{id}/Tasks"))
end

#get_projects(ids: [], tag: '') ⇒ Array?

GET /v2.1/Projects?ids=ids&tag=tag Get a list of projects.

Parameters:

  • ids (Array) (defaults to: [])

    The IDs of the projects to retrieve (optional).

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

    The tag that is applied to the projects (optional).

Returns:

  • (Array, nil)

    .



60
61
62
63
# File 'lib/insightly2/dsl/projects.rb', line 60

def get_projects(ids: [], tag: '')
  url = Utils::UrlHelper.build_url(path: "Projects", params: {ids: ids.join(','), tag: tag})
  Resources::Project.parse(request(:get, url))
end

#update_project(project: nil) ⇒ Insightly2::Resources::Project?

PUT /v2.1/Projects Update a project.

Parameters:

  • project (Hash) (defaults to: nil)

    The project to update.

Returns:

Raises:

  • (ArgumentError)

    If the method arguments are blank.



92
93
94
95
# File 'lib/insightly2/dsl/projects.rb', line 92

def update_project(project: nil)
  raise ArgumentError, "Project cannot be blank" if project.blank?
  Resources::Project.parse(request(:put, "Projects", project))
end

#update_project_image(id: nil, filename: nil) ⇒ Faraday::Response

PUT /v2.1/Projects/c_id/Image/filename Update a project’s image.

Parameters:

  • id (String, Fixnum) (defaults to: nil)

    A project’s ID.

  • filename (String) (defaults to: nil)

    A project image file name.

Returns:

  • (Faraday::Response)

    .

Raises:

  • (ArgumentError)

    If the method arguments are blank.



103
104
105
106
107
# File 'lib/insightly2/dsl/projects.rb', line 103

def update_project_image(id: nil, filename: nil)
  raise ArgumentError, "ID cannot be blank" if id.blank?
  raise ArgumentError, "Filename cannot be blank" if filename.blank?
  request(:put, "Projects/#{id}/Image/#{filename}")
end