From 13d4d2443ed21b9aa184736c00ae01ecedc80dd1 Mon Sep 17 00:00:00 2001 From: Jorge Rodriguez Date: Thu, 17 Apr 2025 19:31:21 -0400 Subject: [PATCH 01/11] Fix broken endpoints --- lib/pipedrive.rb | 2 +- lib/pipedrive/api_operations/request.rb | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/pipedrive.rb b/lib/pipedrive.rb index 38d1779..15de30d 100644 --- a/lib/pipedrive.rb +++ b/lib/pipedrive.rb @@ -24,7 +24,7 @@ require "pipedrive/resources" module Pipedrive - BASE_URL = "https://api.pipedrive.com/api" + BASE_URL = "https://api.pipedrive.com" class << self attr_accessor :api_key, diff --git a/lib/pipedrive/api_operations/request.rb b/lib/pipedrive/api_operations/request.rb index fc78b37..91b1bb1 100644 --- a/lib/pipedrive/api_operations/request.rb +++ b/lib/pipedrive/api_operations/request.rb @@ -17,6 +17,11 @@ def api_version supports_v2_api? ? Pipedrive.api_version : :v1 end + def api_version_prefix + return api_version if api_version == :v1 + "api/#{api_version}" + end + def request(method, url, params = {}) check_api_key! raise "Not supported method" \ @@ -39,7 +44,7 @@ def request(method, url, params = {}) def api_client @api_client = Faraday.new( - url: "#{BASE_URL}/#{api_version}", + url: "#{BASE_URL}/#{api_version_prefix}/", headers: { "Content-Type": "application/json" } ) do |faraday| if Pipedrive.debug_http From c9ae4c9ebc1a1f72fd710067b9c26419f43eefdd Mon Sep 17 00:00:00 2001 From: Jorge Rodriguez Date: Thu, 17 Apr 2025 19:56:58 -0400 Subject: [PATCH 02/11] Add specs --- .byebug_history | 10 ++++++++++ lib/pipedrive/api_operations/request.rb | 6 +++++- spec/lib/pipedrive/activity_spec.rb | 3 +-- spec/lib/pipedrive/pipedrive_spec.rb | 2 +- spec/lib/pipedrive/resource_spec.rb | 22 ++++++++++++++++++++++ spec/spec_helper.rb | 1 + 6 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 .byebug_history diff --git a/.byebug_history b/.byebug_history new file mode 100644 index 0000000..946c494 --- /dev/null +++ b/.byebug_history @@ -0,0 +1,10 @@ +continue +quit +described_class.api_base_url +described_class.supports_v2_version? +described_class.support_v2_version? +described_class.api_base_url +describe_class.api_base_url +describe_Class.api_base_url +Pipedrive.api_version +quit diff --git a/lib/pipedrive/api_operations/request.rb b/lib/pipedrive/api_operations/request.rb index 91b1bb1..bea98a1 100644 --- a/lib/pipedrive/api_operations/request.rb +++ b/lib/pipedrive/api_operations/request.rb @@ -22,6 +22,10 @@ def api_version_prefix "api/#{api_version}" end + def api_base_url + "#{BASE_URL}/#{api_version_prefix}" + end + def request(method, url, params = {}) check_api_key! raise "Not supported method" \ @@ -44,7 +48,7 @@ def request(method, url, params = {}) def api_client @api_client = Faraday.new( - url: "#{BASE_URL}/#{api_version_prefix}/", + url: api_base_url, headers: { "Content-Type": "application/json" } ) do |faraday| if Pipedrive.debug_http diff --git a/spec/lib/pipedrive/activity_spec.rb b/spec/lib/pipedrive/activity_spec.rb index 252c2a8..1f9e8d4 100644 --- a/spec/lib/pipedrive/activity_spec.rb +++ b/spec/lib/pipedrive/activity_spec.rb @@ -30,8 +30,7 @@ end describe "default v2 api version" do -- it "returns v1 api version" do -+ it "returns v2 api version" do + it "returns v2 api version" do expect(described_class.api_version).to eq(:v2) end end diff --git a/spec/lib/pipedrive/pipedrive_spec.rb b/spec/lib/pipedrive/pipedrive_spec.rb index 2828909..fddce9d 100644 --- a/spec/lib/pipedrive/pipedrive_spec.rb +++ b/spec/lib/pipedrive/pipedrive_spec.rb @@ -114,7 +114,7 @@ it "includes data and additional data into the error" do described_class.raise_error(1000, response) rescue StandardError => e - expect(e.data).to eq "\"Error data\"{:abc=>123}" + expect(e.data).to eq "\"Error data\"{abc: 123}" end end end diff --git a/spec/lib/pipedrive/resource_spec.rb b/spec/lib/pipedrive/resource_spec.rb index 9545872..0b00383 100644 --- a/spec/lib/pipedrive/resource_spec.rb +++ b/spec/lib/pipedrive/resource_spec.rb @@ -31,6 +31,28 @@ class Resourceable < Resource end end + describe "#api_base_url" do + context "when it supports v2 api" do + before do + allow(described_class).to receive(:supports_v2_api?).and_return(true) + end + + it "returns v2 expected url" do + expect(described_class.api_base_url).to eq("https://api.pipedrive.com/api/v2") + end + end + + context "when it does not support v2 api" do + before do + allow(described_class).to receive(:supports_v2_api?).and_return(false) + end + + it "returns v1 expected url" do + expect(described_class.api_base_url).to eq("https://api.pipedrive.com/v1") + end + end + end + describe "#class_name" do it "returns the name of the scoped class" do expect(described_class.class_name).to eq("Resourceable") diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5d4509b..e92c95d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -6,6 +6,7 @@ end require "pipedrive" +require "byebug" # This file was generated by the `rspec --init` command. Conventionally, all # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. From 0b7a08a533a1df67edd7761f008cc2461d8a0fc7 Mon Sep 17 00:00:00 2001 From: Jorge Rodriguez Date: Thu, 17 Apr 2025 19:57:57 -0400 Subject: [PATCH 03/11] Update .gitignore --- .byebug_history | 10 ---------- .gitignore | 1 + 2 files changed, 1 insertion(+), 10 deletions(-) delete mode 100644 .byebug_history diff --git a/.byebug_history b/.byebug_history deleted file mode 100644 index 946c494..0000000 --- a/.byebug_history +++ /dev/null @@ -1,10 +0,0 @@ -continue -quit -described_class.api_base_url -described_class.supports_v2_version? -described_class.support_v2_version? -described_class.api_base_url -describe_class.api_base_url -describe_Class.api_base_url -Pipedrive.api_version -quit diff --git a/.gitignore b/.gitignore index 052ad29..2799a42 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ /Gemfile.lock .rvmrc .tool-versions +.byebug_history From 16d248309bd65c28b691e11cccfbc8b0fa0c2813 Mon Sep 17 00:00:00 2001 From: Jorge Rodriguez Date: Thu, 17 Apr 2025 20:08:11 -0400 Subject: [PATCH 04/11] Add github action to run specs --- .github/workflows/ci.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..87a4794 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,23 @@ +name: Run tests + +on: + pull_request: + push: + branches: [master] + +jobs: + run-rspec-tests: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.7 + bundler-cache: true + + - name: Run tests + run: | + bundle exec rspec From 8175fb7cd583e5c9a78cb70ba7d747a5a5df90e5 Mon Sep 17 00:00:00 2001 From: Jorge Rodriguez Date: Thu, 17 Apr 2025 20:16:21 -0400 Subject: [PATCH 05/11] Fix spec for any version of ruby --- lib/pipedrive/errors.rb | 6 +++--- spec/lib/pipedrive/pipedrive_spec.rb | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/pipedrive/errors.rb b/lib/pipedrive/errors.rb index b010cc9..b8e6bd8 100644 --- a/lib/pipedrive/errors.rb +++ b/lib/pipedrive/errors.rb @@ -61,9 +61,9 @@ def raise_error(status, response) error_data = response - .fetch(:data, {}) - .inspect - .concat(response.fetch(:additional_data, {}).inspect) + .fetch(:data, {}) + .inspect + .concat(response.fetch(:additional_data, {}).inspect) error_class = ERROR_CLASS_MAP[status.to_s] raise error_class.new(message, status, error_data) if error_class diff --git a/spec/lib/pipedrive/pipedrive_spec.rb b/spec/lib/pipedrive/pipedrive_spec.rb index fddce9d..07f3fa8 100644 --- a/spec/lib/pipedrive/pipedrive_spec.rb +++ b/spec/lib/pipedrive/pipedrive_spec.rb @@ -107,14 +107,14 @@ { error: "Bad request", data: "Error data", - additional_data: { abc: 123 }, + additional_data: { "abc" => 123 }, } end it "includes data and additional data into the error" do described_class.raise_error(1000, response) rescue StandardError => e - expect(e.data).to eq "\"Error data\"{abc: 123}" + expect(e.data).to eq "\"Error data\"{\"abc\" => 123}" end end end From 2072757e607831ff0e3559b41b9a53dceec289d7 Mon Sep 17 00:00:00 2001 From: Jorge Rodriguez Date: Thu, 17 Apr 2025 20:18:34 -0400 Subject: [PATCH 06/11] Hack to fix spec --- spec/lib/pipedrive/pipedrive_spec.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spec/lib/pipedrive/pipedrive_spec.rb b/spec/lib/pipedrive/pipedrive_spec.rb index 07f3fa8..946c129 100644 --- a/spec/lib/pipedrive/pipedrive_spec.rb +++ b/spec/lib/pipedrive/pipedrive_spec.rb @@ -114,7 +114,10 @@ it "includes data and additional data into the error" do described_class.raise_error(1000, response) rescue StandardError => e - expect(e.data).to eq "\"Error data\"{\"abc\" => 123}" + data = e.data + expect(data).to include("Error data") + expect(data).to include("abc") + expect(data).to include("123") end end end From c72624bc24f7a9e4d104a2fd8a67755e8f94ed5c Mon Sep 17 00:00:00 2001 From: Jorge Rodriguez Date: Thu, 17 Apr 2025 20:19:44 -0400 Subject: [PATCH 07/11] Add CI badge --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2565475..504c60c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![Run tests](https://github.com/getonbrd/pipedrive-connect/actions/workflows/ci.yml/badge.svg)](https://github.com/getonbrd/pipedrive-connect/actions/workflows/ci.yml) + # Pipedrive API Ruby library Pipedrive::Connect provides a convenient access to the Pipedrive API from applications written in the Ruby language. @@ -75,7 +77,8 @@ irb(main):009:0> Pipedrive.use_v2_api! irb(main):010:0> Pipedrive.api_version => :v2 ``` -*Please note:* not all resources have V2 api endpoint. For these resources the V2 setting will be ignored and the + +_Please note:_ not all resources have V2 api endpoint. For these resources the V2 setting will be ignored and the V1 endpoints will always be used. ```ruby From f7cef5eb51c8856ceeffe813fab3f5ea53830d93 Mon Sep 17 00:00:00 2001 From: Jorge Rodriguez Date: Thu, 17 Apr 2025 20:26:10 -0400 Subject: [PATCH 08/11] Run the CI vs several versions of ruby --- .github/workflows/ci.yml | 8 ++++++-- lib/pipedrive/api_operations/request.rb | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 87a4794..3d74223 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,14 +8,18 @@ on: jobs: run-rspec-tests: runs-on: ubuntu-latest + strategy: + matrix: + ruby-version: [2.7, 3.4] + steps: - name: Checkout code uses: actions/checkout@v4 - - name: Set up Ruby + - name: Set up Ruby ${{ matrix.ruby-version }} uses: ruby/setup-ruby@v1 with: - ruby-version: 2.7 + ruby-version: ${{ matrix.ruby-version }} bundler-cache: true - name: Run tests diff --git a/lib/pipedrive/api_operations/request.rb b/lib/pipedrive/api_operations/request.rb index bea98a1..b03bd53 100644 --- a/lib/pipedrive/api_operations/request.rb +++ b/lib/pipedrive/api_operations/request.rb @@ -19,6 +19,7 @@ def api_version def api_version_prefix return api_version if api_version == :v1 + "api/#{api_version}" end From b10cf52a01dc278258d7f84b8aef571e090afdd0 Mon Sep 17 00:00:00 2001 From: Jorge Rodriguez Date: Thu, 17 Apr 2025 20:29:18 -0400 Subject: [PATCH 09/11] Bump version --- CHANGELOG.md | 7 +++++++ lib/pipedrive/version.rb | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bebfae..f841faf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,10 +5,17 @@ This project adheres to [Semantic Versioning](http://semver.org/). This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/). +## [2.0.1] - 2025-04-17 + +- Fix bugs instroduced with version 2 where the base url for v1 was broken. +- Add github actions + ## [2.0.0] - 2025-04-11 + - **BREAKING change**: Minimum ruby version updated to 2.7. - Added options for using new V2 API endpoints. Resource `Pipedrive::Activity` switched to new V2 endpoint. - Documentation updates with information on V1/V2 API endpoint switching. + ## [1.3.1] - 2023-06-01 - **BREAKING change**: Generated `delete_*` method has been refactored to receive the `id` of the record to be dettached or deleted - instead of the resource per se -, for instance: `deal.delete_product(attached_product_id)`. This is because the API behaves different depending on the endpoint, like in case of `#DELETE /deals/{id}/products/{product_attachment_id}` that receives an id corresponding to the attachment id (not a product, but a different record). diff --git a/lib/pipedrive/version.rb b/lib/pipedrive/version.rb index 128bcc2..17b678d 100644 --- a/lib/pipedrive/version.rb +++ b/lib/pipedrive/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Pipedrive - VERSION = "2.0.0" + VERSION = "2.0.1" end From 3700f05a4099749f44aa15751ea260389ef269f5 Mon Sep 17 00:00:00 2001 From: Jorge Rodriguez Date: Thu, 17 Apr 2025 20:30:43 -0400 Subject: [PATCH 10/11] Update lib/pipedrive/api_operations/request.rb Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- lib/pipedrive/api_operations/request.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/pipedrive/api_operations/request.rb b/lib/pipedrive/api_operations/request.rb index b03bd53..24b70ac 100644 --- a/lib/pipedrive/api_operations/request.rb +++ b/lib/pipedrive/api_operations/request.rb @@ -18,6 +18,7 @@ def api_version end def api_version_prefix + # Version 1 endpoints don't use the '/api/' prefix return api_version if api_version == :v1 "api/#{api_version}" From bd8fed9ed80cc764258a066a41e267944e662321 Mon Sep 17 00:00:00 2001 From: Jorge Rodriguez Date: Thu, 17 Apr 2025 20:31:49 -0400 Subject: [PATCH 11/11] Update CHANGELOG.md Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- CHANGELOG.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f841faf..395fd31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,9 +7,8 @@ This change log follows the conventions of [keepachangelog.com](http://keepachan ## [2.0.1] - 2025-04-17 -- Fix bugs instroduced with version 2 where the base url for v1 was broken. -- Add github actions - +- Fix bugs introduced with versionĀ 2 where the baseĀ URL for v1 was broken. +- Add GitHub Actions workflow ## [2.0.0] - 2025-04-11 - **BREAKING change**: Minimum ruby version updated to 2.7.