maropost 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/maropost.rb +1 -0
- data/lib/maropost/api.rb +37 -22
- data/lib/maropost/contact.rb +7 -0
- data/lib/maropost/do_not_mail_list.rb +53 -0
- data/lib/maropost/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c8115f30902b993b7c8d6895006ec6a69cbe84a
|
4
|
+
data.tar.gz: 2fa10ba47d14f3abe08caefb7c48adb6220a0ae5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6484c0511c8216ebc583d9fa4b3baaa0c67c5cd6ddd64384f660a38fa472bd1b9559db1dcb697b3663de5f3c789cf5eeca7e71bf79377d096563c866174dd5c2
|
7
|
+
data.tar.gz: f6623d5bf9b6a974850d5ba9c2a2486c197c3504b5a4b39d9868e31d2861abbdf8f0705cdb51f02d56ac8662b19e5cacf343e069e3df2bdf5c636a578dbb909b
|
data/lib/maropost.rb
CHANGED
data/lib/maropost/api.rb
CHANGED
@@ -2,7 +2,7 @@ module Maropost
|
|
2
2
|
class Api
|
3
3
|
def self.find(email)
|
4
4
|
response = request(:get,
|
5
|
-
|
5
|
+
maropost_url('/contacts/email.json', "contact[email]=#{email}"))
|
6
6
|
Maropost::Contact.new(JSON.parse response.body)
|
7
7
|
rescue RestClient::ResourceNotFound
|
8
8
|
nil
|
@@ -15,11 +15,12 @@ module Maropost
|
|
15
15
|
else
|
16
16
|
create(contact)
|
17
17
|
end
|
18
|
+
update_do_not_mail_list(contact)
|
18
19
|
end
|
19
20
|
|
20
21
|
def self.create(contact)
|
21
22
|
response = request(:post,
|
22
|
-
|
23
|
+
maropost_url('/contacts.json'),
|
23
24
|
create_or_update_payload(contact))
|
24
25
|
Maropost::Contact.new(JSON.parse response.body)
|
25
26
|
rescue RestClient::UnprocessableEntity, RestClient::BadRequest => e
|
@@ -29,7 +30,7 @@ module Maropost
|
|
29
30
|
|
30
31
|
def self.update(contact)
|
31
32
|
response = request(:put,
|
32
|
-
"
|
33
|
+
maropost_url("/contacts/#{contact.id}.json"),
|
33
34
|
create_or_update_payload(contact))
|
34
35
|
Maropost::Contact.new(JSON.parse response.body)
|
35
36
|
rescue RestClient::UnprocessableEntity, RestClient::BadRequest => e
|
@@ -39,6 +40,10 @@ module Maropost
|
|
39
40
|
|
40
41
|
private
|
41
42
|
|
43
|
+
def self.maropost_url(path, query = nil)
|
44
|
+
URI.join(Maropost.configuration.api_url, path).tap { |u| query && u.query = query }.to_s
|
45
|
+
end
|
46
|
+
|
42
47
|
def self.request(method, url, payload = {})
|
43
48
|
RestClient::Request.logged_request(
|
44
49
|
method: method,
|
@@ -52,26 +57,36 @@ module Maropost
|
|
52
57
|
end
|
53
58
|
|
54
59
|
def self.create_or_update_payload(contact)
|
55
|
-
{
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
60
|
+
{
|
61
|
+
contact:
|
62
|
+
{ email: contact.email,
|
63
|
+
phone: contact.phone_number,
|
64
|
+
custom_field: {
|
65
|
+
ama_rewards: contact.ama_rewards,
|
66
|
+
ama_membership: contact.ama_membership,
|
67
|
+
ama_insurance: contact.ama_insurance,
|
68
|
+
ama_travel: contact.ama_travel,
|
69
|
+
ama_new_member_series: contact.ama_new_member_series,
|
70
|
+
ama_fleet_safety: contact.ama_fleet_safety,
|
71
|
+
ovrr_personal: contact.ovrr_personal,
|
72
|
+
ovrr_business: contact.ovrr_business,
|
73
|
+
ovrr_associate: contact.ovrr_associate,
|
74
|
+
ama_vr_reminder: contact.ama_vr_reminder,
|
75
|
+
ama_vr_reminder_email: contact.ama_vr_reminder_email,
|
76
|
+
ama_vr_reminder_sms: contact.ama_vr_reminder_sms,
|
77
|
+
ama_vr_reminder_autocall: contact.ama_vr_reminder_autocall,
|
78
|
+
cell_phone_number: contact.cell_phone_number
|
79
|
+
}
|
80
|
+
}
|
74
81
|
}
|
75
82
|
end
|
83
|
+
|
84
|
+
def self.update_do_not_mail_list(contact)
|
85
|
+
if contact.subscribed_to_any_lists?
|
86
|
+
DoNotMailList.delete(contact)
|
87
|
+
else
|
88
|
+
DoNotMailList.create(contact)
|
89
|
+
end
|
90
|
+
end
|
76
91
|
end
|
77
92
|
end
|
data/lib/maropost/contact.rb
CHANGED
@@ -28,5 +28,12 @@ module Maropost
|
|
28
28
|
|
29
29
|
self.errors = []
|
30
30
|
end
|
31
|
+
|
32
|
+
def subscribed_to_any_lists?
|
33
|
+
ama_rewards.eql?('1') || ama_membership.eql?('1') || ama_insurance.eql?('1') || ama_travel.eql?('1') ||
|
34
|
+
ama_new_member_series.eql?('1') || ama_fleet_safety.eql?('1') ||
|
35
|
+
ama_vr_reminder.eql?('1') || ama_vr_reminder_email.eql?('1') || ama_vr_reminder_sms.eql?('1') ||
|
36
|
+
ama_vr_reminder_autocall.eql?('1')
|
37
|
+
end
|
31
38
|
end
|
32
39
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Maropost
|
2
|
+
class DoNotMailList
|
3
|
+
def self.exists?(contact)
|
4
|
+
response = request(:get,
|
5
|
+
maropost_url('/global_unsubscribes/email.json', "contact[email]=#{contact.email}"))
|
6
|
+
JSON.parse response.body
|
7
|
+
|
8
|
+
response['id'] ? true : false
|
9
|
+
rescue RestClient::ResourceNotFound, RestClient::BadRequest => e
|
10
|
+
contact.errors << "Unexpected error occurred. Error: #{e.message}"
|
11
|
+
contact
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.create(contact)
|
15
|
+
payload = { 'global_unsubscribe': { 'email': contact.email } }
|
16
|
+
|
17
|
+
request(:post,
|
18
|
+
maropost_url('/global_unsubscribes.json'),
|
19
|
+
payload)
|
20
|
+
contact
|
21
|
+
rescue RestClient::UnprocessableEntity, RestClient::BadRequest => e
|
22
|
+
contact.errors << "Unable to subscribe contact. Error: #{e.message}"
|
23
|
+
contact
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.delete(contact)
|
27
|
+
request(:delete,
|
28
|
+
maropost_url('/global_unsubscribes/delete.json', "email=#{contact.email}"))
|
29
|
+
contact
|
30
|
+
rescue RestClient::UnprocessableEntity, RestClient::BadRequest => e
|
31
|
+
contact.errors << "Unable to unsubscribe contact. Error: #{e.message}"
|
32
|
+
contact
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def self.maropost_url(path, query = nil)
|
38
|
+
URI.join(Maropost.configuration.api_url, path).tap { |u| query && u.query = query }.to_s
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.request(method, url, payload = {})
|
42
|
+
RestClient::Request.logged_request(
|
43
|
+
method: method,
|
44
|
+
read_timeout: 10,
|
45
|
+
open_timeout: 5,
|
46
|
+
url: url,
|
47
|
+
payload: { auth_token: Maropost.configuration.auth_token }.merge(payload).to_json,
|
48
|
+
headers: { content_type: 'application/json', accept: 'application/json' },
|
49
|
+
verify_ssl: OpenSSL::SSL::VERIFY_PEER
|
50
|
+
)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/maropost/version.rb
CHANGED
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.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael van den Beuken
|
@@ -21,7 +21,7 @@ authors:
|
|
21
21
|
autorequire:
|
22
22
|
bindir: exe
|
23
23
|
cert_chain: []
|
24
|
-
date: 2017-10-
|
24
|
+
date: 2017-10-06 00:00:00.000000000 Z
|
25
25
|
dependencies:
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: rest-client
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- lib/maropost/api.rb
|
86
86
|
- lib/maropost/configuration.rb
|
87
87
|
- lib/maropost/contact.rb
|
88
|
+
- lib/maropost/do_not_mail_list.rb
|
88
89
|
- lib/maropost/version.rb
|
89
90
|
- maropost.gemspec
|
90
91
|
homepage: https://github.com/amaabca/maropost
|