maropost 0.8.1 → 0.8.2

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: 959764ab2655a270baa41118e055d4aa0dbf3793
4
- data.tar.gz: 6ab1aa5bade2a4a01811d0a0c404f04e1734d5a3
3
+ metadata.gz: ab774a3e10205f14b11eb4d32cd6a0f6f90fd47e
4
+ data.tar.gz: b4141781b430fe4b4d2549db902c87d41de05d5c
5
5
  SHA512:
6
- metadata.gz: a7a86cd7b151395ca9a03342879058ebd048bc40377c6237c32307cf0c68420917c7a790f1da8d4c930eecf13263eaef07ad92b6943af1d2573ae12ac1e448b1
7
- data.tar.gz: 4a60abc715f41ebb41c66927e6a5a3b930c14859c37210df40eef4814fe57e7391cdf9e70e54cd23214ed11c423daf456a684fee8c43df0c618e70aa13f1b114
6
+ metadata.gz: 0364c6faffd676812f234bc804537969a9f975e8a4fbe9de74f635268f670ec93b7343f2ae149f057f8a80e2dcb5f37925193c7bc4178f9f90b43f0a6f3d192c
7
+ data.tar.gz: 0d72e7397284499d31c21c99ab640b14f70a0e83e1f079b013c50f86541788ad8db5fe0813bcf6ebe71e808e1aea066202fb9722d3824115ec21de0ee20922b8
data/lib/maropost/api.rb CHANGED
@@ -54,18 +54,35 @@ module Maropost
54
54
  end
55
55
 
56
56
  def change_email(old_email, new_email)
57
- contact = find(old_email)
57
+ old_email_contact = find(old_email)
58
+ new_email_contact = find(new_email)
58
59
 
59
- if contact.present?
60
- contact.email = new_email
61
- contact = update(contact)
62
- end
60
+ contact = update_email(old_email_contact, new_email_contact, new_email)
61
+
62
+ update_do_not_mail_list(contact) if contact
63
63
 
64
64
  contact
65
65
  end
66
66
 
67
67
  private
68
68
 
69
+ def update_email(old_contact, new_contact, new_email)
70
+ contact = nil
71
+
72
+ if old_contact.present? && new_contact.present?
73
+ new_contact = new_contact.merge_settings(old_contact)
74
+ contact = update(new_contact)
75
+ Maropost::DoNotMailList.create(old_contact)
76
+ elsif old_contact.present?
77
+ old_contact.email = new_email
78
+ contact = update(old_contact)
79
+ elsif new_contact.present?
80
+ contact = update(new_contact)
81
+ end
82
+
83
+ contact
84
+ end
85
+
69
86
  def create_or_update_payload(contact)
70
87
  {
71
88
  contact: {
@@ -53,6 +53,18 @@ module Maropost
53
53
  { cell_phone_number: cell_phone_number }.merge(lists)
54
54
  end
55
55
 
56
+ def merge_settings(old_contact)
57
+ self.phone_number = old_contact.phone_number
58
+ self.cell_phone_number = old_contact.cell_phone_number
59
+ self.allow_emails = old_contact.allow_emails
60
+
61
+ lists.each do |list|
62
+ lists[list] == '1' ? list : old_contact.lists[list]
63
+ end
64
+
65
+ self
66
+ end
67
+
56
68
  private
57
69
 
58
70
  def initialize_lists(opts = {})
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Maropost
4
- VERSION = '0.8.1'
4
+ VERSION = '0.8.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maropost
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael van den Beuken
@@ -19,7 +19,7 @@ authors:
19
19
  autorequire:
20
20
  bindir: bin
21
21
  cert_chain: []
22
- date: 2017-11-09 00:00:00.000000000 Z
22
+ date: 2017-11-15 00:00:00.000000000 Z
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency
25
25
  name: rest-client