pipe_drive_ruby_wrapper 0.2.2 → 0.2.7
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/deal.rb +10 -0
- data/lib/pipe_drive/field_base.rb +30 -10
- data/lib/pipe_drive/pipeline.rb +12 -0
- data/lib/pipe_drive/resource_base.rb +24 -0
- data/lib/pipe_drive_ruby_wrapper.rb +34 -15
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2647fab70c379ff20436d080ddd527925ec09675e1d1877feae8ec3906bf6a3c
|
4
|
+
data.tar.gz: 15193cb7e1e84fc3b35f29540f45f07b61216e18d5cac6d386b8de944440823a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a8849be98b7fa2c1a62902ae9b09ffb06507d6f183f1942f5181d4f02450b0768ab71e763bdb1e547afbddf8c284c9ed3138767cafdeb72d2e4f554a9a30eba
|
7
|
+
data.tar.gz: 61c2c6c60c020b017a21bc699367e7b94d5fed2e6c015aa40dbafa03e81560adeaeba1ad8c078ae38fca68eb63a2386d0fab75052b8a140feafa1aae7e6338c5
|
data/lib/pipe_drive/deal.rb
CHANGED
@@ -2,5 +2,15 @@ module PipeDrive
|
|
2
2
|
class Deal < ResourceBase
|
3
3
|
ALLOW_FOR_SEARCH_TERMS = %i[title]
|
4
4
|
ALLOW_FOR_ADDITION_SEARCH_OPTS = %i[org_id person_id]
|
5
|
+
|
6
|
+
def organization
|
7
|
+
pipedrive_org_id = org_id.is_a?(Hash) ? org_id[:value] : org_id
|
8
|
+
Organization.find_by_id(pipedrive_org_id)
|
9
|
+
end
|
10
|
+
|
11
|
+
def person
|
12
|
+
pipedrive_person_id = person_id.is_a?(Hash) ? person_id[:value] : person_id
|
13
|
+
Person.find_by_id(pipedrive_person_id)
|
14
|
+
end
|
5
15
|
end
|
6
16
|
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module PipeDrive
|
2
2
|
class FieldBase < Base
|
3
|
-
def
|
3
|
+
def add_to_field_infos
|
4
4
|
resource = self.class.correspond_resource.to_sym
|
5
|
-
field_name = parameterize(name, '_')
|
6
|
-
PipeDrive.field_keys[resource][field_name] = {id: id, key: key}
|
5
|
+
field_name = parameterize(name, '_')
|
6
|
+
PipeDrive.field_keys[resource][field_name.to_sym] = {id: id, key: key}
|
7
|
+
PipeDrive.field_names[resource][key] = {id: id, name: field_name}
|
7
8
|
end
|
8
9
|
|
9
10
|
class << self
|
@@ -33,36 +34,55 @@ module PipeDrive
|
|
33
34
|
|
34
35
|
def create(opts)
|
35
36
|
new_field = super(opts)
|
36
|
-
new_field.
|
37
|
+
new_field.add_to_field_infos
|
37
38
|
end
|
38
39
|
|
39
|
-
def
|
40
|
+
def field_infos_map
|
40
41
|
field_keys_map = Hash.new{|hash, key| hash[key] = {}}
|
42
|
+
field_names_map = Hash.new{|hash, key| hash[key] = {}}
|
41
43
|
resource = correspond_resource.to_sym
|
42
44
|
list.each do |field|
|
43
|
-
|
44
|
-
|
45
|
+
next if field.id.nil?
|
46
|
+
field_name = parameterize(field.name, '_')
|
47
|
+
field_keys_map[resource][field_name.to_sym] = {id: field.id, key: field.key}
|
48
|
+
field_names_map[resource][field.key] = {id: field.id, name: field_name}
|
45
49
|
end
|
46
|
-
field_keys_map
|
50
|
+
{key_map: field_keys_map, name_map: field_names_map}
|
47
51
|
end
|
48
52
|
|
49
53
|
def cache_keys
|
50
54
|
PipeDrive.field_keys[correspond_resource.to_sym]
|
51
55
|
end
|
52
56
|
|
57
|
+
def cache_names
|
58
|
+
PipeDrive.field_names[correspond_resource.to_sym]
|
59
|
+
end
|
60
|
+
|
53
61
|
def pipedrive_key_of(field_name)
|
54
62
|
cache_field_name = field_name.is_a?(String) ? parameterize(field_name, '_').to_sym : field_name
|
55
63
|
pipedrive_key = cache_keys[cache_field_name]
|
56
64
|
return pipedrive_key[:key] unless pipedrive_key.nil?
|
57
|
-
PipeDrive.
|
65
|
+
PipeDrive.reset_field_infos!
|
58
66
|
pipedrive_key = cache_keys[cache_field_name]
|
59
67
|
if pipedrive_key.nil?
|
60
|
-
raise TargetNotFound.new(self.name, :
|
68
|
+
raise TargetNotFound.new(self.name, :field_name, field_name)
|
61
69
|
else
|
62
70
|
pipedrive_key[:key]
|
63
71
|
end
|
64
72
|
end
|
65
73
|
|
74
|
+
def pipedrive_name_of(field_key)
|
75
|
+
pipedrive_name = cache_names[field_key]
|
76
|
+
return pipedrive_name[:name] unless pipedrive_name.nil?
|
77
|
+
PipeDrive.reset_field_infos!
|
78
|
+
pipedrive_name = cache_names[field_key]
|
79
|
+
if pipedrive_name.nil?
|
80
|
+
raise TargetNotFound.new(self.name, :field_key, field_key)
|
81
|
+
else
|
82
|
+
pipedrive_name[:name]
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
66
86
|
end
|
67
87
|
end
|
68
88
|
end
|
data/lib/pipe_drive/pipeline.rb
CHANGED
@@ -3,5 +3,17 @@ module PipeDrive
|
|
3
3
|
ALLOW_FOR_SEARCH_TERMS = %i[name]
|
4
4
|
ALLOW_FOR_ADDITION_SEARCH_OPTS = %i[]
|
5
5
|
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def pipeline_ids_map
|
9
|
+
id_map = {}
|
10
|
+
list.each do |pipeline|
|
11
|
+
pipeline_name = parameterize(pipeline.name, '_').to_sym
|
12
|
+
id_map[pipeline_name] = pipeline.id
|
13
|
+
end
|
14
|
+
id_map
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
6
18
|
end
|
7
19
|
end
|
@@ -1,6 +1,26 @@
|
|
1
1
|
module PipeDrive
|
2
2
|
class ResourceBase < Base
|
3
3
|
|
4
|
+
def initialize(attrs)
|
5
|
+
unless self.class.field_names.nil?
|
6
|
+
data = attrs[:data] || PipeDrive.hash_except(attrs, [:additional_data])
|
7
|
+
processed_data = {}
|
8
|
+
data.each_pair do |key, value|
|
9
|
+
key = key.to_s
|
10
|
+
if key.end_with?('_id')
|
11
|
+
field_name = key
|
12
|
+
else
|
13
|
+
field_name_map = self.class.field_names[key]
|
14
|
+
field_name = field_name_map.nil? ? key : field_name_map[:name]
|
15
|
+
end
|
16
|
+
processed_data[field_name] = value
|
17
|
+
end
|
18
|
+
attrs[:data] = processed_data
|
19
|
+
end
|
20
|
+
|
21
|
+
super(attrs)
|
22
|
+
end
|
23
|
+
|
4
24
|
protected
|
5
25
|
|
6
26
|
def pagination(path, params, &block)
|
@@ -17,6 +37,10 @@ module PipeDrive
|
|
17
37
|
PipeDrive.field_keys[resource_name.to_sym]
|
18
38
|
end
|
19
39
|
|
40
|
+
def field_names
|
41
|
+
PipeDrive.field_names[resource_name.to_sym]
|
42
|
+
end
|
43
|
+
|
20
44
|
def resource_class
|
21
45
|
self
|
22
46
|
end
|
@@ -11,7 +11,7 @@ module PipeDrive
|
|
11
11
|
FIELD_CLASSES = %w[OrganizationField PersonField DealField]
|
12
12
|
|
13
13
|
class << self; attr_accessor :api_token; end
|
14
|
-
class << self; attr_writer :field_keys, :stage_ids; end
|
14
|
+
class << self; attr_writer :field_keys, :field_names, :stage_ids, :pipeline_ids; end
|
15
15
|
|
16
16
|
class << self
|
17
17
|
def setup
|
@@ -19,32 +19,39 @@ module PipeDrive
|
|
19
19
|
self
|
20
20
|
end
|
21
21
|
|
22
|
+
def field_infos
|
23
|
+
return @field_infos unless @field_infos.nil? || @field_infos.empty?
|
24
|
+
@field_infos = obtain_field_infos
|
25
|
+
end
|
26
|
+
|
27
|
+
def reset_field_infos!
|
28
|
+
@field_infos = obtain_field_infos
|
29
|
+
end
|
30
|
+
|
22
31
|
def field_keys
|
23
|
-
|
24
|
-
@field_keys = {}
|
25
|
-
FIELD_CLASSES.each do |class_name|
|
26
|
-
@field_keys.merge!(const_get(class_name).field_keys_map)
|
27
|
-
end
|
28
|
-
@field_keys
|
32
|
+
@fields_keys = field_infos[:key_map]
|
29
33
|
end
|
30
34
|
|
31
|
-
def
|
32
|
-
@
|
33
|
-
FIELD_CLASSES.each do |class_name|
|
34
|
-
@field_keys.merge!(const_get(class_name).field_keys_map)
|
35
|
-
end
|
36
|
-
@field_keys
|
35
|
+
def field_names
|
36
|
+
@field_names = field_infos[:name_map]
|
37
37
|
end
|
38
38
|
|
39
39
|
def stage_ids
|
40
|
-
|
41
|
-
@stage_ids = Stage.stage_ids_map
|
40
|
+
@stage_ids ||= Stage.stage_ids_map
|
42
41
|
end
|
43
42
|
|
44
43
|
def reset_stage_ids!
|
45
44
|
@stage_ids = Stage.stage_ids_map
|
46
45
|
end
|
47
46
|
|
47
|
+
def pipeline_ids
|
48
|
+
@pipeline_ids ||= Pipeline.pipeline_ids_map
|
49
|
+
end
|
50
|
+
|
51
|
+
def reset_pipeline_ids!
|
52
|
+
@pipeline_ids = Pipeline.pipeline_ids_map
|
53
|
+
end
|
54
|
+
|
48
55
|
def host
|
49
56
|
"https://api.pipedrive.com"
|
50
57
|
end
|
@@ -58,6 +65,18 @@ module PipeDrive
|
|
58
65
|
remain_keys = all_keys - except_keys
|
59
66
|
hash.slice(*remain_keys)
|
60
67
|
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def obtain_field_infos
|
72
|
+
field_infos = {key_map: {}, name_map: {}}
|
73
|
+
FIELD_CLASSES.each do |class_name|
|
74
|
+
infos = const_get(class_name).field_infos_map
|
75
|
+
field_infos[:key_map].merge!(infos[:key_map])
|
76
|
+
field_infos[:name_map].merge!(infos[:name_map])
|
77
|
+
end
|
78
|
+
field_infos
|
79
|
+
end
|
61
80
|
end
|
62
81
|
|
63
82
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pipe_drive_ruby_wrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- JiaRou Lee
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -58,7 +58,7 @@ homepage: https://github.com/laura34963/pipe_drive_ruby_wrapper
|
|
58
58
|
licenses:
|
59
59
|
- MIT
|
60
60
|
metadata: {}
|
61
|
-
post_install_message:
|
61
|
+
post_install_message:
|
62
62
|
rdoc_options:
|
63
63
|
- "--charset=UTF-8"
|
64
64
|
require_paths:
|
@@ -74,9 +74,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
requirements: []
|
77
|
-
|
78
|
-
|
79
|
-
signing_key:
|
77
|
+
rubygems_version: 3.0.1
|
78
|
+
signing_key:
|
80
79
|
specification_version: 4
|
81
80
|
summary: Some PipeDrive API Ruby Wrapper
|
82
81
|
test_files:
|