Skip to content
Merged
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
27 changes: 27 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
/Gemfile.lock
.rvmrc
.tool-versions
.byebug_history
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/pipedrive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 12 additions & 1 deletion lib/pipedrive/api_operations/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/pipedrive/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/pipedrive/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Pipedrive
VERSION = "2.0.0"
VERSION = "2.0.1"
end
3 changes: 1 addition & 2 deletions spec/lib/pipedrive/activity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions spec/lib/pipedrive/pipedrive_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions spec/lib/pipedrive/resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down