Module: Insightly2::DSL::Opportunities

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

Instance Method Summary collapse

Instance Method Details

#create_opportunity(opportunity: nil) ⇒ Insightly2::Resources::Opportunity?

POST /v2.1/Opportunities Create an opportunity.

Parameters:

  • opportunity (Hash) (defaults to: nil)

    The opportunity to create.

Returns:

Raises:

  • (ArgumentError)

    If the method arguments are blank.



78
79
80
81
# File 'lib/insightly2/dsl/opportunities.rb', line 78

def create_opportunity(opportunity: nil)
  raise ArgumentError, "Opportunity cannot be blank" if opportunity.blank?
  Resources::Opportunity.parse(request(:post, "Opportunities", opportunity))
end

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

POST /v2.1/Opportunities/c_id/Image/filename Add an attachment to an opportunity.

Parameters:

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

    An opportunity’s ID.

  • filename (String) (defaults to: nil)

    A name of a file.

Returns:

  • (Faraday::Response)

Raises:

  • (ArgumentError)

    If the method arguments are blank.



89
90
91
92
93
# File 'lib/insightly2/dsl/opportunities.rb', line 89

def create_opportunity_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, "Opportunities/#{id}/Image/#{filename}")
end

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

DELETE /v2.1/Opportunities/id

Parameters:

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

    An opportunity’s ID.

Returns:

  • (Faraday::Response)

    .

Raises:

  • (ArgumentError)

    If the method arguments are blank.



120
121
122
123
# File 'lib/insightly2/dsl/opportunities.rb', line 120

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

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

DELETE /v2.1/Opportunities/c_id/Image

Parameters:

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

    An opportunity’s ID.

Returns:

  • (Faraday::Response)

    .

Raises:

  • (ArgumentError)

    If the method arguments are blank.



129
130
131
132
# File 'lib/insightly2/dsl/opportunities.rb', line 129

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

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

GET /v2.1/Opportunities?ids=ids&tag=tag Get a list of opportunities.

Parameters:

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

    IDs of opportunities (optional).

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

    The tag that has been applied to an opportunity (optional).

Returns:

  • (Array, nil)

    .



68
69
70
71
# File 'lib/insightly2/dsl/opportunities.rb', line 68

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

#get_opportunity(id: nil) ⇒ Insightly2::Resources::Opportunity?

GET /v2.1/Opportunities/id Get an opportunity.

Parameters:

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

    An opportunity’s ID.

Returns:

Raises:

  • (ArgumentError)

    If the method arguments are blank.



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

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

#get_opportunity_emails(id: nil) ⇒ Array?

GET /v2.1/Opportunities/c_id/Emails Get an opportunity’s emails.

Parameters:

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

    An opportunity’s ID.

Returns:

  • (Array, nil)

    .

Raises:

  • (ArgumentError)

    If the method arguments are blank.



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

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

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

GET /v2.1/Opportunities/c_id/Image

Parameters:

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

    An opportunity’s ID

Returns:

  • (Faraday::Response)

Raises:

  • (ArgumentError)

    If the method arguments are blank.



29
30
31
# File 'lib/insightly2/dsl/opportunities.rb', line 29

def get_opportunity_image(id: nil)
  request(:get, "Opportunities/#{id}/Image")
end

#get_opportunity_notes(id: nil) ⇒ Array?

GET /v2.1/Opportunities/c_id/Notes Get an opportunity’s notes.

Parameters:

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

    An opportunity’s ID.

Returns:

  • (Array, nil)

    .

Raises:

  • (ArgumentError)

    If the method arguments are blank.



38
39
40
41
# File 'lib/insightly2/dsl/opportunities.rb', line 38

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

#get_opportunity_state_history(id: nil) ⇒ Array?

GET /v2.1/Opportunities/c_id/StateHistory Get an opportunity’s state history.

Parameters:

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

    An opportunity’s ID.

Returns:

  • (Array, nil)

    .

Raises:

  • (ArgumentError)

    If the method arguments are blank.



48
49
50
51
# File 'lib/insightly2/dsl/opportunities.rb', line 48

def get_opportunity_state_history(id: nil)
  raise ArgumentError, "ID cannot be blank" if id.blank?
  Resources::OpportunityStateReason.parse(request(:get, "Opportunities/#{id}/StateHistory"))
end

#get_opportunity_tasks(id: nil) ⇒ Array?

GET /v2.1/Opportunities/c_id/Tasks Get an opportunity’s tasks.

Parameters:

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

    An opportunity’s ID.

Returns:

  • (Array, nil)

    .

Raises:

  • (ArgumentError)

    If the method arguments are blank.



58
59
60
61
# File 'lib/insightly2/dsl/opportunities.rb', line 58

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

#update_opportunity(opportunity: nil) ⇒ Insightly2::Resources::Opportunity?

PUT /v2.1/Opportunities Update an opportunity.

Parameters:

  • opportunity (Hash) (defaults to: nil)

    The opportunity to update.

Returns:

Raises:

  • (ArgumentError)

    If the method arguments are blank.



100
101
102
103
# File 'lib/insightly2/dsl/opportunities.rb', line 100

def update_opportunity(opportunity: nil)
  raise ArgumentError, "Opportunity cannot be blank" if opportunity.blank?
  Resources::Opportunity.parse(request(:put, "Opportunities", opportunity))
end

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

PUT /v2.1/Opportunities/c_id/Image/filename

Parameters:

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

    An opportunity’s ID.

  • filename (String) (defaults to: nil)

    A name of a file.

Returns:

  • (Faraday::Response)

    .

Raises:

  • (ArgumentError)

    If the method arguments are blank.



110
111
112
113
114
# File 'lib/insightly2/dsl/opportunities.rb', line 110

def update_opportunity_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, "Opportunities/#{id}/Image/#{filename}")
end