Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions lib/pipedrive-ruby.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'pipedrive/base'
require_relative 'pipedrive/base'
require 'pipedrive/activity'
require 'pipedrive/activity-type'
require 'pipedrive/authorization'
Expand All @@ -14,7 +14,7 @@
require 'pipedrive/person-field'
require 'pipedrive/permission-set'
require 'pipedrive/pipeline'
require 'pipedrive/product'
require_relative 'pipedrive/product'
require 'pipedrive/product-field'
require 'pipedrive/role'
require 'pipedrive/search-result'
Expand All @@ -30,5 +30,4 @@ module Pipedrive
def self.authenticate(token)
Base.authenticate(token)
end

end
end
20 changes: 11 additions & 9 deletions lib/pipedrive/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Base < OpenStruct

include HTTParty

base_uri 'api.pipedrive.com/v1'
base_uri 'https://api.pipedrive.com/v1'
headers HEADERS
format :json

Expand Down Expand Up @@ -49,13 +49,14 @@ def initialize(attrs = {})
#
# @param [Hash] opts
# @return [Boolean]
def update(opts = {})
res = put "#{resource_path}/#{id}", :body => opts
def update(opts = {}, custom_header = {})
res = put "#{resource_path}/#{id}", body: opts, headers: Base.default_options[:headers].merge(custom_header)
opts = JSON.parse(opts) unless opts.is_a?(Hash)
if res.success?
res['data'] = Hash[res['data'].map {|k, v| [k.to_sym, v] }]
@table.merge!(res['data'])
else
false
Base.bad_response(res, opts)
end
end

Expand Down Expand Up @@ -84,22 +85,23 @@ def new_list( attrs )
attrs['data'].is_a?(Array) ? attrs['data'].map {|data| self.new( 'data' => data ) } : []
end

def all(response = nil, options={},get_absolutely_all=false)
def all(response = nil, options = { query: {} }, get_absolutely_all = true)
res = response || get(resource_path, options)
if res.ok?
data = res['data'].nil? ? [] : res['data'].map{|obj| new(obj)}
if get_absolutely_all && res['additional_data']['pagination'] && res['additional_data']['pagination'] && res['additional_data']['pagination']['more_items_in_collection']
if get_absolutely_all && res['additional_data'] && res['additional_data']['pagination'] && res['additional_data']['pagination']['more_items_in_collection']
options[:query] = options[:query].merge({:start => res['additional_data']['pagination']['next_start']})
data += self.all(nil,options,true)
end
data
else
bad_response(res,attrs)
bad_response(res, options)
end
end

def create( opts = {} )
res = post resource_path, :body => opts
def create(opts = {}, custom_header = {})
res = post resource_path, body: opts, headers: default_options[:headers].merge(custom_header)
opts = JSON.parse(opts) unless opts.is_a?(Hash)
if res.success?
res['data'] = opts.merge res['data']
new(res)
Expand Down
8 changes: 8 additions & 0 deletions lib/pipedrive/product.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
module Pipedrive
class Product < Base
def update(opts = {})
super(opts.to_json, {'Content-Type' => 'application/json'})
end
class << self
def create(opts = {})
super(opts.to_json, {'Content-Type' => 'application/json'})
end
end
end
end