Class: PipedrivePUT::Search

Inherits:
Object
  • Object
show all
Includes:
PipedrivePUT
Defined in:
lib/PipedrivePUT/search.rb

Constant Summary

Constants included from PipedrivePUT

VERSION

Instance Attribute Summary

Attributes included from PipedrivePUT

#key

Class Method Summary collapse

Methods included from PipedrivePUT

getKey

Class Method Details

.keyObject



7
8
9
# File 'lib/PipedrivePUT/search.rb', line 7

def self.key
  return @@key
end

.search(term, *args) ⇒ Object

Search Pipedrive



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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/PipedrivePUT/search.rb', line 13

def self.search(term, *args) 
      @start = 0

      
      
      if (args.size > 1)
      
      raise "Please only specify one item type (deal, organization, person, product, file)"
      return
      end
      

     if (args.size == 1)
       #Search through specific Item
      table = Array.new
        @more_items = true

        @item_type = args[0].downcase 

        while @more_items == true do
        count = 0
        @base = 'https://api.pipedrive.com/v1/searchResults?term=' + term.to_s + '&item_type=' + @item_type.to_s + '&start=' + @start.to_s + '&limit=500&api_token=' + @@key.to_s

        #puts @base

        @content = open(@base.to_s).read

        #puts @content    

        @parsed = JSON.parse(@content)


        while count < @parsed["data"].size
          table.push(@parsed["data"][count])
          count = count +1
        end

        @pagination = @parsed['additional_data']['pagination']
        @more_items = @pagination['more_items_in_collection']
        #puts @more_items
        @start = @pagination['next_start']
        #puts @start
      end 
      return table
     
     else

       #Search through every item type
        table = Array.new
        @more_items = true

        while @more_items == true do
        @base = 'https://api.pipedrive.com/v1/searchResults?term=' + term.to_s + '&start=' + @start.to_s + '&limit=500&api_token=' + @@key.to_s
        count = 0
        #puts @base

        @content = open(@base.to_s).read

        #puts @content    

        @parsed = JSON.parse(@content)

        while count < @parsed["data"].size
          table.push(@parsed["data"][count])
          count = count +1
        end

        @pagination = @parsed['additional_data']['pagination']
        @more_items = @pagination['more_items_in_collection']
        #puts @more_items
        @start = @pagination['next_start']
        #puts @start
      end 
      return table
    end
end