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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 93e0fdacc778f6cdd1a7b227d8c34187b27a29ca410f6f2abd175dff39e442c3
4
- data.tar.gz: 8ed2f42c1e757de34b76017bb98f085c7ed39ad1a8241837855d5e3a07bbf92b
3
+ metadata.gz: fcbe72e2bf68f4c523e960b23aedca76b280fe9d553d4d9391ba17d5c4d7b288
4
+ data.tar.gz: 9765928e946a864d2c2f64c716f05ac44735ea0c12c41fb0327a05374ab19370
5
5
  SHA512:
6
- metadata.gz: 6ee7df332dd515924942efe3ca8d68c2290a895968332279ace8e563576279d97f9fe3046d006afe2adaec9008908726b1697cae64a80b0fc0bcf0e05b2baea3
7
- data.tar.gz: 05a9e1339fa9c285d4833ee0dd90233f24871455caf02eab460a265b542ea68b41edaf1f01ca84542aa6c3763c0dbde9f70f88b7e7897ba6b475e125af16b971
6
+ metadata.gz: d4adceeb26ab4562d7d137a3fb677de6e1ff606ee47e9f35e69efe8acb9afdfbc492532ecd87a53bdd98f1061732b2157bbaa20612192f044a802ec215708e87
7
+ data.tar.gz: ebe709ac759da03fb30c01bed1981b5bb5863d5071dc4b6397f9412feb162dbeac2c8afececd033dfa56dd15cf83934b968bfe6d4b9e01816864b27887f454c2
@@ -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].present? ? self.class.field_keys[key][:key] : key}
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.transform_keys!{|key| field_keys[key].present? ? field_keys[key][:key] : key}
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.transform_keys!{|key| field_keys[key].present? ? field_keys[key][:key] : key}
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
@@ -33,4 +33,10 @@ module PipeDrive
33
33
  super(response.to_json)
34
34
  end
35
35
  end
36
+
37
+ class FieldNotExist < StandardError
38
+ def initialize(field_name)
39
+ super("#{field_name} not existed field name")
40
+ end
41
+ end
36
42
  end
@@ -17,6 +17,10 @@ module PipeDrive
17
17
  PipeDrive.field_keys[resource_name.to_sym]
18
18
  end
19
19
 
20
+ def field_class
21
+ Object.const_get("#{name}Field")
22
+ end
23
+
20
24
  def list(options={}, &block)
21
25
  path = "/#{resource_name}s"
22
26
  params = {start_from: 0, limit: DEFAULT_PER_PAGE}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pipe_drive_ruby_wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - JiaRou Lee