pipedrive-connect 1.2.6 → 1.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e705f90cd87169ced3f60343e12dc37b327620287f432fafb67801057568fb3c
4
- data.tar.gz: e424975763b80cb7d3af1f29ffd2f6625cd53dc5a752383419443e143e9ce81d
3
+ metadata.gz: 2281f9b37f07b817f422ff7d3d8b254901850051e49a14b8f9e8e5d8e6882046
4
+ data.tar.gz: 52a88a1f8d811197c860821ce67937ebb381aef36b78f9a683f849f84e818e11
5
5
  SHA512:
6
- metadata.gz: 1e0bd348c7478ceb95af39b0edfc33b7914a216bfe20d9ce51a799f64ff2642a193be605dbc2fd46d77a040ee3c9c6fb87653d5396453af5b708fa23030bd3dc
7
- data.tar.gz: c627679cf39a5fdabc0901ced1664bdb6b551119db5805a477177d62bd176ea70b6bdc18ef1c375f9cbf2a9e92b42998d96e97b9ebcd21d9b457160874c5fe4a
6
+ metadata.gz: 8d754a927d1aff43105a9c74a2ac650a7750ddc1c092c5dfc8c45a58cecc9fa857e55aaabc3a0bed7afbd42afed9b8500514e62fa25d6491f5433531b06a10d2
7
+ data.tar.gz: e84716ef498f0bd319e036c7e2fdc6df88ac9b9c0d43ab978f41ff0003721747c2a27e0db4192fee8de6c9ee862b220bf28e0d5197dd3c6353dcbb22f4fa7fa2
data/CHANGELOG.md CHANGED
@@ -4,6 +4,26 @@ This file contains all notable changes to this project.
4
4
  This project adheres to [Semantic Versioning](http://semver.org/).
5
5
  This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/).
6
6
 
7
+ ## [1.2.10] - 2022-10-19
8
+
9
+ - Implement `empty?` (or `no_content?`) method on all the models when the response is No content (204 HTTP code)
10
+ - Add option to treat 204 HTTP code (No Content) as 404 HTTP code (Not found)
11
+
12
+ ## [1.2.9] - 2022-10-13
13
+
14
+ - Add `find_by_deal` method to `Subscription`to allow finding of subscriptions by `deal_id`.
15
+
16
+ ## [1.2.8] - 2022-10-11
17
+
18
+ - Add the new resource `Pipedrive::OrganizationField`
19
+ - Add activities (as a `has_many` relationship) to `Pipedrive::Person`
20
+ - Provide better error information also maping the status code to a class according to https://pipedrive.readme.io/docs/core-api-concepts-http-status-codes (check lib/pipedrive/errors.rb)
21
+
22
+ ## [1.2.7] - 2022-09-23
23
+
24
+ - Add `Subscription` resource with additional `create_recurring`, `update_recurring` and `cancel_recurring` methods.
25
+ - Changed faraday dependency to allow more flexibility
26
+
7
27
  ## [1.2.6] - 2022-07-11
8
28
 
9
29
  - Add `delete_attached_product` method to `Deal`
data/README.md CHANGED
@@ -97,6 +97,29 @@ new_acme.update(name: "Acme the new Inc")
97
97
  new_acme.delete
