class PipedrivePUT::Organizations

Public Class Methods

addOrganization(company_name, options = {}) click to toggle source

Add an organization

# File lib/PipedrivePUT/organization.rb, line 48
                def self.addOrganization(company_name, options = {})
                        uri = "https://api.pipedrive.com/v1/organizations?api_token=#{@@key}"
                        options = options.merge(name: company_name)
HTTParty.post(uri, body: options.to_json, headers: {'Content-type' => 'application/json'})
                end
findOrganizationByName(name, options = {}) click to toggle source

Find Organization by name

# File lib/PipedrivePUT/organization.rb, line 72
def self.findOrganizationByName(name, options = {})
  params = {}

  params[:term]      = name if name && !name.empty?
  params[:start]     = options.fetch(:start, 0)
  params[:limit]     = options.fetch(:limit, 500)
  params[:api_token] = @@key.to_s

  url = "https://api.pipedrive.com/v1/organizations/find?#{URI.encode_www_form(params)}"

  begin
    table = []
    more_items = true
    tablesize = 0

    while more_items == true
      count = 0

      content = open(url).read
      parsed = JSON.parse(content)
      return table if parsed['data'].nil?

      while count < parsed['data'].size
        table[tablesize] = parsed['data'][count]
        count += 1
        tablesize += 1
      end
      pagination     = parsed['additional_data']['pagination']
      more_items     = pagination['more_items_in_collection']
      params[:start] = pagination['next_start']
    end
    return table
  rescue OpenURI::HTTPError => error
    response = error.io
    return response.status
  end
end
getAllOrgs() click to toggle source

Get All Organizations from Pipedrive

# File lib/PipedrivePUT/organization.rb, line 14
def self.getAllOrgs()
                   @start = 0

                   table = Array.new
                   @more_items = true
                   tablesize = 0
                   while @more_items == true do
                         count = 0
                         #puts @more_items
                         @base = URI.parse('https://api.pipedrive.com/v1/organizations?start=' + @start.to_s + '&limit=500&api_token=' + @@key.to_s)
                         #puts @base
                         @content = Net::HTTP.get(@base)
                         @parsed = JSON.parse(@content)

                         while count < @parsed["data"].size
                                 #table.push(@parsed["data"][count])
                                 table[tablesize] = @parsed["data"][count]
                                 count = count +1
                                 tablesize = tablesize + 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
getOrganization(id) click to toggle source

Return data of a specific Organization

# File lib/PipedrivePUT/organization.rb, line 55
def self.getOrganization(id)
        begin
                @base = 'https://api.pipedrive.com/v1/organizations/' + id.to_s + '?api_token=' + @@key.to_s
                @content = open(@base.to_s).read
                @parsed = JSON.parse(@content)
                if @parsed["data"].nil?
                                return "Organization does not exist in pipedrive"
                else
                        return @parsed
                end
        rescue OpenURI::HTTPError => error
                response = error.io
                return response.status
        end
end
getPersonsOfOrganization(id) click to toggle source

Get Persons of an Organization

# File lib/PipedrivePUT/organization.rb, line 112
def self.getPersonsOfOrganization(id)
        begin
                @start = 0

                table = Array.new
                @more_items = true
                tablesize = 0

                while @more_items == true do
                        count = 0

                        @base = 'https://api.pipedrive.com/v1/organizations/' + id.to_s + '/persons?&start=' + @start.to_s + '&limit=500&api_token=' + @@key.to_s

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

                        puts @content

                        @parsed = JSON.parse(@content)

                        if @parsed["data"].nil?
                                return "Organization does not have any Person associated with that id"
                        else

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

                                        end
                                @pagination = @parsed['additional_data']['pagination']
                                @more_items = @pagination['more_items_in_collection']
                                #puts @more_items
                                @start = @pagination['next_start']
                                #puts @start
                        end
            end
                return table
        rescue OpenURI::HTTPError => error
                response = error.io
                return response.status
        end
end
key() click to toggle source
# File lib/PipedrivePUT/organization.rb, line 9
def self.key
 return @@key
end
updateOrganization(id, options = {}) click to toggle source

Update an Organization

# File lib/PipedrivePUT/organization.rb, line 157
def self.updateOrganization(id, options = {})
        @url = 'https://api.pipedrive.com/v1/organizations/' + id.to_s + '?api_token=' + @@key.to_s

        #puts @url

        if (!options.nil?)

                options.merge!(:id => id)
                #puts options

                #puts '----------------------'

                response = HTTParty.put(@url.to_s, :body => options.to_json, :headers => {'Content-type' => 'application/json'})
                #puts '----------------------'
                #puts response

        end

end