Module: Insightly2::DSL::Emails

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

Instance Method Summary collapse

Instance Method Details

#create_email_comment(id: nil, comment: nil) ⇒ Faraday::Response

POST /v2.1/Emails/c_id/Comments Create a comment for a task.

Parameters:

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

    A task’s ID.

  • comment (Hash) (defaults to: nil)

    The comment to create.

Returns:

  • (Faraday::Response)

    .

Raises:

  • (ArgumentError)

    If the method arguments are blank.



41
42
43
44
45
# File 'lib/insightly2/dsl/emails.rb', line 41

def create_email_comment(id: nil, comment: nil)
  raise ArgumentError, "ID cannot be blank" if id.blank?
  raise ArgumentError, "Comment cannot be blank" if comment.blank?
  request(:post, "Emails/#{id}/Comments", comment)
end

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

DELETE /v2.1/Emails/id Deletes an email.

Parameters:

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

    The ID of the email to delete.

Returns:

  • (Faraday::Response)

    .

Raises:

  • (ArgumentError)

    If the method arguments are blank.



52
53
54
55
# File 'lib/insightly2/dsl/emails.rb', line 52

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

#get_email(id: nil) ⇒ Insightly2::Resources::Email?

GET /v2.1/Emails/id Gets an email.

Parameters:

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

    The ID of the email.

Returns:

Raises:

  • (ArgumentError)

    If the method arguments are blank.



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

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

#get_email_comments(id: nil) ⇒ Array?

GET /v2.1/Emails/c_id/Comments Gets an email’s comments.

Parameters:

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

    The ID of the email.

Returns:

  • (Array, nil)

    .

Raises:

  • (ArgumentError)

    If the method arguments are blank.



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

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

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

GET /v2.1/Emails?ids=ids&tag=tag Gets a list of Emails.

Parameters:

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

    The list of email IDs (optional).

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

    Emails tagged with this tag (optional).

Returns:

  • (Array, nil)

    .



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

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