pipedrive-connect 1.2.14 → 1.3.1

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: fdbad8b1fea466decfba502bd303d1dbd80e71bd9902baaaaa5f94ac53466bee
4
- data.tar.gz: 4de6d7d9e2f791a993cdfe3bc6d678379b7009b13e684a87389aa6ebbcfa1e37
3
+ metadata.gz: 802a599c26c15ec1dd3dca1ec4601dae2e1687138f4208a979e1da0bb4a3a80b
4
+ data.tar.gz: a330bd75c0dc1713873e82fad5014c2091b1b50933ebaf7f4021b14d3c8bd846
5
5
  SHA512:
6
- metadata.gz: 6bc678ae0f3aacea13f25f0af9426b88d27c13563ad89cdbf8cb934b32687bcc0b3316749ff0c14417e252553dd887b7bf00ad6a1cd26db5273d5a9d3c3460a7
7
- data.tar.gz: b89e76e137037be243b0403a5bce4a2809db8cd5054b07177fd4fffba56f6954ee3726f282a32dc4a6b8290ea9df36243d6a32db8530741e222a7670c28c043e
6
+ metadata.gz: 862a75c93af2ab058fac2bc491ed0125bbc9cc8beff21c32a7b53c2874010d3bf5759978f92917cdd786fe83510f4e0bc67bf4b07eee825f065aa02821375be0
7
+ data.tar.gz: 81656beb8265d16d4f6105b3046ede92cbf3a08555b696f9960e979ed343abf17abb0437055330d3c37080d053e145e4a30173b640aac3f42b3031784878fbe6
data/CHANGELOG.md CHANGED
@@ -2,8 +2,20 @@
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
+
12
+ ## [1.3.0] - 2023-04-17
13
+
14
+ - Modify `has_many` to generate methods to `add` and `delete` resources. ie. `add_participant`, `add_product`, `delete_product`
15
+ - Add `Pipedrive::Participant` resource and add the association to `Pipedrive::Deal`
16
+ - BREAKING CHANGE: Removed `delete_attached_product` in favor of `delete_product` passing a hash of params instead of an instance of `Pipedrive::Resource`
17
+ - BREAKING CHANGE: `add_product` changed method signature because of the changes introduced in `has_many`
18
+
7
19
  ## [1.2.14] - 2023-01-31
8
20
 
9
21
  - The codebase paginates until fetching all the fields so the diccionary of custom fields is complete (checkout `lib/pipedrive/fields` for more info)
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.
@@ -66,12 +66,14 @@ module Pipedrive
66
66
  response.dig(:data, :items).map { |d| new(d.dig(:item)) }
67
67
  end
68
68
 
69
- def has_many(resource_name, class_name:)
69
+ def has_many(resource_name, args = {})
70
+ class_name = args[:class_name]
70
71
  unless resource_name && class_name
71
72
  raise "You must specify the resource name and its class name " \
72
73
  "For example has_many :deals, class_name: 'Deal'"
73
74
  end
74
75
  class_name_lower_case = class_name.downcase
76
+ singular = args[:singular] || class_name_lower_case
75
77
  # always include all the data of the resource
76
78
  options = { "include_#{class_name_lower_case}_data": 1 }
77
79
  # add namespace to class_name
@@ -80,14 +82,30 @@ module Pipedrive
80
82
  response = request(:get,
81
83
  "#{resource_url}/#{resource_name}",
82
84
  params.merge(options))
83
- response.dig(:data)&.map do |data|
84
- class_name_as_sym = class_name_lower_case.to_sym
85
- data[:metadata] = data
86
- if data.key?(class_name_as_sym)
87
- 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)
88
94
  end
89
- Object.const_get(class_name).new(data)
90
- end
95
+ end
96
+
97
+ define_method("add_#{singular}") do |params|
98
+ response = request(
99
+ :post,
100
+ "#{resource_url}/#{resource_name}",
101
+ params.merge(id: id)
102
+ )
103
+ Object.const_get(class_name).new(response.dig(:data))
104
+ end
105
+
106
+ define_method("delete_#{singular}") do |resource_id|
107
+ response = request(:delete, "#{resource_url}/#{resource_name}/#{resource_id}")
108
+ response[:success]
91
109
  end
92
110
  end
93
111
  end
@@ -6,28 +6,6 @@ module Pipedrive
6
6
  include Merge
7
7
 
8
8
  has_many :products, class_name: "Product"
9
-
10
- # POST /deals/:id/products
11
- # Add a product to this deal
12
- def add_product(product, params)
13
- raise "Param *product* is not an instance of Pipedrive::Product" \
14
- unless product.is_a?(Pipedrive::Product)
15
- raise "Param :item_price is required" unless params.key?(:item_price)
16
- raise "Param :quantity is required" unless params.key?(:quantity)
17
-
18
- response = request(
19
- :post,
20
- "#{resource_url}/products",
21
- params.merge(id: id, product_id: product.id)
22
- )
23
- Product.new(response.dig(:data))
24
- end
25
-
26
- # DELETE /deals/:id/products/:product_attachment_id
27
- # Detach a product from this deal
28
- def delete_attached_product(product_attachment_id)
29
- response = request(:delete, "#{resource_url}/products/#{product_attachment_id}")
30
- response[:success]
31
- end
9
+ has_many :participants, class_name: "Participant"
32
10
  end
33
11
  end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pipedrive
4
+ class Participant < Resource; end
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
@@ -14,6 +14,7 @@ require "pipedrive/resources/lead_source"
14
14
  require "pipedrive/resources/lead"
15
15
  require "pipedrive/resources/organization"
16
16
  require "pipedrive/resources/organization_field"
17
+ require "pipedrive/resources/participant"
17
18
  require "pipedrive/resources/pipeline"
18
19
  require "pipedrive/resources/product"
19
20
  require "pipedrive/resources/person"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pipedrive
4
- VERSION = "1.2.14"
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.2.14
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-01-31 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
@@ -67,6 +67,7 @@ files:
67
67
  - lib/pipedrive/resources/note.rb
68
68
  - lib/pipedrive/resources/organization.rb
69
69
  - lib/pipedrive/resources/organization_field.rb
70
+ - lib/pipedrive/resources/participant.rb
70
71
  - lib/pipedrive/resources/person.rb
71
72
  - lib/pipedrive/resources/pipeline.rb
72
73
  - lib/pipedrive/resources/product.rb