pipedrive-connect 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8eea5a65d7d2e39294f3fa5a4a48fc0435776e3b026d315da8bad5ad6f167bdb
4
- data.tar.gz: 9f36431228dfed9f9e05cad2083796d5ab2806c9195821b901df9a81893eef0d
3
+ metadata.gz: 802a599c26c15ec1dd3dca1ec4601dae2e1687138f4208a979e1da0bb4a3a80b
4
+ data.tar.gz: a330bd75c0dc1713873e82fad5014c2091b1b50933ebaf7f4021b14d3c8bd846
5
5
  SHA512:
6
- metadata.gz: 598554f66789fa6be6e2896fba4badb65c2cfa757e2e084ad30496cac5f5dce5845b1900f6976d4c6d94fdfde2c0dcfd89a0e4449a18198daa55126453b6d204
7
- data.tar.gz: 18c041a8723dc4d4a8e9f9c636daeec1ef549346d62d149baf1602019c70f30cd3b71d0bf18a23bfbee2d9b170d7551d90a87c9fc2af7e3ed5a155aefc9083d9
6
+ metadata.gz: 862a75c93af2ab058fac2bc491ed0125bbc9cc8beff21c32a7b53c2874010d3bf5759978f92917cdd786fe83510f4e0bc67bf4b07eee825f065aa02821375be0
7
+ data.tar.gz: 81656beb8265d16d4f6105b3046ede92cbf3a08555b696f9960e979ed343abf17abb0437055330d3c37080d053e145e4a30173b640aac3f42b3031784878fbe6
data/CHANGELOG.md CHANGED
@@ -2,8 +2,13 @@
2
2
 
3
3
  This file contains all notable changes to this project.
4
4
  This project adheres to [Semantic Versioning](http://semver.org/).
5
+
5
6
  This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/).
6
7
 
8
+ ## [1.3.1] - 2023-06-01
9
+
10
+ - **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).
11
+
7
12
  ## [1.3.0] - 2023-04-17
8
13
 
9
14
  - Modify `has_many` to generate methods to `add` and `delete` resources. ie. `add_participant`, `add_product`, `delete_product`
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
+ ### Has many methods
101
+
102
+ ```ruby
103
+ deal = Pipedrive::Deal.retrieve 1
104
+ person = Pipedrive::Person.retrieve 1
105
+ product = Pipedrive::Product.retrieve 1
106
+
107
+ # add a participant
108
+ deal.add_participant(person_id: person.id)
109
+
110
+ # attach a product to a deal returning the attachment data
111
+ product_attachment =
112
+ deal.add_product(product_id: product.id,
113
+ item_price: 99,
114
+ quantity: 2,
115
+ discount_percentage: 5)
116
+
117
+ # detach a product from a deal
118
+ # Note: product attachment is not the product per se
119
+ # but the record that represent the attachment
120
+ deal.delete_product(product_attachment.id)
121
+ ```
122
+
100
123
  ### 204 No Content responses
101
124
 
102
125
  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.
@@ -73,7 +73,7 @@ module Pipedrive
73
73
  "For example has_many :deals, class_name: 'Deal'"
74
74
  end
75
75
  class_name_lower_case = class_name.downcase
76
- singular = args[:singular] || class_name_lower_case[0..-1]
76
+ singular = args[:singular] || class_name_lower_case
77
77
  # always include all the data of the resource
78
78
  options = { "include_#{class_name_lower_case}_data": 1 }
79
79
  # add namespace to class_name
@@ -82,14 +82,16 @@ module Pipedrive
82
82
  response = request(:get,
83
83
  "#{resource_url}/#{resource_name}",
84
84
  params.merge(options))
85
- response.dig(:data)&.map do |data|
86
- class_name_as_sym = class_name_lower_case.to_sym
87
- data[:metadata] = data
88
- if data.key?(class_name_as_sym)
89
- data = data.merge(data.delete(class_name_as_sym))
85
+ response
86
+ .dig(:data)
87
+ &.map do |data|
88
+ class_name_as_sym = class_name_lower_case.to_sym
89
+ data[:metadata] = data
90
+ if data.key?(class_name_as_sym)
91
+ data = data.merge(data.delete(class_name_as_sym))
92
+ end
93
+ Object.const_get(class_name).new(data)
90
94
  end
91
- Object.const_get(class_name).new(data)
92
- end
93
95
  end
94
96
 
95
97
  define_method("add_#{singular}") do |params|
@@ -101,10 +103,8 @@ module Pipedrive
101
103
  Object.const_get(class_name).new(response.dig(:data))
102
104
  end
103
105
 
104
- define_method("delete_#{singular}") do |resource|
105
- raise "Param *resource* is not an instance of Pipedrive::Resource" \
106
- unless resource.is_a?(Pipedrive::Resource)
107
- response = request(:delete, "#{resource_url}/#{resource_name}/#{resource.id}")
106
+ define_method("delete_#{singular}") do |resource_id|
107
+ response = request(:delete, "#{resource_url}/#{resource_name}/#{resource_id}")
108
108
  response[:success]
109
109
  end
110
110
  end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pipedrive
4
- class Participant < Resource
5
- end
4
+ class Participant < Resource; end
6
5
  end
@@ -4,7 +4,7 @@ module Pipedrive
4
4
  class Person < Resource
5
5
  include Fields
6
6
  include Merge
7
-
7
+
8
8
  has_many :deals, class_name: "Deal"
9
9
  has_many :activities, class_name: "Activity"
10
10
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pipedrive
4
- VERSION = "1.3.0"
4
+ VERSION = "1.3.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pipedrive-connect
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
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: 2023-05-18 00:00:00.000000000 Z
11
+ date: 2023-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday