pipe_drive_ruby_wrapper 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pipe_drive/base.rb +4 -4
- data/lib/pipe_drive/field_base.rb +5 -5
- data/spec/lib/deal_spec.rb +1 -1
- data/spec/lib/organization_spec.rb +1 -1
- data/spec/lib/person_spec.rb +1 -1
- data/spec/pipe_drive_ruby_wrapper_spec.rb +2 -2
- data/spec/spec_helper.rb +3 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93e0fdacc778f6cdd1a7b227d8c34187b27a29ca410f6f2abd175dff39e442c3
|
4
|
+
data.tar.gz: 8ed2f42c1e757de34b76017bb98f085c7ed39ad1a8241837855d5e3a07bbf92b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ee7df332dd515924942efe3ca8d68c2290a895968332279ace8e563576279d97f9fe3046d006afe2adaec9008908726b1697cae64a80b0fc0bcf0e05b2baea3
|
7
|
+
data.tar.gz: 05a9e1339fa9c285d4833ee0dd90233f24871455caf02eab460a265b542ea68b41edaf1f01ca84542aa6c3763c0dbde9f70f88b7e7897ba6b475e125af16b971
|
data/lib/pipe_drive/base.rb
CHANGED
@@ -14,7 +14,7 @@ module PipeDrive
|
|
14
14
|
|
15
15
|
def update(opts)
|
16
16
|
path = "/#{self.class.resource_name}s/#{id}"
|
17
|
-
opts.transform_keys!{|key| self.class.field_keys[key]
|
17
|
+
opts.transform_keys!{|key| self.class.field_keys[key].present? ? self.class.field_keys[key][:key] : key}
|
18
18
|
requester.http_put(path, opts) do |result|
|
19
19
|
self.class.new(result)
|
20
20
|
end
|
@@ -42,7 +42,7 @@ module PipeDrive
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def create(opts)
|
45
|
-
opts.transform_keys!{|key| field_keys[key]
|
45
|
+
opts.transform_keys!{|key| field_keys[key].present? ? field_keys[key][:key] : key}
|
46
46
|
requester.http_post("/#{resource_name}s", opts) do |result|
|
47
47
|
new(result)
|
48
48
|
end
|
@@ -50,7 +50,7 @@ module PipeDrive
|
|
50
50
|
|
51
51
|
def update(id, opts)
|
52
52
|
path = "/#{resource_name}s/#{id}"
|
53
|
-
opts.transform_keys!{|key| field_keys[key]
|
53
|
+
opts.transform_keys!{|key| field_keys[key].present? ? field_keys[key][:key] : key}
|
54
54
|
requester.http_put(path, opts) do |result|
|
55
55
|
new(result)
|
56
56
|
end
|
@@ -77,7 +77,7 @@ module PipeDrive
|
|
77
77
|
end
|
78
78
|
|
79
79
|
def parameterize(target_string, separator)
|
80
|
-
target_string.gsub!(/[
|
80
|
+
target_string.gsub!(/[\W_]+/, separator)
|
81
81
|
target_string.downcase
|
82
82
|
end
|
83
83
|
|
@@ -3,7 +3,7 @@ module PipeDrive
|
|
3
3
|
def add_to_field_keys
|
4
4
|
resource = self.class.correspond_resource.to_sym
|
5
5
|
field_name = parameterize(name, '_').to_sym
|
6
|
-
PipeDrive.field_keys[resource][field_name] = key
|
6
|
+
PipeDrive.field_keys[resource][field_name] = {id: id, key: key}
|
7
7
|
end
|
8
8
|
|
9
9
|
class << self
|
@@ -33,7 +33,7 @@ module PipeDrive
|
|
33
33
|
resource = correspond_resource.to_sym
|
34
34
|
list.each do |field|
|
35
35
|
field_name = parameterize(field.name, '_').to_sym
|
36
|
-
field_keys_map[resource][field_name] = field.key
|
36
|
+
field_keys_map[resource][field_name] = {id: field.id, key: field.key}
|
37
37
|
end
|
38
38
|
field_keys_map
|
39
39
|
end
|
@@ -43,15 +43,15 @@ module PipeDrive
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def pipedrive_key_of(field_name)
|
46
|
-
cache_field_name = parameterize(field_name, '_').to_sym
|
46
|
+
cache_field_name = field_name.is_a?(String) ? parameterize(field_name, '_').to_sym : field_name
|
47
47
|
pipedrive_key = cache_keys[cache_field_name]
|
48
|
-
return pipedrive_key unless pipedrive_key.nil?
|
48
|
+
return pipedrive_key[:key] unless pipedrive_key.nil?
|
49
49
|
PipeDrive.reset_field_keys!
|
50
50
|
pipedrive_key = cache_keys[cache_field_name]
|
51
51
|
if pipedrive_key.nil?
|
52
52
|
raise TargetNotFound.new(self.name, :name, field_name)
|
53
53
|
else
|
54
|
-
pipedrive_key
|
54
|
+
pipedrive_key[:key]
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
data/spec/lib/deal_spec.rb
CHANGED
@@ -8,7 +8,7 @@ RSpec.describe PipeDrive::Deal do
|
|
8
8
|
|
9
9
|
context '.field_keys' do
|
10
10
|
it 'should obtain person custom field' do
|
11
|
-
deal_custom_fields = {product: 'product key'}
|
11
|
+
deal_custom_fields = {product: {id: 3, key: 'product key'}}
|
12
12
|
expect(PipeDrive::Deal.field_keys).to eq(deal_custom_fields)
|
13
13
|
end
|
14
14
|
end
|
@@ -8,7 +8,7 @@ RSpec.describe PipeDrive::Organization do
|
|
8
8
|
|
9
9
|
context '.field_keys' do
|
10
10
|
it 'should obtain person custom field' do
|
11
|
-
org_custom_fields = {region: 'region key'}
|
11
|
+
org_custom_fields = {region: {id: 1, key: 'region key'}}
|
12
12
|
expect(PipeDrive::Organization.field_keys).to eq(org_custom_fields)
|
13
13
|
end
|
14
14
|
end
|
data/spec/lib/person_spec.rb
CHANGED
@@ -8,7 +8,7 @@ RSpec.describe PipeDrive::Person do
|
|
8
8
|
|
9
9
|
context '.field_keys' do
|
10
10
|
it 'should obtain person custom field' do
|
11
|
-
person_custom_fields = {role: 'role key'}
|
11
|
+
person_custom_fields = {role: {id: 2, key: 'role key'}}
|
12
12
|
expect(PipeDrive::Person.field_keys).to eq(person_custom_fields)
|
13
13
|
end
|
14
14
|
end
|
@@ -4,7 +4,7 @@ RSpec.describe PipeDrive do
|
|
4
4
|
PipeDrive.setup do |config|
|
5
5
|
config.api_token = 'api token'
|
6
6
|
config.field_keys = {
|
7
|
-
person: {test: 'test_key'}
|
7
|
+
person: {test: {id: 1, key: 'test_key'}}
|
8
8
|
}
|
9
9
|
config.stage_ids = {
|
10
10
|
1 => {
|
@@ -13,7 +13,7 @@ RSpec.describe PipeDrive do
|
|
13
13
|
}
|
14
14
|
end
|
15
15
|
expect(PipeDrive.api_token).to eq('api token')
|
16
|
-
expect(PipeDrive.field_keys).to eq({person: {test: 'test_key'}})
|
16
|
+
expect(PipeDrive.field_keys).to eq({person: {test: {id: 1, key: 'test_key'}}})
|
17
17
|
expect(PipeDrive.stage_ids).to eq({1 => {test: 1}})
|
18
18
|
end
|
19
19
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -13,13 +13,13 @@ PipeDrive.setup do |config|
|
|
13
13
|
config.api_token = 'api_token'
|
14
14
|
config.field_keys = {
|
15
15
|
organization: {
|
16
|
-
region: 'region key'
|
16
|
+
region: {id: 1, key: 'region key'}
|
17
17
|
},
|
18
18
|
person: {
|
19
|
-
role: 'role key'
|
19
|
+
role: {id: 2, key: 'role key'}
|
20
20
|
},
|
21
21
|
deal: {
|
22
|
-
product: 'product key'
|
22
|
+
product: {id: 3, key: 'product key'}
|
23
23
|
}
|
24
24
|
}
|
25
25
|
config.stage_ids = {
|