sendgrid4r 0.3.0 → 0.4.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/.env.example +4 -1
- data/.travis.yml +1 -1
- data/lib/client.rb +0 -2
- data/lib/sendgrid4r/rest/api.rb +4 -0
- data/lib/sendgrid4r/rest/api_keys/api_keys.rb +4 -10
- data/lib/sendgrid4r/rest/asm/global_suppressions.rb +9 -16
- data/lib/sendgrid4r/rest/asm/groups.rb +3 -7
- data/lib/sendgrid4r/rest/asm/suppressions.rb +25 -18
- data/lib/sendgrid4r/rest/categories/categories.rb +1 -3
- data/lib/sendgrid4r/rest/contacts/custom_fields.rb +1 -1
- data/lib/sendgrid4r/rest/contacts/lists.rb +15 -37
- data/lib/sendgrid4r/rest/contacts/recipients.rb +19 -44
- data/lib/sendgrid4r/rest/contacts/reserved_fields.rb +1 -5
- data/lib/sendgrid4r/rest/contacts/segments.rb +9 -16
- data/lib/sendgrid4r/rest/email_activity/email_activity.rb +84 -0
- data/lib/sendgrid4r/rest/ips/addresses.rb +9 -18
- data/lib/sendgrid4r/rest/ips/pools.rb +7 -12
- data/lib/sendgrid4r/rest/ips/warmup.rb +7 -17
- data/lib/sendgrid4r/rest/request.rb +7 -1
- data/lib/sendgrid4r/rest/settings/enforced_tls.rb +5 -12
- data/lib/sendgrid4r/rest/stats/advanced.rb +10 -32
- data/lib/sendgrid4r/rest/stats/category.rb +4 -11
- data/lib/sendgrid4r/rest/stats/global.rb +3 -2
- data/lib/sendgrid4r/rest/stats/parse.rb +4 -6
- data/lib/sendgrid4r/rest/stats/subuser.rb +4 -11
- data/lib/sendgrid4r/rest/subusers/subusers.rb +83 -0
- data/lib/sendgrid4r/rest/templates/templates.rb +1 -1
- data/lib/sendgrid4r/rest/templates/versions.rb +3 -2
- data/lib/sendgrid4r/version.rb +1 -1
- data/spec/client_spec.rb +17 -4
- data/spec/factory/condition_factory_spec.rb +1 -1
- data/spec/factory/segment_factory_spec.rb +1 -1
- data/spec/factory/version_factory_spec.rb +1 -1
- data/spec/{api_keys → rest/api_keys}/api_keys_spec.rb +52 -18
- data/spec/{asm → rest/asm}/asm_spec.rb +23 -17
- data/spec/{asm → rest/asm}/global_suppressions_spec.rb +45 -2
- data/spec/{asm → rest/asm}/groups_spec.rb +76 -7
- data/spec/{asm → rest/asm}/suppressions_spec.rb +95 -20
- data/spec/{categories → rest/categories}/categories_spec.rb +27 -7
- data/spec/{contacts → rest/contacts}/custom_fields_spec.rb +49 -15
- data/spec/{contacts → rest/contacts}/lists_spec.rb +138 -15
- data/spec/{contacts → rest/contacts}/recipients_spec.rb +141 -26
- data/spec/{contacts → rest/contacts}/reserved_fields_spec.rb +29 -13
- data/spec/{contacts → rest/contacts}/segments_spec.rb +108 -31
- data/spec/rest/email_activity/email_activity_spec.rb +192 -0
- data/spec/{ips → rest/ips}/addresses_spec.rb +58 -18
- data/spec/{ips → rest/ips}/pools_spec.rb +80 -45
- data/spec/{ips → rest/ips}/warmup_spec.rb +50 -7
- data/spec/{settings → rest/settings}/enforced_tls_spec.rb +32 -7
- data/spec/{stats → rest/stats}/advanced_spec.rb +2 -2
- data/spec/{stats → rest/stats}/category_spec.rb +2 -2
- data/spec/{stats → rest/stats}/global_spec.rb +2 -2
- data/spec/{stats → rest/stats}/parse_spec.rb +2 -2
- data/spec/{stats → rest/stats}/stats_spec.rb +2 -2
- data/spec/{stats → rest/stats}/subuser_spec.rb +2 -2
- data/spec/rest/subusers/subusers_spec.rb +246 -0
- data/spec/{templates → rest/templates}/templates_spec.rb +55 -15
- data/spec/{templates → rest/templates}/versions_spec.rb +44 -7
- metadata +54 -48
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7417acd0a5a7f7568d4b05a42983b09da86d716
|
4
|
+
data.tar.gz: eba6a546a827b39af30df5128b267d5432820c80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8bf55ba5f91ea40f8e9062208b87597a0242526a3101bddd52f6da55c537a99478bccb357676eb99b67bdac5aff8d9b69f17fb9fe4f42e2bad74c6170db39f4d
|
7
|
+
data.tar.gz: 8573913c991b79f02d8c39168e41f574b63ceba5abc4151b1e89d2a0083a8c442c488b5e4b9dbfbaa2958622f6000e6144730f2809e2c5d21fc9c633651b309e
|
data/.env.example
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
SENDGRID_USERNAME=sendgrid username
|
2
2
|
SENDGRID_PASSWORD=sendgrid_password
|
3
3
|
API_KEY=apikey
|
4
|
-
USE_SILVER=true
|
5
4
|
SILVER_SENDGRID_USERNAME=silver_sendgrid_username
|
6
5
|
SILVER_SENDGRID_PASSWORD=silver_sendgird_password
|
7
6
|
SILVER_SUBUSER=subusername
|
7
|
+
SILVER_SUBUSER2=subusername
|
8
|
+
SUBUSER1=subusername
|
9
|
+
SUBPASS1=password
|
10
|
+
SUBMAIL1=email@email.com
|
data/.travis.yml
CHANGED
data/lib/client.rb
CHANGED
data/lib/sendgrid4r/rest/api.rb
CHANGED
@@ -24,6 +24,8 @@ require 'sendgrid4r/rest/contacts/recipients'
|
|
24
24
|
require 'sendgrid4r/rest/contacts/reserved_fields'
|
25
25
|
require 'sendgrid4r/rest/contacts/segments'
|
26
26
|
require 'sendgrid4r/rest/api_keys/api_keys'
|
27
|
+
require 'sendgrid4r/rest/subusers/subusers'
|
28
|
+
require 'sendgrid4r/rest/email_activity/email_activity'
|
27
29
|
|
28
30
|
module SendGrid4r
|
29
31
|
module REST
|
@@ -53,6 +55,8 @@ module SendGrid4r
|
|
53
55
|
include SendGrid4r::REST::Contacts::ReservedFields
|
54
56
|
include SendGrid4r::REST::Contacts::Segments
|
55
57
|
include SendGrid4r::REST::ApiKeys
|
58
|
+
include SendGrid4r::REST::Subusers
|
59
|
+
include SendGrid4r::REST::EmailActivity
|
56
60
|
end
|
57
61
|
end
|
58
62
|
end
|
@@ -15,7 +15,7 @@ module SendGrid4r
|
|
15
15
|
ApiKey = Struct.new(:name, :api_key_id, :api_key, :scope_set_id)
|
16
16
|
|
17
17
|
def self.url(api_key = nil)
|
18
|
-
url = "#{
|
18
|
+
url = "#{BASE_URL}/api_keys"
|
19
19
|
url = "#{url}/#{api_key}" unless api_key.nil?
|
20
20
|
url
|
21
21
|
end
|
@@ -47,9 +47,7 @@ module SendGrid4r
|
|
47
47
|
def post_api_key(name, &block)
|
48
48
|
params = {}
|
49
49
|
params['name'] = name
|
50
|
-
resp = post(
|
51
|
-
@auth, SendGrid4r::REST::ApiKeys.url, params, &block
|
52
|
-
)
|
50
|
+
resp = post(@auth, SendGrid4r::REST::ApiKeys.url, params, &block)
|
53
51
|
SendGrid4r::REST::ApiKeys.create_api_key(resp)
|
54
52
|
end
|
55
53
|
|
@@ -60,12 +58,8 @@ module SendGrid4r
|
|
60
58
|
def patch_api_key(api_key, name, &block)
|
61
59
|
params = {}
|
62
60
|
params['name'] = name
|
63
|
-
|
64
|
-
|
65
|
-
SendGrid4r::REST::ApiKeys.url(api_key),
|
66
|
-
params,
|
67
|
-
&block
|
68
|
-
)
|
61
|
+
endpoint = SendGrid4r::REST::ApiKeys.url(api_key)
|
62
|
+
resp = patch(@auth, endpoint, params, &block)
|
69
63
|
SendGrid4r::REST::ApiKeys.create_api_key(resp)
|
70
64
|
end
|
71
65
|
end
|
@@ -13,36 +13,29 @@ module SendGrid4r
|
|
13
13
|
include SendGrid4r::REST::Request
|
14
14
|
|
15
15
|
def self.url(email_address = nil)
|
16
|
-
url = "#{
|
16
|
+
url = "#{BASE_URL}/asm/suppressions/global"
|
17
17
|
url = "#{url}/#{email_address}" unless email_address.nil?
|
18
18
|
url
|
19
19
|
end
|
20
20
|
|
21
21
|
def post_global_suppressed_emails(recipient_emails, &block)
|
22
22
|
params = { recipient_emails: recipient_emails }
|
23
|
-
|
24
|
-
|
25
|
-
SendGrid4r::REST::Asm::GlobalSuppressions.url,
|
26
|
-
params,
|
27
|
-
&block
|
28
|
-
)
|
23
|
+
endpoint = SendGrid4r::REST::Asm::GlobalSuppressions.url
|
24
|
+
resp = post(@auth, endpoint, params, &block)
|
29
25
|
SendGrid4r::REST::Asm.create_recipient_emails(resp)
|
30
26
|
end
|
31
27
|
|
32
28
|
def get_global_suppressed_email(email_address, &block)
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
&block
|
37
|
-
)
|
29
|
+
endpoint =
|
30
|
+
SendGrid4r::REST::Asm::GlobalSuppressions.url(email_address)
|
31
|
+
resp = get(@auth, endpoint, &block)
|
38
32
|
SendGrid4r::REST::Asm.create_recipient_email(resp)
|
39
33
|
end
|
40
34
|
|
41
35
|
def delete_global_suppressed_email(email_address, &block)
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
&block)
|
36
|
+
endpoint =
|
37
|
+
SendGrid4r::REST::Asm::GlobalSuppressions.url(email_address)
|
38
|
+
delete(@auth, endpoint, &block)
|
46
39
|
end
|
47
40
|
end
|
48
41
|
end
|
@@ -16,7 +16,7 @@ module SendGrid4r
|
|
16
16
|
:id, :name, :description, :last_email_sent_at, :unsubscribes)
|
17
17
|
|
18
18
|
def self.url(group_id = nil)
|
19
|
-
url = "#{
|
19
|
+
url = "#{BASE_URL}/asm/groups"
|
20
20
|
url = "#{url}/#{group_id}" unless group_id.nil?
|
21
21
|
url
|
22
22
|
end
|
@@ -58,12 +58,8 @@ module SendGrid4r
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def patch_group(group_id, group, &block)
|
61
|
-
|
62
|
-
|
63
|
-
SendGrid4r::REST::Asm::Groups.url(group_id),
|
64
|
-
group.to_h,
|
65
|
-
&block
|
66
|
-
)
|
61
|
+
endpoint = SendGrid4r::REST::Asm::Groups.url(group_id)
|
62
|
+
resp = patch(@auth, endpoint, group.to_h, &block)
|
67
63
|
SendGrid4r::REST::Asm::Groups.create_group(resp)
|
68
64
|
end
|
69
65
|
|
@@ -16,15 +16,13 @@ module SendGrid4r
|
|
16
16
|
Suppressions = Struct.new(:suppressions)
|
17
17
|
|
18
18
|
def self.url(group_id, email_address = nil)
|
19
|
-
url =
|
20
|
-
"#{SendGrid4r::Client::BASE_URL}"\
|
21
|
-
"/asm/groups/#{group_id}/suppressions"
|
19
|
+
url = "#{BASE_URL}/asm/groups/#{group_id}/suppressions"
|
22
20
|
url = "#{url}/#{email_address}" unless email_address.nil?
|
23
21
|
url
|
24
22
|
end
|
25
23
|
|
26
24
|
def self.create_suppressions(resp)
|
27
|
-
resp if resp.nil?
|
25
|
+
return resp if resp.nil?
|
28
26
|
suppressions = []
|
29
27
|
resp['suppressions'].each do |suppression|
|
30
28
|
suppressions.push(
|
@@ -37,39 +35,48 @@ module SendGrid4r
|
|
37
35
|
end
|
38
36
|
|
39
37
|
def self.create_suppression(resp)
|
40
|
-
resp if resp.nil?
|
38
|
+
return resp if resp.nil?
|
41
39
|
Suppression.new(
|
42
40
|
resp['id'], resp['name'], resp['description'], resp['suppressed']
|
43
41
|
)
|
44
42
|
end
|
45
43
|
|
46
|
-
def
|
44
|
+
def self.create_emails(resp)
|
45
|
+
return resp if resp.nil?
|
46
|
+
emails = []
|
47
|
+
resp.each do |email|
|
48
|
+
emails.push(email)
|
49
|
+
end
|
50
|
+
emails
|
51
|
+
end
|
52
|
+
|
53
|
+
def post_suppressed_emails(group_id, recipient_emails, &block)
|
47
54
|
resp = post(
|
48
55
|
@auth,
|
49
56
|
SendGrid4r::REST::Asm::Suppressions.url(group_id),
|
50
|
-
recipient_emails: recipient_emails
|
57
|
+
recipient_emails: recipient_emails,
|
58
|
+
&block
|
51
59
|
)
|
52
60
|
SendGrid4r::REST::Asm.create_recipient_emails(resp)
|
53
61
|
end
|
54
62
|
|
55
|
-
def get_suppressed_emails(group_id)
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
)
|
63
|
+
def get_suppressed_emails(group_id, &block)
|
64
|
+
endpoint = SendGrid4r::REST::Asm::Suppressions.url(group_id)
|
65
|
+
resp = get(@auth, endpoint, &block)
|
66
|
+
SendGrid4r::REST::Asm::Suppressions.create_emails(resp)
|
60
67
|
end
|
61
68
|
|
62
|
-
def get_suppressions(email_address)
|
63
|
-
|
64
|
-
|
65
|
-
"#{SendGrid4r::Client::BASE_URL}/asm/suppressions/#{email_address}")
|
69
|
+
def get_suppressions(email_address, &block)
|
70
|
+
endpoint = "#{BASE_URL}/asm/suppressions/#{email_address}"
|
71
|
+
resp = get(@auth, endpoint, &block)
|
66
72
|
SendGrid4r::REST::Asm::Suppressions.create_suppressions(resp)
|
67
73
|
end
|
68
74
|
|
69
|
-
def delete_suppressed_email(group_id, email_address)
|
75
|
+
def delete_suppressed_email(group_id, email_address, &block)
|
70
76
|
delete(
|
71
77
|
@auth,
|
72
|
-
SendGrid4r::REST::Asm::Suppressions.url(group_id, email_address)
|
78
|
+
SendGrid4r::REST::Asm::Suppressions.url(group_id, email_address),
|
79
|
+
&block
|
73
80
|
)
|
74
81
|
end
|
75
82
|
end
|
@@ -37,9 +37,7 @@ module SendGrid4r
|
|
37
37
|
params['category'] = category unless category.nil?
|
38
38
|
params['limit'] = limit unless limit.nil?
|
39
39
|
params['offset'] = offset unless limit.nil?
|
40
|
-
resp = get(
|
41
|
-
@auth, "#{SendGrid4r::Client::BASE_URL}/categories", params, &block
|
42
|
-
)
|
40
|
+
resp = get(@auth, "#{BASE_URL}/categories", params, &block)
|
43
41
|
SendGrid4r::REST::Categories::Categories.create_categories(resp)
|
44
42
|
end
|
45
43
|
end
|
@@ -25,7 +25,7 @@ module SendGrid4r
|
|
25
25
|
Fields = Struct.new(:custom_fields)
|
26
26
|
|
27
27
|
def self.url(custom_field_id = nil)
|
28
|
-
url = "#{
|
28
|
+
url = "#{BASE_URL}/contactdb/custom_fields"
|
29
29
|
url = "#{url}/#{custom_field_id}" unless custom_field_id.nil?
|
30
30
|
url
|
31
31
|
end
|
@@ -16,7 +16,7 @@ module SendGrid4r
|
|
16
16
|
Lists = Struct.new(:lists)
|
17
17
|
|
18
18
|
def self.url(list_id = nil)
|
19
|
-
url = "#{
|
19
|
+
url = "#{BASE_URL}/contactdb/lists"
|
20
20
|
url = "#{url}/#{list_id}" unless list_id.nil?
|
21
21
|
url
|
22
22
|
end
|
@@ -65,12 +65,8 @@ module SendGrid4r
|
|
65
65
|
def patch_list(list_id, name, &block)
|
66
66
|
params = {}
|
67
67
|
params['name'] = name
|
68
|
-
|
69
|
-
|
70
|
-
SendGrid4r::REST::Contacts::Lists.url(list_id),
|
71
|
-
params,
|
72
|
-
&block
|
73
|
-
)
|
68
|
+
endpoint = SendGrid4r::REST::Contacts::Lists.url(list_id)
|
69
|
+
resp = patch(@auth, endpoint, params, &block)
|
74
70
|
SendGrid4r::REST::Contacts::Lists.create_list(resp)
|
75
71
|
end
|
76
72
|
|
@@ -81,54 +77,36 @@ module SendGrid4r
|
|
81
77
|
# no bodies returned
|
82
78
|
def post_recipients_to_list(list_id, recipients, &block)
|
83
79
|
url = SendGrid4r::REST::Contacts::Lists.url(list_id)
|
84
|
-
|
85
|
-
|
86
|
-
"#{url}/recipients_batch",
|
87
|
-
recipients,
|
88
|
-
&block
|
89
|
-
)
|
80
|
+
endpoint = "#{url}/recipients_batch"
|
81
|
+
post(@auth, endpoint, recipients, &block)
|
90
82
|
end
|
91
83
|
|
92
84
|
def get_recipients_from_list(list_id, limit = nil, offset = nil, &block)
|
93
85
|
params = {}
|
94
86
|
params['limit'] = limit unless limit.nil?
|
95
87
|
params['offset'] = offset unless offset.nil?
|
96
|
-
|
97
|
-
|
98
|
-
SendGrid4r::REST::Contacts::Lists.recipients_url(list_id),
|
99
|
-
params,
|
100
|
-
&block
|
101
|
-
)
|
88
|
+
endpoint = SendGrid4r::REST::Contacts::Lists.recipients_url(list_id)
|
89
|
+
resp = get(@auth, endpoint, params, &block)
|
102
90
|
SendGrid4r::REST::Contacts::Recipients.create_recipients(resp)
|
103
91
|
end
|
104
92
|
|
105
93
|
def post_recipient_to_list(list_id, recipient_id, &block)
|
106
|
-
|
107
|
-
|
108
|
-
SendGrid4r::REST::Contacts::Lists.recipients_url(
|
109
|
-
list_id, recipient_id
|
110
|
-
),
|
111
|
-
&block
|
94
|
+
endpoint = SendGrid4r::REST::Contacts::Lists.recipients_url(
|
95
|
+
list_id, recipient_id
|
112
96
|
)
|
97
|
+
post(@auth, endpoint, &block)
|
113
98
|
end
|
114
99
|
|
115
100
|
def delete_recipient_from_list(list_id, recipient_id, &block)
|
116
|
-
|
117
|
-
|
118
|
-
SendGrid4r::REST::Contacts::Lists.recipients_url(
|
119
|
-
list_id, recipient_id
|
120
|
-
),
|
121
|
-
&block
|
101
|
+
endpoint = SendGrid4r::REST::Contacts::Lists.recipients_url(
|
102
|
+
list_id, recipient_id
|
122
103
|
)
|
104
|
+
delete(@auth, endpoint, &block)
|
123
105
|
end
|
124
106
|
|
125
107
|
def delete_lists(list_ids, &block)
|
126
|
-
|
127
|
-
|
128
|
-
"#{SendGrid4r::Client::BASE_URL}/contactdb/lists_batch",
|
129
|
-
list_ids,
|
130
|
-
&block
|
131
|
-
)
|
108
|
+
endpoint = "#{BASE_URL}/contactdb/lists_batch"
|
109
|
+
delete(@auth, endpoint, list_ids, &block)
|
132
110
|
end
|
133
111
|
end
|
134
112
|
end
|
@@ -61,79 +61,58 @@ module SendGrid4r
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def self.url(recipient_id = nil)
|
64
|
-
url = "#{
|
64
|
+
url = "#{BASE_URL}/contactdb/recipients"
|
65
65
|
url = "#{url}/#{recipient_id}" unless recipient_id.nil?
|
66
66
|
url
|
67
67
|
end
|
68
68
|
|
69
69
|
def post_recipient(params, &block)
|
70
|
-
|
71
|
-
|
72
|
-
)
|
70
|
+
endpoint = SendGrid4r::REST::Contacts::Recipients.url
|
71
|
+
resp = post(@auth, endpoint, params, &block)
|
73
72
|
SendGrid4r::REST::Contacts::Recipients.create_recipient(resp)
|
74
73
|
end
|
75
74
|
|
76
75
|
def delete_recipients(emails, &block)
|
77
|
-
|
78
|
-
|
79
|
-
)
|
76
|
+
endpoint = SendGrid4r::REST::Contacts::Recipients.url
|
77
|
+
delete(@auth, endpoint, emails, &block)
|
80
78
|
end
|
81
79
|
|
82
80
|
def get_recipients(limit = nil, offset = nil, &block)
|
83
81
|
params = {}
|
84
82
|
params['limit'] = limit unless limit.nil?
|
85
83
|
params['offset'] = offset unless offset.nil?
|
86
|
-
|
87
|
-
|
88
|
-
)
|
84
|
+
endpoint = SendGrid4r::REST::Contacts::Recipients.url
|
85
|
+
resp = get(@auth, endpoint, params, &block)
|
89
86
|
SendGrid4r::REST::Contacts::Recipients.create_recipients(resp)
|
90
87
|
end
|
91
88
|
|
92
89
|
def get_recipients_by_id(recipient_ids, &block)
|
93
|
-
|
94
|
-
|
95
|
-
"#{SendGrid4r::REST::Contacts::Recipients.url}/batch",
|
96
|
-
nil,
|
97
|
-
recipient_ids,
|
98
|
-
&block
|
99
|
-
)
|
90
|
+
endpoint = "#{SendGrid4r::REST::Contacts::Recipients.url}/batch"
|
91
|
+
resp = get(@auth, endpoint, nil, recipient_ids, &block)
|
100
92
|
SendGrid4r::REST::Contacts::Recipients.create_recipients(resp)
|
101
93
|
end
|
102
94
|
|
103
95
|
def get_recipients_count(&block)
|
104
|
-
|
105
|
-
|
106
|
-
"#{SendGrid4r::REST::Contacts::Recipients.url}/count",
|
107
|
-
&block
|
108
|
-
)
|
96
|
+
endpoint = "#{SendGrid4r::REST::Contacts::Recipients.url}/count"
|
97
|
+
resp = get(@auth, endpoint, &block)
|
109
98
|
resp['recipient_count'] unless resp.nil?
|
110
99
|
end
|
111
100
|
|
112
101
|
def search_recipients(params, &block)
|
113
|
-
|
114
|
-
|
115
|
-
"#{SendGrid4r::REST::Contacts::Recipients.url}/search",
|
116
|
-
params,
|
117
|
-
&block
|
118
|
-
)
|
102
|
+
endpoint = "#{SendGrid4r::REST::Contacts::Recipients.url}/search"
|
103
|
+
resp = get(@auth, endpoint, params, &block)
|
119
104
|
SendGrid4r::REST::Contacts::Recipients.create_recipients(resp)
|
120
105
|
end
|
121
106
|
|
122
107
|
def get_recipient(recipient_id, &block)
|
123
|
-
|
124
|
-
|
125
|
-
SendGrid4r::REST::Contacts::Recipients.url(recipient_id),
|
126
|
-
&block
|
127
|
-
)
|
108
|
+
endpoint = SendGrid4r::REST::Contacts::Recipients.url(recipient_id)
|
109
|
+
resp = get(@auth, endpoint, &block)
|
128
110
|
SendGrid4r::REST::Contacts::Recipients.create_recipient(resp)
|
129
111
|
end
|
130
112
|
|
131
113
|
def delete_recipient(recipient_id, &block)
|
132
|
-
|
133
|
-
|
134
|
-
SendGrid4r::REST::Contacts::Recipients.url(recipient_id),
|
135
|
-
&block
|
136
|
-
)
|
114
|
+
endpoint = SendGrid4r::REST::Contacts::Recipients.url(recipient_id)
|
115
|
+
delete(@auth, endpoint, &block)
|
137
116
|
end
|
138
117
|
|
139
118
|
def get_lists_recipient_belong(recipient_id, &block)
|
@@ -146,12 +125,8 @@ module SendGrid4r
|
|
146
125
|
end
|
147
126
|
|
148
127
|
def post_recipients(recipients, &block)
|
149
|
-
|
150
|
-
|
151
|
-
"#{SendGrid4r::Client::BASE_URL}/contactdb/recipients_batch",
|
152
|
-
recipients,
|
153
|
-
&block
|
154
|
-
)
|
128
|
+
endpoint = "#{BASE_URL}/contactdb/recipients_batch"
|
129
|
+
resp = post(@auth, endpoint, recipients, &block)
|
155
130
|
SendGrid4r::REST::Contacts::Recipients.create_result(resp)
|
156
131
|
end
|
157
132
|
|
@@ -41,11 +41,7 @@ module SendGrid4r
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def get_reserved_fields(&block)
|
44
|
-
resp = get(
|
45
|
-
@auth,
|
46
|
-
"#{SendGrid4r::Client::BASE_URL}/contactdb/reserved_fields",
|
47
|
-
&block
|
48
|
-
)
|
44
|
+
resp = get(@auth, "#{BASE_URL}/contactdb/reserved_fields", &block)
|
49
45
|
SendGrid4r::REST::Contacts::ReservedFields.create_fields(resp)
|
50
46
|
end
|
51
47
|
end
|
@@ -21,7 +21,7 @@ module SendGrid4r
|
|
21
21
|
Segments = Struct.new(:segments)
|
22
22
|
|
23
23
|
def self.url(segment_id = nil)
|
24
|
-
url = "#{
|
24
|
+
url = "#{BASE_URL}/contactdb/segments"
|
25
25
|
url = "#{url}/#{segment_id}" unless segment_id.nil?
|
26
26
|
url
|
27
27
|
end
|
@@ -62,9 +62,8 @@ module SendGrid4r
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def post_segment(params, &block)
|
65
|
-
|
66
|
-
|
67
|
-
)
|
65
|
+
endpoint = SendGrid4r::REST::Contacts::Segments.url
|
66
|
+
resp = post(@auth, endpoint, params.to_h, &block)
|
68
67
|
SendGrid4r::REST::Contacts::Segments.create_segment(resp)
|
69
68
|
end
|
70
69
|
|
@@ -74,26 +73,20 @@ module SendGrid4r
|
|
74
73
|
end
|
75
74
|
|
76
75
|
def get_segment(segment_id, &block)
|
77
|
-
|
78
|
-
|
79
|
-
)
|
76
|
+
endpoint = SendGrid4r::REST::Contacts::Segments.url(segment_id)
|
77
|
+
resp = get(@auth, endpoint, &block)
|
80
78
|
SendGrid4r::REST::Contacts::Segments.create_segment(resp)
|
81
79
|
end
|
82
80
|
|
83
81
|
def put_segment(segment_id, params, &block)
|
84
|
-
|
85
|
-
|
86
|
-
SendGrid4r::REST::Contacts::Segments.url(segment_id),
|
87
|
-
params,
|
88
|
-
&block
|
89
|
-
)
|
82
|
+
endpoint = SendGrid4r::REST::Contacts::Segments.url(segment_id)
|
83
|
+
resp = put(@auth, endpoint, params, &block)
|
90
84
|
SendGrid4r::REST::Contacts::Segments.create_segment(resp)
|
91
85
|
end
|
92
86
|
|
93
87
|
def delete_segment(segment_id, &block)
|
94
|
-
|
95
|
-
|
96
|
-
)
|
88
|
+
endpoint = SendGrid4r::REST::Contacts::Segments.url(segment_id)
|
89
|
+
delete(@auth, endpoint, &block)
|
97
90
|
end
|
98
91
|
|
99
92
|
def get_recipients_from_segment(
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$LOAD_PATH.unshift File.dirname(__FILE__)
|
3
|
+
|
4
|
+
require 'sendgrid4r/rest/request'
|
5
|
+
|
6
|
+
module SendGrid4r
|
7
|
+
module REST
|
8
|
+
#
|
9
|
+
# SendGrid Web API v3 EmailActivity
|
10
|
+
#
|
11
|
+
module EmailActivity
|
12
|
+
include SendGrid4r::REST::Request
|
13
|
+
|
14
|
+
#
|
15
|
+
# SendGrid Web API v3 Stats - AggregatedBy
|
16
|
+
#
|
17
|
+
module Event
|
18
|
+
BOUNCES = 'bounces'
|
19
|
+
CLICKS = 'clicks'
|
20
|
+
DEFERRED = 'deferred'
|
21
|
+
DELIVERED = 'delivered'
|
22
|
+
DROPS = 'drops'
|
23
|
+
GROUP_UNSUBSCRIBE = 'group_unsubscribe'
|
24
|
+
GROUP_RESUBSCRIBE = 'group_resubscribe'
|
25
|
+
OPENS = 'opens'
|
26
|
+
PROCESSED = 'processed'
|
27
|
+
PARSEAPI = 'parseapi'
|
28
|
+
SPAM_REPORTS = 'spam_reports'
|
29
|
+
UNSUBSCRIBE = 'unsubscribes'
|
30
|
+
end
|
31
|
+
|
32
|
+
Activity = Struct.new(
|
33
|
+
:email, :event, :created, :category, :smtp_id, :asm_group_id,
|
34
|
+
:msg_id, :ip, :url, :reason
|
35
|
+
)
|
36
|
+
|
37
|
+
def self.url
|
38
|
+
url = "#{BASE_URL}/email_activity"
|
39
|
+
url
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.create_activities(resp)
|
43
|
+
return resp if resp.nil?
|
44
|
+
activities = []
|
45
|
+
resp.each do |activity|
|
46
|
+
activities.push(
|
47
|
+
SendGrid4r::REST::EmailActivity.create_activity(activity)
|
48
|
+
)
|
49
|
+
end
|
50
|
+
activities
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.create_activity(resp)
|
54
|
+
return resp if resp.nil?
|
55
|
+
Activity.new(
|
56
|
+
resp['email'],
|
57
|
+
resp['event'],
|
58
|
+
resp['created'].nil? ? nil : Time.at(resp['created']),
|
59
|
+
resp['category'],
|
60
|
+
resp['smtp_id'],
|
61
|
+
resp['asm_group_id'],
|
62
|
+
resp['msg_id'],
|
63
|
+
resp['ip'],
|
64
|
+
resp['url'],
|
65
|
+
resp['reason']
|
66
|
+
)
|
67
|
+
end
|
68
|
+
|
69
|
+
def get_email_activities(
|
70
|
+
email: nil, events: nil, exclude_events: nil, start_time: nil,
|
71
|
+
end_time: nil, &block
|
72
|
+
)
|
73
|
+
params = {}
|
74
|
+
params['email'] = email unless email.nil?
|
75
|
+
params['events'] = events unless events.nil?
|
76
|
+
params['exclude_events'] = exclude_events unless exclude_events.nil?
|
77
|
+
params['start_time'] = start_time.to_i unless start_time.nil?
|
78
|
+
params['end_time'] = end_time.to_i unless end_time.nil?
|
79
|
+
resp = get(@auth, SendGrid4r::REST::EmailActivity.url, params, &block)
|
80
|
+
SendGrid4r::REST::EmailActivity.create_activities(resp)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|