pipe_drive_ruby_wrapper 0.1.8 → 0.1.9
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 +23 -3
- data/lib/pipe_drive/exception.rb +6 -0
- data/lib/pipe_drive/resource_base.rb +4 -0
- 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: fcbe72e2bf68f4c523e960b23aedca76b280fe9d553d4d9391ba17d5c4d7b288
|
4
|
+
data.tar.gz: 9765928e946a864d2c2f64c716f05ac44735ea0c12c41fb0327a05374ab19370
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4adceeb26ab4562d7d137a3fb677de6e1ff606ee47e9f35e69efe8acb9afdfbc492532ecd87a53bdd98f1061732b2157bbaa20612192f044a802ec215708e87
|
7
|
+
data.tar.gz: ebe709ac759da03fb30c01bed1981b5bb5863d5071dc4b6397f9412feb162dbeac2c8afececd033dfa56dd15cf83934b968bfe6d4b9e01816864b27887f454c2
|
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
|
17
|
+
opts = self.class.send(:transform_opts, opts)
|
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
|
45
|
+
opts = transform_opts(opts)
|
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
|
53
|
+
opts = transform_opts(opts)
|
54
54
|
requester.http_put(path, opts) do |result|
|
55
55
|
new(result)
|
56
56
|
end
|
@@ -101,6 +101,26 @@ module PipeDrive
|
|
101
101
|
new(struct_attr)
|
102
102
|
end
|
103
103
|
end
|
104
|
+
|
105
|
+
def transform_opts(opts)
|
106
|
+
new_opts = {}
|
107
|
+
opts.each_pair do |key, value|
|
108
|
+
raise FieldNotExist.new(key) if field_keys[key].nil?
|
109
|
+
new_key = field_keys[key][:key]
|
110
|
+
if value.is_a?(Array)
|
111
|
+
field_info = field_class.find_by_id(field_keys[key][:id])
|
112
|
+
new_value = value.map do |val|
|
113
|
+
target = field_info.options.find{|f| f[:label] == val}
|
114
|
+
target[:id] unless target.nil?
|
115
|
+
end
|
116
|
+
new_value.compact!
|
117
|
+
else
|
118
|
+
new_value = value
|
119
|
+
end
|
120
|
+
new_opts[new_key] = new_value
|
121
|
+
end
|
122
|
+
new_opts
|
123
|
+
end
|
104
124
|
|
105
125
|
end
|
106
126
|
end
|
data/lib/pipe_drive/exception.rb
CHANGED