From b5eb41d86abd23f73b86009f44bbc633ba14d787 Mon Sep 17 00:00:00 2001 From: Mehreen Tahir Date: Tue, 13 Dec 2016 18:09:15 +0500 Subject: [PATCH 1/9] PipeDrive: Uptated base_uri for https support of pipedrive API --- lib/pipedrive/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pipedrive/base.rb b/lib/pipedrive/base.rb index 9a0adb0..7879d30 100644 --- a/lib/pipedrive/base.rb +++ b/lib/pipedrive/base.rb @@ -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 From d113ca765440ef27e41a5e92e74dfcd232311efe Mon Sep 17 00:00:00 2001 From: Mehreen Tahir Date: Tue, 13 Dec 2016 18:10:15 +0500 Subject: [PATCH 2/9] PipeDrive: Updated to require relative from require for base class --- lib/pipedrive-ruby.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/pipedrive-ruby.rb b/lib/pipedrive-ruby.rb index b2b7ab9..c2bc516 100644 --- a/lib/pipedrive-ruby.rb +++ b/lib/pipedrive-ruby.rb @@ -1,4 +1,4 @@ -require 'pipedrive/base' +require_relative 'pipedrive/base' require 'pipedrive/activity' require 'pipedrive/activity-type' require 'pipedrive/authorization' @@ -30,5 +30,4 @@ module Pipedrive def self.authenticate(token) Base.authenticate(token) end - -end \ No newline at end of file +end From 2d6b7c3924d15ab6508e75bd52293bab401d9520 Mon Sep 17 00:00:00 2001 From: Mehreen Tahir Date: Thu, 15 Dec 2016 11:12:57 +0500 Subject: [PATCH 3/9] Pipedrive: Updated with bad response if updation fails for entities --- lib/pipedrive/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pipedrive/base.rb b/lib/pipedrive/base.rb index 7879d30..e32c6cf 100644 --- a/lib/pipedrive/base.rb +++ b/lib/pipedrive/base.rb @@ -55,7 +55,7 @@ def update(opts = {}) 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 From d9bb51a3942ed5a8aa49608ae3b011e6c14997d7 Mon Sep 17 00:00:00 2001 From: Mehreen Tahir Date: Fri, 16 Dec 2016 12:20:09 +0500 Subject: [PATCH 4/9] Pipedrive: Added custom creation method for product creation + updated base creation --- lib/pipedrive/base.rb | 5 +++-- lib/pipedrive/product.rb | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/pipedrive/base.rb b/lib/pipedrive/base.rb index e32c6cf..5203247 100644 --- a/lib/pipedrive/base.rb +++ b/lib/pipedrive/base.rb @@ -98,8 +98,9 @@ def all(response = nil, options={},get_absolutely_all=false) 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) diff --git a/lib/pipedrive/product.rb b/lib/pipedrive/product.rb index a8baaf8..4cbf808 100644 --- a/lib/pipedrive/product.rb +++ b/lib/pipedrive/product.rb @@ -1,4 +1,9 @@ module Pipedrive class Product < Base + class << self + def create(opts = {}) + super(opts.to_json, {'Content-Type' => 'application/json'}) + end + end end end From 2ba0eb3d7d9a9ec43281ba39ee839e4592711632 Mon Sep 17 00:00:00 2001 From: Mehreen Tahir Date: Fri, 16 Dec 2016 13:08:09 +0500 Subject: [PATCH 5/9] Pipedrive: Added custom updation method for product + updated base updation --- lib/pipedrive/base.rb | 5 +++-- lib/pipedrive/product.rb | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/pipedrive/base.rb b/lib/pipedrive/base.rb index 5203247..0f220c4 100644 --- a/lib/pipedrive/base.rb +++ b/lib/pipedrive/base.rb @@ -49,8 +49,9 @@ 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']) diff --git a/lib/pipedrive/product.rb b/lib/pipedrive/product.rb index 4cbf808..c23eae7 100644 --- a/lib/pipedrive/product.rb +++ b/lib/pipedrive/product.rb @@ -1,5 +1,8 @@ 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'}) From 76529a98b2abbf3446420acf5a07fc51d0a2bd34 Mon Sep 17 00:00:00 2001 From: Mehreen Tahir Date: Fri, 16 Dec 2016 13:08:46 +0500 Subject: [PATCH 6/9] PipeDrive: Required pipedrive product by the relative path --- lib/pipedrive-ruby.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pipedrive-ruby.rb b/lib/pipedrive-ruby.rb index c2bc516..e0b0697 100644 --- a/lib/pipedrive-ruby.rb +++ b/lib/pipedrive-ruby.rb @@ -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' From 61ee2aa21bcfcdfdb7318f60a99b8606ecf5ca37 Mon Sep 17 00:00:00 2001 From: Mehreen Tahir Date: Fri, 16 Dec 2016 15:24:01 +0500 Subject: [PATCH 7/9] Pipedrive: Fixed the pagination issues for fetching pipedrive entities --- lib/pipedrive/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pipedrive/base.rb b/lib/pipedrive/base.rb index 0f220c4..d72d4b2 100644 --- a/lib/pipedrive/base.rb +++ b/lib/pipedrive/base.rb @@ -85,7 +85,7 @@ 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)} From 45484499dc30ca3e2a23a6b1414485f04af47d0c Mon Sep 17 00:00:00 2001 From: Mehreen Tahir Date: Thu, 22 Dec 2016 15:52:59 +0500 Subject: [PATCH 8/9] PipeDrive: Updated the bad response params --- lib/pipedrive/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pipedrive/base.rb b/lib/pipedrive/base.rb index d72d4b2..8add8d7 100644 --- a/lib/pipedrive/base.rb +++ b/lib/pipedrive/base.rb @@ -95,7 +95,7 @@ def all(response = nil, options = { query: {} }, get_absolutely_all = true) end data else - bad_response(res,attrs) + bad_response(res, options) end end From 6a701030043a5a68ffac0daa392ad1672169ffe0 Mon Sep 17 00:00:00 2001 From: MehreenT Date: Tue, 7 Feb 2017 00:59:02 +0500 Subject: [PATCH 9/9] Base: Updated the conditions of pagination in retrival of entities --- lib/pipedrive/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pipedrive/base.rb b/lib/pipedrive/base.rb index 8add8d7..b03cff9 100644 --- a/lib/pipedrive/base.rb +++ b/lib/pipedrive/base.rb @@ -89,7 +89,7 @@ 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