pipedrive-connect 1.2.14 → 1.3.0

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: 8eea5a65d7d2e39294f3fa5a4a48fc0435776e3b026d315da8bad5ad6f167bdb
4
+ data.tar.gz: 9f36431228dfed9f9e05cad2083796d5ab2806c9195821b901df9a81893eef0d
5
5
  SHA512:
6
- metadata.gz: 6bc678ae0f3aacea13f25f0af9426b88d27c13563ad89cdbf8cb934b32687bcc0b3316749ff0c14417e252553dd887b7bf00ad6a1cd26db5273d5a9d3c3460a7
7
- data.tar.gz: b89e76e137037be243b0403a5bce4a2809db8cd5054b07177fd4fffba56f6954ee3726f282a32dc4a6b8290ea9df36243d6a32db8530741e222a7670c28c043e
6
+ metadata.gz: 598554f66789fa6be6e2896fba4badb65c2cfa757e2e084ad30496cac5f5dce5845b1900f6976d4c6d94fdfde2c0dcfd89a0e4449a18198daa55126453b6d204
7
+ data.tar.gz: 18c041a8723dc4d4a8e9f9c636daeec1ef549346d62d149baf1602019c70f30cd3b71d0bf18a23bfbee2d9b170d7551d90a87c9fc2af7e3ed5a155aefc9083d9
data/CHANGELOG.md CHANGED
@@ -4,6 +4,13 @@ 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.3.0] - 2023-04-17
8
+
9
+ - Modify `has_many` to generate methods to `add` and `delete` resources. ie. `add_participant`, `add_product`, `delete_product`
10
+ - Add `Pipedrive::Participant` resource and add the association to `Pipedrive::Deal`
11
+ - BREAKING CHANGE: Removed `delete_attached_product` in favor of `delete_product` passing a hash of params instead of an instance of `Pipedrive::Resource`
12
+ - BREAKING CHANGE: `add_product` changed method signature because of the changes introduced in `has_many`
13
+
7
14
  ## [1.2.14] - 2023-01-31
8
15
 
9
16
  - The codebase paginates until fetching all the fields so the diccionary of custom fields is complete (checkout `lib/pipedrive/fields` for more info)
@@ -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[0..-1]
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
@@ -89,6 +91,22 @@ module Pipedrive
89
91
  Object.const_get(class_name).new(data)
90
92
  end
91
93
  end
94
+
95
+ define_method("add_#{singular}") do |params|
96
+ response = request(
97
+ :post,
98
+ "#{resource_url}/#{resource_name}",
99
+ params.merge(id: id)
100
+ )
101
+ Object.const_get(class_name).new(response.dig(:data))
102
+ end
103
+
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}")
108
+ response[:success]
109
+ end
92
110
  end
93
111
  end
94
112
 
@@ -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,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pipedrive
4
+ class Participant < Resource
5
+ end
6
+ 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.0"
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.0
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-05-18 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