Class: Insightly::Opportunity

Inherits:
ReadWrite show all
Includes:
LinkHelper, TagHelper
Defined in:
lib/insightly/opportunity.rb

Constant Summary collapse

CUSTOM_FIELD_PREFIX =
"OPPORTUNITY_FIELD"

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TagHelper

#add_tag, #tags, #tags=

Methods included from LinkHelper

#add_link, #links, #links=

Methods inherited from ReadWrite

#post_collection, #put_collection, #to_json, #update_data

Methods inherited from Base

#==, all, api_field, build, #build, #config, custom_fields, #get_collection, #initialize, #load, #process, #reload, #remote_data, #to_json, #url_base

Constructor Details

This class inherits a constructor from Insightly::Base

Class Method Details

.find_by_name(name) ⇒ Object



82
83
84
85
86
87
# File 'lib/insightly/opportunity.rb', line 82

def self.find_by_name(name)
  Insightly::Opportunity.all.each do |o|
    return o if o.opportunity_name && o.opportunity_name == name
  end
  nil
end

.search_by_name(name) ⇒ Object



89
90
91
92
93
94
95
96
97
# File 'lib/insightly/opportunity.rb', line 89

def self.search_by_name(name)
  list = []
  Insightly::Opportunity.all.each do |o|
    if o.opportunity_name && o.opportunity_name.match(name)
      list << o
    end
  end
  list
end

Instance Method Details



112
113
114
115
116
# File 'lib/insightly/opportunity.rb', line 112

def fix_for_link(link)
  #This needs to auto set the org id on the item
  link.opportunity_id = self.remote_id
  link
end

#remote_idObject



41
42
43
# File 'lib/insightly/opportunity.rb', line 41

def remote_id
  opportunity_id
end

#saveObject



99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/insightly/opportunity.rb', line 99

def save
  creating = remote_id ? false : true

  super
  if creating
    @state_reason = Insightly::OpportunityStateReason.find_by_state_reason("Open", "Created by API")

    if @state_reason
      put_collection("OpportunityStateChange/#{opportunity_id}", @state_reason.remote_data.to_json)
    end
  end

end

#tasksObject



45
46
47
48
49
50
51
# File 'lib/insightly/opportunity.rb', line 45

def tasks
  list = []
  Insightly::TaskLink.search_by_opportunity_id(opportunity_id).each do |x|
    list << Insightly::Task.new(x.task_id)
  end
  list
end