Class: CapsuleCRM::Task

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Naming
Includes:
ActiveModel::Conversion, ActiveModel::Validations, Associations::BelongsTo, Attributes, Collection, Virtus
Defined in:
lib/capsule_crm/task.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Attributes

#attributes=

Class Method Details

._for_case(case_id) ⇒ Object



47
48
49
50
51
# File 'lib/capsule_crm/task.rb', line 47

def self._for_case(case_id)
  CapsuleCRM::ResultsProxy.new(
    CapsuleCRM::Task.all.select { |task| task.case_id == case_id }
  )
end

._for_opportunity(opportunity_id) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/capsule_crm/task.rb', line 39

def self._for_opportunity(opportunity_id)
  CapsuleCRM::ResultsProxy.new(
    CapsuleCRM::Task.all.select do |task|
      task.opportunity_id == opportunity_id
    end
  )
end

._for_party(party_id) ⇒ Object Also known as: _for_person, _for_organization



29
30
31
32
33
# File 'lib/capsule_crm/task.rb', line 29

def self._for_party(party_id)
  CapsuleCRM::ResultsProxy.new(
    CapsuleCRM::Task.all.select { |task| task.party_id == party_id }
  )
end

.all(options = {}) ⇒ Object



59
60
61
62
63
# File 'lib/capsule_crm/task.rb', line 59

def self.all(options = {})
  init_collection(
    CapsuleCRM::Connection.get('/api/tasks', options)['tasks']['task']
  )
end

.categoriesObject



118
119
120
121
# File 'lib/capsule_crm/task.rb', line 118

def self.categories
  CapsuleCRM::Connection.
    get('/api/task/categories')['taskCategories']['taskCategory']
end

.create(attributes = {}) ⇒ Object



69
70
71
# File 'lib/capsule_crm/task.rb', line 69

def self.create(attributes = {})
  new(attributes).tap(&:save)
end

.create!(attributes = {}) ⇒ Object



73
74
75
# File 'lib/capsule_crm/task.rb', line 73

def self.create!(attributes = {})
  new(attributes).tap(&:save!)
end

.find(id) ⇒ Object



65
66
67
# File 'lib/capsule_crm/task.rb', line 65

def self.find(id)
  new CapsuleCRM::Connection.get("/api/task/#{id}")['task']
end

Instance Method Details

#completeObject



108
109
110
111
# File 'lib/capsule_crm/task.rb', line 108

def complete
  CapsuleCRM::Connection.post("/api/task/#{id}/complete")
  self
end

#destroyObject



103
104
105
106
# File 'lib/capsule_crm/task.rb', line 103

def destroy
  self.id = nil if CapsuleCRM::Connection.delete("/api/task/#{id}")
  self
end

#new_record?Boolean

Returns:

  • (Boolean)


123
124
125
# File 'lib/capsule_crm/task.rb', line 123

def new_record?
  !id
end

#owner=(user) ⇒ Object



53
54
55
56
57
# File 'lib/capsule_crm/task.rb', line 53

def owner=(user)
  user = CapsuleCRM::User.find_by_username(user) if user.is_a?(String)
  @owner = user
  self
end

#persisted?Boolean

Returns:

  • (Boolean)


127
128
129
# File 'lib/capsule_crm/task.rb', line 127

def persisted?
  !new_record?
end

#reopenObject



113
114
115
116
# File 'lib/capsule_crm/task.rb', line 113

def reopen
  CapsuleCRM::Connection.post("/api/task/#{id}/reopen")
  self
end

#saveObject



87
88
89
90
91
92
93
# File 'lib/capsule_crm/task.rb', line 87

def save
  if valid?
    new_record? ? create_record : update_record
  else
    false
  end
end

#save!Object



95
96
97
98
99
100
101
# File 'lib/capsule_crm/task.rb', line 95

def save!
  if valid?
    save
  else
    raise CapsuleCRM::Errors::RecordInvalid.new(self)
  end
end

#to_capsule_jsonObject



131
132
133
134
135
# File 'lib/capsule_crm/task.rb', line 131

def to_capsule_json
  {
    task: CapsuleCRM::HashHelper.camelize_keys(capsule_attributes)
  }.stringify_keys
end

#update_attributes(attributes = {}) ⇒ Object



77
78
79
80
# File 'lib/capsule_crm/task.rb', line 77

def update_attributes(attributes = {})
  self.attributes = attributes
  save
end

#update_attributes!(attributes = {}) ⇒ Object



82
83
84
85
# File 'lib/capsule_crm/task.rb', line 82

def update_attributes!(attributes = {})
  self.attributes = attributes
  save!
end