mailjet 1.5.0 → 1.5.1

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
  SHA1:
3
- metadata.gz: 97d0fd939a2c9ce129ce2dc69ceacfa1e74927b0
4
- data.tar.gz: 6fe2384a9d5142a6641e6246fa4cd78456464efe
3
+ metadata.gz: 0caf5b8f84f19dcfddd140a77d3912e0e6ee1672
4
+ data.tar.gz: a5cd66471eb7a399882b33ac4fd347c2f16698a6
5
5
  SHA512:
6
- metadata.gz: 915c0bcff51e94b47fffb16699326a765fb186a850f0763a0684c35c3def3288a87df4a859d885bf2d7cd5f187285f09aa552dd1e2af87ca0e8a95d018c887d5
7
- data.tar.gz: 219fd219da5b8bdf8d3dae8931e21f3d4c600e71e2240d76e1bb02b100897646d05a8eaa85fac7e38a30923011112cf416c4028a49e7bf0419e6de5e855159af
6
+ metadata.gz: 38c9e20e47f52baf3746f61e898c579692801d05a13c1dc69c8991bae21573c6f2a4c07da87eb580bec8beab52eb044cda671e108b605fcbc7aae130f4215309
7
+ data.tar.gz: 2d96779dee5a705fd311fa3a9502f9fa1c502b67348d0fd85c45211c45553d9cb81a04d30ab8f297248cdff78a74f64ab6cf135f7d85ab119fa1ebb6f7269dde
@@ -245,22 +245,24 @@ module Mailjet
245
245
 
246
246
  def save(options)
247
247
  if persisted?
248
+ # case where the entity is updated
248
249
  response = connection(options)[attributes[:id]].put(formatted_payload, default_headers, options[:perform_api_call])
249
250
  else
251
+ # case where the entity is created
250
252
  response = connection(options).post(formatted_payload, default_headers, options[:perform_api_call])
251
253
  end
252
254
 
253
- if options[:perform_api_call]
254
- if self.resource_path == 'send/'
255
- self.attributes = ActiveSupport::JSON.decode(response)
256
- return true
255
+ if options[:perform_api_call] && !persisted?
256
+ # get attributes only for entity creation
257
+ self.attributes = if self.resource_path == 'send'
258
+ ActiveSupport::JSON.decode(response)
259
+ else
260
+ parse_api_json(response).first
257
261
  end
258
-
259
- self.attributes = parse_api_json(response).first
260
- return true
261
- else
262
- return true
263
262
  end
263
+
264
+ return true
265
+
264
266
  rescue Mailjet::ApiError => e
265
267
  if e.code.to_s == "304"
266
268
  return true # When you save a record twice it should not raise error
@@ -280,8 +282,19 @@ module Mailjet
280
282
  end
281
283
 
282
284
  def update_attributes(attribute_hash = {}, options = {})
283
- self.attributes = attribute_hash
284
- save(options)
285
+ self.attributes.deep_merge!(attribute_hash) do |key, old, new|
286
+ if old.is_a?(Array) && new.is_a?(Array)
287
+ # uniqueness of hashes based on their value of "Name"
288
+ (new + old).uniq do |data|
289
+ data["Name"]
290
+ end
291
+ else
292
+ new
293
+ end
294
+ end
295
+
296
+ opts = self.class.change_resource_path(options)
297
+ save(opts)
285
298
  end
286
299
 
287
300
  def delete(call)
@@ -1,3 +1,3 @@
1
1
  module Mailjet
2
- VERSION = "1.5.0"
2
+ VERSION = "1.5.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailjet
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Nappy
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2017-05-22 00:00:00.000000000 Z
14
+ date: 2017-05-26 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport