diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..3d74223 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,27 @@ +name: Run tests + +on: + pull_request: + push: + branches: [master] + +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 ${{ matrix.ruby-version }} + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby-version }} + bundler-cache: true + + - name: Run tests + run: | + bundle exec rspec 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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bebfae..395fd31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,10 +5,16 @@ 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 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. - 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/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 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..24b70ac 100644 --- a/lib/pipedrive/api_operations/request.rb +++ b/lib/pipedrive/api_operations/request.rb @@ -17,6 +17,17 @@ def api_version supports_v2_api? ? Pipedrive.api_version : :v1 end + def api_version_prefix + # Version 1 endpoints don't use the '/api/' prefix + return api_version if api_version == :v1 + + "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" \ @@ -39,7 +50,7 @@ def request(method, url, params = {}) def api_client @api_client = Faraday.new( - url: "#{BASE_URL}/#{api_version}", + url: api_base_url, headers: { "Content-Type": "application/json" } ) do |faraday| if Pipedrive.debug_http 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/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 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..946c129 100644 --- a/spec/lib/pipedrive/pipedrive_spec.rb +++ b/spec/lib/pipedrive/pipedrive_spec.rb @@ -107,14 +107,17 @@ { 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}" + data = e.data + expect(data).to include("Error data") + expect(data).to include("abc") + expect(data).to include("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`.