98
98
  ```
99
99
 
100
+ ### 204 No Content responses
101
+
102
+ Some endpoints of the API return the HTTP status code **204** which is still a success code returning no data (empty body). This could be confusing but probably has a rationale behind.
103
+
104
+ For these cases a method `empty?` within the model responds `true`.
105
+
106
+ For instance:
107
+
108
+ ```ruby
109
+ # Asuming the subscription is not found but still return with empty body
110
+ subscription = Pipedrive::Subscription.find_by_deal(123)
111
+ subscription.empty? # true
112
+ subscription.no_content? # true - is an alias of empty?
113
+ ```
114
+
115
+ In case you want to override that behavior treating **no content** as **not found**, there is an option for that:
116
+
117
+ ```ruby
118
+ Pipedrive.treat_no_content_as_not_found = true
119
+ # Will raise a instance of Pipedrive::NotFoundError if subscription
120
+ subscription = Pipedrive::Subscription.find_by_deal(123)
121
+ ```
122
+
100
123
  ### Custom Fields
101
124
 
102
125
  Pipedrive gives you the chance to add additional data by creating custom fields that are not included by default. Deals, Persons, Organizations and Products can all contain custom fields.
@@ -2,12 +2,13 @@
2
2
 
3
3
  module Pipedrive
4
4
  class PipedriveError < StandardError
5
- attr_reader :code
5
+ attr_reader :code, :data
6
6
 
7
- def initialize(message = nil, code = nil)
7
+ def initialize(message = nil, code = nil, data = nil)
8
8
  super(message)
9
9
  @message = message
10
10
  @code = code
11
+ @data = data
11
12
  end
12
13
 
13
14
  def message
@@ -15,8 +16,60 @@ module Pipedrive
15
16
  "#{code_str}#{@message}"
16
17
  end
17
18
  end
19
+
20
+ # As documented at https://pipedrive.readme.io/docs/core-api-concepts-http-status-codes
18
21
  class SettingError < PipedriveError; end
19
22
  class AuthenticationError < PipedriveError; end
20
23
  class NotFoundError < PipedriveError; end
24
+ class BadRequestError < PipedriveError; end
25
+ class UnauthorizedError < PipedriveError; end
26
+ class PaymentRequiredError < PipedriveError; end
27
+ class ForbiddenError < PipedriveError; end
28
+ class MethodNotAllowedError < PipedriveError; end
29
+ class GoneError < PipedriveError; end
30
+ class UnsupportedMediaTypeError < PipedriveError; end
31
+ class UnprocessableEntityError < PipedriveError; end
32
+ class TooManyRequestsError < PipedriveError; end
33
+ class InternalServerError < PipedriveError; end
34
+ class NotImplementedError < PipedriveError; end
35
+ class ServiceUnavailableError < PipedriveError; end
21
36
  class UnkownAPIError < PipedriveError; end
37
+
38
+ ERROR_CLASS_MAP = {
39
+ "400" => BadRequestError,
40
+ "401" => UnauthorizedError,
41
+ "402" => PaymentRequiredError,
42
+ "403" => ForbiddenError,
43
+ "404" => NotFoundError,
44
+ "405" => MethodNotAllowedError,
45
+ "410" => GoneError,
46
+ "415" => UnsupportedMediaTypeError,
47
+ "422" => UnprocessableEntityError,
48
+ "429" => TooManyRequestsError,
49
+ "500" => InternalServerError,
50
+ "501" => NotImplementedError,
51
+ "503" => ServiceUnavailableError,
52
+ }.freeze
53
+
54
+ def raise_error(status, response)
55
+ return if [200, 201].include?(status)
56
+
57
+ message =
58
+ [response.dig(:error), response.dig(:error_info)]
59
+ .compact
60
+ .join(". ")
61
+
62
+ error_data =
63
+ response
64
+ .fetch(:data, {})
65
+ .inspect
66
+ .concat(response.fetch(:additional_data, {}).inspect)
67
+
68
+ error_class = ERROR_CLASS_MAP[status.to_s]
69
+ raise error_class.new(message, status, error_data) if error_class
70
+
71
+ raise UnkownAPIError.new(message, status, error_data)
72
+ end
73
+
74
+ module_function :raise_error
22
75
  end
@@ -116,7 +116,7 @@ module Pipedrive
116
116
  # init data
117
117
  @data = data
118
118
  # generate the methods
119
- data.each_key do |k|
119
+ data&.each_key do |k|
120
120
  # it could be a custom field diccionary
121
121
  m, is_custom_field = klass.fields_dicc&.dig(k) &&
122
122
  [klass.fields_dicc&.dig(k), true] ||
@@ -152,5 +152,10 @@ module Pipedrive
152
152
  protected def fetch_value(key, is_custom_field)
153
153
  @data[is_custom_field ? self.class.inverted_fields_dicc.dig(key) : key]
154
154
  end
155
+
156
+ def no_content?
157
+ @data.nil? || @data.empty?
158
+ end
159
+ alias empty? no_content?
155
160
  end
156
161
  end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pipedrive
4
+ class OrganizationField < Resource
5
+ self.resources_url = "organizationFields"
6
+ end
7
+ end
@@ -6,5 +6,6 @@ module Pipedrive
6
6
  include Merge
7
7
 
8
8
  has_many :deals, class_name: "Deal"
9
+ has_many :activities, class_name: "Activity"
9
10
  end
10
11
  end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pipedrive
4
+ class Subscription < Resource
5
+ # POST /subscriptions/recurring
6
+ # Adds a recurring subscription
7
+ def self.create_recurring(params)
8
+ response = request(
9
+ :post,
10
+ "#{resource_url}/recurring",
11
+ params
12
+ )
13
+ Subscription.new(response.dig(:data))
14
+ end
15
+
16
+ # GET /subscriptions/find/:id
17
+ # Returns details of a recurring subscription by the deal ID
18
+ def self.find_by_deal(id)
19
+ response = request(:get,"#{resource_url}/find/#{id}")
20
+ new(response.dig(:data))
21
+ end
22
+
23
+ # PUT /subscriptions/recurring/:id
24
+ # Updates a recurring subscription
25
+ def update_recurring(params = {})
26
+ response = request(
27
+ :put,
28
+ "#{self.class.resource_url}/recurring/#{id}",
29
+ params
30
+ )
31
+ Subscription.new(response.dig(:data))
32
+ end
33
+
34
+ # PUT /subscriptions/recurring/:id/cancel
35
+ # Cancels a recurring subscription
36
+ def cancel_recurring(params = {})
37
+ response = request(
38
+ :put,
39
+ "#{self.class.resource_url}/recurring/#{id}/cancel",
40
+ params
41
+ )
42
+ Subscription.new(response.dig(:data))
43
+ end
44
+
45
+ end
46
+ end
@@ -13,6 +13,7 @@ require "pipedrive/resources/lead_label"
13
13
  require "pipedrive/resources/lead_source"
14
14
  require "pipedrive/resources/lead"
15
15
  require "pipedrive/resources/organization"
16
+ require "pipedrive/resources/organization_field"
16
17
  require "pipedrive/resources/pipeline"
17
18
  require "pipedrive/resources/product"
18
19
  require "pipedrive/resources/person"
@@ -20,4 +21,5 @@ require "pipedrive/resources/note"
20
21
  require "pipedrive/resources/stage"
21
22
  require "pipedrive/resources/team"
22
23
  require "pipedrive/resources/user"
24
+ require "pipedrive/resources/subscription"
23
25
  require "pipedrive/resources/webhook"
@@ -3,18 +3,18 @@
3
3
  module Pipedrive
4
4
  module Util
5
5
  def self.serialize_response(response, symbolize_names: true)
6
- rjson = JSON.parse(response.body, symbolize_names: symbolize_names)
7
- return rjson if response.success?
6
+ if response.status == 204
7
+ return {} unless Pipedrive.treat_no_content_as_not_found
8
8
 
9
- raise_error(response.status, rjson)
10
- end
9
+ Pipedrive.raise_error(404, error: "HTTP 204 status code received. No content")
10
+ end
11
+
12
+ json_body = JSON.parse(response.body, symbolize_names: symbolize_names)
11
13
 
12
- def self.raise_error(status, response)
13
- case status
14
- when 404
15
- raise NotFoundError.new(response.dig(:error), status)
14
+ if response.success?
15
+ json_body
16
16
  else
17
- raise UnkownAPIError.new(response.dig(:error), status)
17
+ Pipedrive.raise_error(response.status, json_body)
18
18
  end
19
19
  end
20
20
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pipedrive
4
- VERSION = "1.2.6"
4
+ VERSION = "1.2.10"
5
5
  end
data/lib/pipedrive.rb CHANGED
@@ -27,7 +27,12 @@ module Pipedrive
27
27
  BASE_URL = "https://api.pipedrive.com/v1"
28
28
 
29
29
  class << self
30
- attr_accessor :api_key, :logger, :debug, :debug_http, :debug_http_body
30
+ attr_accessor :api_key,
31
+ :logger,
32
+ :debug,
33
+ :debug_http,
34
+ :debug_http_body,
35
+ :treat_no_content_as_not_found
31
36
  end
32
37
 
33
38
  @logger = Logger.new(STDOUT)
@@ -29,5 +29,5 @@ Gem::Specification.new do |spec|
29
29
  spec.require_paths = ["lib"]
30
30
 
31
31
  # dependencies
32
- spec.add_dependency("faraday", "~> 1.3")
32
+ spec.add_dependency("faraday", "< 3")
33
33
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pipedrive-connect
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.6
4
+ version: 1.2.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Get on Board
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-11 00:00:00.000000000 Z
11
+ date: 2022-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - "<"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.3'
19
+ version: '3'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - "<"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.3'
26
+ version: '3'
27
27
  description:
28
28
  email: team@getonbrd.com
29
29
  executables: []
@@ -66,10 +66,12 @@ files:
66
66
  - lib/pipedrive/resources/lead_source.rb
67
67
  - lib/pipedrive/resources/note.rb
68
68
  - lib/pipedrive/resources/organization.rb
69
+ - lib/pipedrive/resources/organization_field.rb
69
70
  - lib/pipedrive/resources/person.rb
70
71
  - lib/pipedrive/resources/pipeline.rb
71
72
  - lib/pipedrive/resources/product.rb
72
73
  - lib/pipedrive/resources/stage.rb
74
+ - lib/pipedrive/resources/subscription.rb
73
75
  - lib/pipedrive/resources/team.rb
74
76
  - lib/pipedrive/resources/user.rb
75
77
  - lib/pipedrive/resources/webhook.rb