pipedrive-connect 1.2.13 → 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 +4 -4
- data/CHANGELOG.md +11 -0
- data/Gemfile +1 -0
- data/bin/console +15 -4
- data/lib/pipedrive/fields.rb +13 -1
- data/lib/pipedrive/resource.rb +22 -4
- data/lib/pipedrive/resources/deal.rb +1 -23
- data/lib/pipedrive/resources/participant.rb +6 -0
- data/lib/pipedrive/resources.rb +1 -0
- data/lib/pipedrive/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8eea5a65d7d2e39294f3fa5a4a48fc0435776e3b026d315da8bad5ad6f167bdb
|
4
|
+
data.tar.gz: 9f36431228dfed9f9e05cad2083796d5ab2806c9195821b901df9a81893eef0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 598554f66789fa6be6e2896fba4badb65c2cfa757e2e084ad30496cac5f5dce5845b1900f6976d4c6d94fdfde2c0dcfd89a0e4449a18198daa55126453b6d204
|
7
|
+
data.tar.gz: 18c041a8723dc4d4a8e9f9c636daeec1ef549346d62d149baf1602019c70f30cd3b71d0bf18a23bfbee2d9b170d7551d90a87c9fc2af7e3ed5a155aefc9083d9
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,17 @@ 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
|
+
|
14
|
+
## [1.2.14] - 2023-01-31
|
15
|
+
|
16
|
+
- The codebase paginates until fetching all the fields so the diccionary of custom fields is complete (checkout `lib/pipedrive/fields` for more info)
|
17
|
+
|
7
18
|
## [1.2.13] - 2022-12-08
|
8
19
|
|
9
20
|
- Update `LeadLabel` resource to use _PATCH_ method (as according to the API doc)
|
data/Gemfile
CHANGED
data/bin/console
CHANGED
@@ -4,13 +4,24 @@
|
|
4
4
|
|
5
5
|
require "bundler/setup"
|
6
6
|
require "pipedrive"
|
7
|
+
require "pry"
|
8
|
+
require "irb"
|
7
9
|
|
8
10
|
# You can add fixtures and/or initialization code here to make experimenting
|
9
11
|
# with your gem easier. You can also use a different console, if you like.
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
#
|
13
|
+
def reload!(print = true)
|
14
|
+
puts "Reloading ..." if print
|
15
|
+
# Main project directory.
|
16
|
+
root_dir = File.expand_path("..", __dir__)
|
17
|
+
# Directories within the project that should be reloaded.
|
18
|
+
reload_dirs = %w[lib]
|
19
|
+
# Loop through and reload every file in all relevant project directories.
|
20
|
+
reload_dirs.each do |dir|
|
21
|
+
Dir.glob("#{root_dir}/#{dir}/**/*.rb").each { |f| load(f) }
|
22
|
+
end
|
23
|
+
# Return true when complete.
|
24
|
+
true
|
25
|
+
end
|
14
26
|
|
15
|
-
require "irb"
|
16
27
|
IRB.start(__FILE__)
|
data/lib/pipedrive/fields.rb
CHANGED
@@ -12,7 +12,19 @@ module Pipedrive
|
|
12
12
|
module ClassMethods
|
13
13
|
def fields
|
14
14
|
url = fields_url || "#{class_name.downcase}Fields"
|
15
|
-
|
15
|
+
|
16
|
+
data = []
|
17
|
+
start = 0
|
18
|
+
request_more_fields = true
|
19
|
+
|
20
|
+
while request_more_fields
|
21
|
+
response = request(:get, url, start: start)
|
22
|
+
data.concat(response.dig(:data))
|
23
|
+
# Check wether there are more fields to bring
|
24
|
+
metadata = response.dig(:additional_data, :pagination)
|
25
|
+
request_more_fields = metadata&.fetch(:more_items_in_collection, false)
|
26
|
+
start = metadata[:next_start] if request_more_fields
|
27
|
+
end
|
16
28
|
# return a hash prefilled with
|
17
29
|
# the fields hash and name parameterized
|
18
30
|
# and the original array of fields (schema)
|
data/lib/pipedrive/resource.rb
CHANGED
@@ -10,7 +10,7 @@ module Pipedrive
|
|
10
10
|
class << self
|
11
11
|
attr_accessor :resources_url
|
12
12
|
|
13
|
-
def update_method(method_override=nil)
|
13
|
+
def update_method(method_override = nil)
|
14
14
|
@update_method ||= method_override
|
15
15
|
end
|
16
16
|
|
@@ -66,20 +66,22 @@ 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,
|
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
|
78
80
|
class_name = "::Pipedrive::#{class_name}" unless class_name.include?("Pipedrive")
|
79
81
|
define_method(resource_name) do |params = {}|
|
80
82
|
response = request(:get,
|
81
|
-
|
82
|
-
|
83
|
+
"#{resource_url}/#{resource_name}",
|
84
|
+
params.merge(options))
|
83
85
|
response.dig(:data)&.map do |data|
|
84
86
|
class_name_as_sym = class_name_lower_case.to_sym
|
85
87
|
data[:metadata] = data
|
@@ -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
|
data/lib/pipedrive/resources.rb
CHANGED
@@ -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"
|
data/lib/pipedrive/version.rb
CHANGED
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.
|
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:
|
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
|