Class: PipeRocket::Deal

Inherits:
Entity
  • Object
show all
Defined in:
lib/pipe_rocket/deal.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Entity

#assign_custom_fields, #transform_field_name

Constructor Details

#initialize(hash) ⇒ Deal

Returns a new instance of Deal.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/pipe_rocket/deal.rb', line 13

def initialize(hash)
  super(hash.except(*Deal.key_field_hash.keys))

  org_id = hash['org_id']
  person_id = hash['person_id']

  assign_custom_fields(Deal.key_field_hash, hash)

  if org_id
    @organization = case org_id
      when Integer
        Pipedrive.organizations.find(org_id)
      when Hash
        Organization.new(org_id)
      else
        nil
      end
  end

  if person_id
    @person = case person_id
      when Integer
        Pipedrive.persons.find(person_id)
      when Hash
        Person.new(person_id)
      else
        nil
      end
    end
end

Instance Attribute Details

#organizationObject

Returns the value of attribute organization.



6
7
8
# File 'lib/pipe_rocket/deal.rb', line 6

def organization
  @organization
end

#personObject

Returns the value of attribute person.



6
7
8
# File 'lib/pipe_rocket/deal.rb', line 6

def person
  @person
end

Class Method Details

.key_field_hashObject

Returns hash PipeRocket::Field object



9
10
11
# File 'lib/pipe_rocket/deal.rb', line 9

def self.key_field_hash
  @@key_field_hash ||= Pipedrive.deal_fields.key_field_hash
end

Instance Method Details

#display_stage_nameObject

Returns stage name like PipelineName:StageName



50
51
52
# File 'lib/pipe_rocket/deal.rb', line 50

def display_stage_name
  self.stage.display_name
end

#filesObject



54
55
56
57
58
59
# File 'lib/pipe_rocket/deal.rb', line 54

def files
  mail_files = Pipedrive.deals.deal_mail_messages(self.id).inject([]) do |res, message|
    res + message.files
  end
  Pipedrive.deals.deal_files(self.id) + mail_files
end

#stageObject

Returns PipeRocket::Stage object corresponding to current deal stage



45
46
47
# File 'lib/pipe_rocket/deal.rb', line 45

def stage
  Pipedrive.stages.find(self.stage_id)
end