sendgrid4r 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.env.example +5 -0
- data/.rubocop.yml +8 -8
- data/README.md +2 -0
- data/lib/auth.rb +5 -2
- data/lib/client.rb +4 -2
- data/lib/sendgrid4r/factory/version_factory.rb +1 -1
- data/lib/sendgrid4r/rest/api.rb +4 -0
- data/lib/sendgrid4r/rest/api_keys/api_keys.rb +73 -0
- data/lib/sendgrid4r/rest/asm/asm.rb +28 -0
- data/lib/sendgrid4r/rest/asm/global_suppressions.rb +12 -8
- data/lib/sendgrid4r/rest/asm/groups.rb +29 -22
- data/lib/sendgrid4r/rest/asm/suppressions.rb +25 -15
- data/lib/sendgrid4r/rest/categories/categories.rb +19 -9
- data/lib/sendgrid4r/rest/contacts/custom_fields.rb +14 -8
- data/lib/sendgrid4r/rest/contacts/lists.rb +32 -20
- data/lib/sendgrid4r/rest/contacts/recipients.rb +42 -31
- data/lib/sendgrid4r/rest/contacts/reserved_fields.rb +6 -2
- data/lib/sendgrid4r/rest/contacts/segments.rb +22 -12
- data/lib/sendgrid4r/rest/ips/addresses.rb +36 -22
- data/lib/sendgrid4r/rest/ips/pools.rb +31 -16
- data/lib/sendgrid4r/rest/ips/warmup.rb +34 -15
- data/lib/sendgrid4r/rest/request.rb +33 -19
- data/lib/sendgrid4r/rest/settings/enforced_tls.rb +12 -5
- data/lib/sendgrid4r/rest/stats/advanced.rb +73 -25
- data/lib/sendgrid4r/rest/stats/category.rb +11 -6
- data/lib/sendgrid4r/rest/stats/global.rb +6 -4
- data/lib/sendgrid4r/rest/stats/parse.rb +10 -4
- data/lib/sendgrid4r/rest/stats/stats.rb +13 -18
- data/lib/sendgrid4r/rest/stats/subuser.rb +10 -6
- data/lib/sendgrid4r/rest/templates/templates.rb +23 -16
- data/lib/sendgrid4r/rest/templates/versions.rb +39 -36
- data/lib/sendgrid4r/version.rb +1 -1
- data/spec/api_keys/api_keys_spec.rb +152 -0
- data/spec/asm/asm_spec.rb +33 -0
- data/spec/asm/global_suppressions_spec.rb +111 -45
- data/spec/asm/groups_spec.rb +172 -48
- data/spec/asm/suppressions_spec.rb +180 -54
- data/spec/categories/categories_spec.rb +81 -25
- data/spec/client_spec.rb +11 -4
- data/spec/contacts/custom_fields_spec.rb +135 -44
- data/spec/contacts/lists_spec.rb +314 -84
- data/spec/contacts/recipients_spec.rb +337 -92
- data/spec/contacts/reserved_fields_spec.rb +80 -60
- data/spec/contacts/segments_spec.rb +219 -88
- data/spec/factory/condition_factory_spec.rb +12 -12
- data/spec/factory/segment_factory_spec.rb +19 -19
- data/spec/factory/version_factory_spec.rb +6 -6
- data/spec/ips/addresses_spec.rb +177 -84
- data/spec/ips/pools_spec.rb +190 -34
- data/spec/ips/warmup_spec.rb +106 -38
- data/spec/settings/enforced_tls_spec.rb +76 -18
- data/spec/stats/advanced_spec.rb +373 -196
- data/spec/stats/category_spec.rb +133 -71
- data/spec/stats/global_spec.rb +74 -47
- data/spec/stats/parse_spec.rb +46 -29
- data/spec/stats/stats_spec.rb +246 -0
- data/spec/stats/subuser_spec.rb +99 -54
- data/spec/templates/templates_spec.rb +219 -54
- data/spec/templates/versions_spec.rb +171 -67
- metadata +10 -2
@@ -28,6 +28,7 @@ module SendGrid4r
|
|
28
28
|
Recipients = Struct.new(:recipients)
|
29
29
|
|
30
30
|
def self.create_recipient(resp)
|
31
|
+
return resp if resp.nil?
|
31
32
|
custom_fields = []
|
32
33
|
resp['custom_fields'].each do |field|
|
33
34
|
custom_fields.push(
|
@@ -35,7 +36,7 @@ module SendGrid4r
|
|
35
36
|
)
|
36
37
|
end
|
37
38
|
Recipient.new(
|
38
|
-
resp['created_at'],
|
39
|
+
Time.at(resp['created_at']),
|
39
40
|
custom_fields,
|
40
41
|
resp['email'],
|
41
42
|
resp['first_name'],
|
@@ -44,11 +45,12 @@ module SendGrid4r
|
|
44
45
|
resp['last_emailed'],
|
45
46
|
resp['last_name'],
|
46
47
|
resp['last_opend'],
|
47
|
-
resp['updated_at']
|
48
|
+
Time.at(resp['updated_at'])
|
48
49
|
)
|
49
50
|
end
|
50
51
|
|
51
52
|
def self.create_recipients(resp)
|
53
|
+
return resp if resp.nil?
|
52
54
|
recipients = []
|
53
55
|
resp['recipients'].each do |recipient|
|
54
56
|
recipients.push(
|
@@ -64,83 +66,91 @@ module SendGrid4r
|
|
64
66
|
url
|
65
67
|
end
|
66
68
|
|
67
|
-
def post_recipient(params)
|
68
|
-
resp = post(
|
69
|
+
def post_recipient(params, &block)
|
70
|
+
resp = post(
|
71
|
+
@auth, SendGrid4r::REST::Contacts::Recipients.url, params, &block
|
72
|
+
)
|
69
73
|
SendGrid4r::REST::Contacts::Recipients.create_recipient(resp)
|
70
74
|
end
|
71
75
|
|
72
|
-
def delete_recipients(emails)
|
73
|
-
delete(
|
76
|
+
def delete_recipients(emails, &block)
|
77
|
+
delete(
|
78
|
+
@auth, SendGrid4r::REST::Contacts::Recipients.url, emails, &block
|
79
|
+
)
|
74
80
|
end
|
75
81
|
|
76
|
-
def get_recipients(limit = nil, offset = nil)
|
82
|
+
def get_recipients(limit = nil, offset = nil, &block)
|
77
83
|
params = {}
|
78
84
|
params['limit'] = limit unless limit.nil?
|
79
85
|
params['offset'] = offset unless offset.nil?
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
)
|
84
|
-
else
|
85
|
-
resp = get(
|
86
|
-
@auth, SendGrid4r::REST::Contacts::Recipients.url
|
87
|
-
)
|
88
|
-
end
|
86
|
+
resp = get(
|
87
|
+
@auth, SendGrid4r::REST::Contacts::Recipients.url, params, &block
|
88
|
+
)
|
89
89
|
SendGrid4r::REST::Contacts::Recipients.create_recipients(resp)
|
90
90
|
end
|
91
91
|
|
92
|
-
def get_recipients_by_id(recipient_ids)
|
92
|
+
def get_recipients_by_id(recipient_ids, &block)
|
93
93
|
resp = get(
|
94
94
|
@auth,
|
95
95
|
"#{SendGrid4r::REST::Contacts::Recipients.url}/batch",
|
96
96
|
nil,
|
97
|
-
recipient_ids
|
97
|
+
recipient_ids,
|
98
|
+
&block
|
98
99
|
)
|
99
100
|
SendGrid4r::REST::Contacts::Recipients.create_recipients(resp)
|
100
101
|
end
|
101
102
|
|
102
|
-
def get_recipients_count
|
103
|
+
def get_recipients_count(&block)
|
103
104
|
resp = get(
|
104
|
-
@auth,
|
105
|
-
|
105
|
+
@auth,
|
106
|
+
"#{SendGrid4r::REST::Contacts::Recipients.url}/count",
|
107
|
+
&block
|
108
|
+
)
|
109
|
+
resp['recipient_count'] unless resp.nil?
|
106
110
|
end
|
107
111
|
|
108
|
-
def search_recipients(params)
|
112
|
+
def search_recipients(params, &block)
|
109
113
|
resp = get(
|
110
114
|
@auth,
|
111
115
|
"#{SendGrid4r::REST::Contacts::Recipients.url}/search",
|
112
|
-
params
|
116
|
+
params,
|
117
|
+
&block
|
113
118
|
)
|
114
119
|
SendGrid4r::REST::Contacts::Recipients.create_recipients(resp)
|
115
120
|
end
|
116
121
|
|
117
|
-
def get_recipient(recipient_id)
|
122
|
+
def get_recipient(recipient_id, &block)
|
118
123
|
resp = get(
|
119
124
|
@auth,
|
120
|
-
SendGrid4r::REST::Contacts::Recipients.url(recipient_id)
|
125
|
+
SendGrid4r::REST::Contacts::Recipients.url(recipient_id),
|
126
|
+
&block
|
121
127
|
)
|
122
128
|
SendGrid4r::REST::Contacts::Recipients.create_recipient(resp)
|
123
129
|
end
|
124
130
|
|
125
|
-
def delete_recipient(recipient_id)
|
131
|
+
def delete_recipient(recipient_id, &block)
|
126
132
|
delete(
|
127
|
-
@auth,
|
133
|
+
@auth,
|
134
|
+
SendGrid4r::REST::Contacts::Recipients.url(recipient_id),
|
135
|
+
&block
|
128
136
|
)
|
129
137
|
end
|
130
138
|
|
131
|
-
def get_lists_recipient_belong(recipient_id)
|
139
|
+
def get_lists_recipient_belong(recipient_id, &block)
|
132
140
|
resp = get(
|
133
141
|
@auth,
|
134
|
-
"#{SendGrid4r::REST::Contacts::Recipients.url(recipient_id)}/lists"
|
142
|
+
"#{SendGrid4r::REST::Contacts::Recipients.url(recipient_id)}/lists",
|
143
|
+
&block
|
135
144
|
)
|
136
145
|
SendGrid4r::REST::Contacts::Lists.create_lists(resp)
|
137
146
|
end
|
138
147
|
|
139
|
-
def post_recipients(recipients)
|
148
|
+
def post_recipients(recipients, &block)
|
140
149
|
resp = post(
|
141
150
|
@auth,
|
142
151
|
"#{SendGrid4r::Client::BASE_URL}/contactdb/recipients_batch",
|
143
|
-
recipients
|
152
|
+
recipients,
|
153
|
+
&block
|
144
154
|
)
|
145
155
|
SendGrid4r::REST::Contacts::Recipients.create_result(resp)
|
146
156
|
end
|
@@ -154,6 +164,7 @@ module SendGrid4r
|
|
154
164
|
)
|
155
165
|
|
156
166
|
def self.create_result(resp)
|
167
|
+
return resp if resp.nil?
|
157
168
|
error_indices = []
|
158
169
|
resp['error_indices'].each do |index|
|
159
170
|
error_indices.push(index)
|
@@ -25,6 +25,7 @@ module SendGrid4r
|
|
25
25
|
Fields = Struct.new(:reserved_fields)
|
26
26
|
|
27
27
|
def self.create_fields(resp)
|
28
|
+
return resp if resp.nil?
|
28
29
|
reserved_fields = []
|
29
30
|
resp['reserved_fields'].each do |field|
|
30
31
|
reserved_fields.push(
|
@@ -35,12 +36,15 @@ module SendGrid4r
|
|
35
36
|
end
|
36
37
|
|
37
38
|
def self.create_field(resp)
|
39
|
+
return resp if resp.nil?
|
38
40
|
Field.new(resp['name'], resp['type'])
|
39
41
|
end
|
40
42
|
|
41
|
-
def get_reserved_fields
|
43
|
+
def get_reserved_fields(&block)
|
42
44
|
resp = get(
|
43
|
-
@auth,
|
45
|
+
@auth,
|
46
|
+
"#{SendGrid4r::Client::BASE_URL}/contactdb/reserved_fields",
|
47
|
+
&block
|
44
48
|
)
|
45
49
|
SendGrid4r::REST::Contacts::ReservedFields.create_fields(resp)
|
46
50
|
end
|
@@ -27,12 +27,14 @@ module SendGrid4r
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def self.create_condition(resp)
|
30
|
+
return resp if resp.nil?
|
30
31
|
Condition.new(
|
31
32
|
resp['field'], resp['value'], resp['operator'], resp['and_or']
|
32
33
|
)
|
33
34
|
end
|
34
35
|
|
35
36
|
def self.create_segment(resp)
|
37
|
+
return resp if resp.nil?
|
36
38
|
conditions = []
|
37
39
|
resp['conditions'].each do |condition|
|
38
40
|
conditions.push(
|
@@ -49,6 +51,7 @@ module SendGrid4r
|
|
49
51
|
end
|
50
52
|
|
51
53
|
def self.create_segments(resp)
|
54
|
+
return resp if resp.nil?
|
52
55
|
segments = []
|
53
56
|
resp['segments'].each do |segment|
|
54
57
|
segments.push(
|
@@ -58,42 +61,49 @@ module SendGrid4r
|
|
58
61
|
Segments.new(segments)
|
59
62
|
end
|
60
63
|
|
61
|
-
def post_segment(params)
|
64
|
+
def post_segment(params, &block)
|
62
65
|
resp = post(
|
63
|
-
@auth, SendGrid4r::REST::Contacts::Segments.url, params.to_h
|
66
|
+
@auth, SendGrid4r::REST::Contacts::Segments.url, params.to_h, &block
|
64
67
|
)
|
65
68
|
SendGrid4r::REST::Contacts::Segments.create_segment(resp)
|
66
69
|
end
|
67
70
|
|
68
|
-
def get_segments
|
69
|
-
resp = get(@auth, SendGrid4r::REST::Contacts::Segments.url)
|
71
|
+
def get_segments(&block)
|
72
|
+
resp = get(@auth, SendGrid4r::REST::Contacts::Segments.url, &block)
|
70
73
|
SendGrid4r::REST::Contacts::Segments.create_segments(resp)
|
71
74
|
end
|
72
75
|
|
73
|
-
def get_segment(segment_id)
|
76
|
+
def get_segment(segment_id, &block)
|
74
77
|
resp = get(
|
75
|
-
@auth, SendGrid4r::REST::Contacts::Segments.url(segment_id)
|
78
|
+
@auth, SendGrid4r::REST::Contacts::Segments.url(segment_id), &block
|
76
79
|
)
|
77
80
|
SendGrid4r::REST::Contacts::Segments.create_segment(resp)
|
78
81
|
end
|
79
82
|
|
80
|
-
def put_segment(segment_id, params)
|
83
|
+
def put_segment(segment_id, params, &block)
|
81
84
|
resp = put(
|
82
|
-
@auth,
|
85
|
+
@auth,
|
86
|
+
SendGrid4r::REST::Contacts::Segments.url(segment_id),
|
87
|
+
params,
|
88
|
+
&block
|
83
89
|
)
|
84
90
|
SendGrid4r::REST::Contacts::Segments.create_segment(resp)
|
85
91
|
end
|
86
92
|
|
87
|
-
def delete_segment(segment_id)
|
88
|
-
delete(
|
93
|
+
def delete_segment(segment_id, &block)
|
94
|
+
delete(
|
95
|
+
@auth, SendGrid4r::REST::Contacts::Segments.url(segment_id), &block
|
96
|
+
)
|
89
97
|
end
|
90
98
|
|
91
|
-
def get_recipients_from_segment(
|
99
|
+
def get_recipients_from_segment(
|
100
|
+
segment_id, limit = nil, offset = nil, &block
|
101
|
+
)
|
92
102
|
params = {}
|
93
103
|
params['limit'] = limit unless limit.nil?
|
94
104
|
params['offset'] = offset unless offset.nil?
|
95
105
|
url = SendGrid4r::REST::Contacts::Segments.url(segment_id)
|
96
|
-
resp = get(@auth, "#{url}/recipients", params)
|
106
|
+
resp = get(@auth, "#{url}/recipients", params, &block)
|
97
107
|
SendGrid4r::REST::Contacts::Recipients.create_recipients(resp)
|
98
108
|
end
|
99
109
|
end
|
@@ -18,54 +18,68 @@ module SendGrid4r
|
|
18
18
|
Address = Struct.new(
|
19
19
|
:ip, :pools, :warmup, :start_date, :subusers, :rdns, :pool_name)
|
20
20
|
|
21
|
+
def self.create_addresses(resp)
|
22
|
+
return resp if resp.nil?
|
23
|
+
ips = []
|
24
|
+
resp.each do |address|
|
25
|
+
ips.push(SendGrid4r::REST::Ips::Addresses.create_address(address))
|
26
|
+
end
|
27
|
+
ips
|
28
|
+
end
|
29
|
+
|
21
30
|
def self.create_address(resp)
|
31
|
+
return resp if resp.nil?
|
22
32
|
Address.new(
|
23
33
|
resp['ip'],
|
24
34
|
resp['pools'],
|
25
35
|
resp['warmup'],
|
26
|
-
resp['start_date'],
|
36
|
+
resp['start_date'].nil? ? nil : Time.at(resp['start_date']),
|
27
37
|
resp['subusers'],
|
28
38
|
resp['rdns'],
|
29
39
|
resp['pool_name']
|
30
40
|
)
|
31
41
|
end
|
32
42
|
|
33
|
-
def
|
43
|
+
def self.url(ip = nil)
|
44
|
+
url = "#{SendGrid4r::Client::BASE_URL}/ips"
|
45
|
+
url = "#{url}/#{ip}" unless ip.nil?
|
46
|
+
url
|
47
|
+
end
|
48
|
+
|
49
|
+
def post_ip_to_pool(pool_name, ip, &block)
|
34
50
|
resp = post(
|
35
51
|
@auth,
|
36
|
-
|
37
|
-
ip: ip
|
52
|
+
SendGrid4r::REST::Ips::Pools.url(pool_name, 'ips'),
|
53
|
+
ip: ip,
|
54
|
+
&block
|
38
55
|
)
|
39
56
|
SendGrid4r::REST::Ips::Addresses.create_address(resp)
|
40
57
|
end
|
41
58
|
|
42
|
-
def get_ips
|
43
|
-
|
44
|
-
|
45
|
-
resp_a.each do |resp|
|
46
|
-
ips.push(SendGrid4r::REST::Ips::Addresses.create_address(resp))
|
47
|
-
end
|
48
|
-
ips
|
59
|
+
def get_ips(&block)
|
60
|
+
resp = get(@auth, SendGrid4r::REST::Ips::Addresses.url, &block)
|
61
|
+
SendGrid4r::REST::Ips::Addresses.create_addresses(resp)
|
49
62
|
end
|
50
63
|
|
51
|
-
def get_ips_assigned
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
57
|
-
ips
|
64
|
+
def get_ips_assigned(&block)
|
65
|
+
resp = get(
|
66
|
+
@auth, SendGrid4r::REST::Ips::Addresses.url('assigned'), &block
|
67
|
+
)
|
68
|
+
SendGrid4r::REST::Ips::Addresses.create_addresses(resp)
|
58
69
|
end
|
59
70
|
|
60
|
-
def get_ip(ip)
|
61
|
-
resp = get(
|
71
|
+
def get_ip(ip, &block)
|
72
|
+
resp = get(
|
73
|
+
@auth, SendGrid4r::REST::Ips::Addresses.url(ip), &block
|
74
|
+
)
|
62
75
|
SendGrid4r::REST::Ips::Addresses.create_address(resp)
|
63
76
|
end
|
64
77
|
|
65
|
-
def delete_ip_from_pool(pool_name, ip)
|
78
|
+
def delete_ip_from_pool(pool_name, ip, &block)
|
66
79
|
delete(
|
67
80
|
@auth,
|
68
|
-
|
81
|
+
SendGrid4r::REST::Ips::Pools.url(pool_name, 'ips', ip),
|
82
|
+
&block
|
69
83
|
)
|
70
84
|
end
|
71
85
|
end
|
@@ -17,45 +17,60 @@ module SendGrid4r
|
|
17
17
|
|
18
18
|
Pool = Struct.new(:pool_name, :name, :ips)
|
19
19
|
|
20
|
+
def self.create_pools(resp)
|
21
|
+
return resp if resp.nil?
|
22
|
+
pools = []
|
23
|
+
resp.each do |pool|
|
24
|
+
pools.push(SendGrid4r::REST::Ips::Pools.create_pool(pool))
|
25
|
+
end
|
26
|
+
pools
|
27
|
+
end
|
28
|
+
|
20
29
|
def self.create_pool(resp)
|
30
|
+
return resp if resp.nil?
|
21
31
|
ips = []
|
22
32
|
Array(resp['ips']).each { |ip| ips.push(ip) }
|
23
33
|
Pool.new(resp['pool_name'], resp['name'], ips)
|
24
34
|
end
|
25
35
|
|
26
|
-
def
|
36
|
+
def self.url(name = nil, ips = nil, ip = nil)
|
37
|
+
url = "#{SendGrid4r::Client::BASE_URL}/ips/pools"
|
38
|
+
url = "#{url}/#{name}" unless name.nil?
|
39
|
+
url = "#{url}/#{ips}" unless ips.nil?
|
40
|
+
url = "#{url}/#{ip}" unless ip.nil?
|
41
|
+
url
|
42
|
+
end
|
43
|
+
|
44
|
+
def post_pool(name, &block)
|
27
45
|
resp = post(
|
28
|
-
@auth,
|
46
|
+
@auth, SendGrid4r::REST::Ips::Pools.url, name: name, &block
|
29
47
|
)
|
30
48
|
SendGrid4r::REST::Ips::Pools.create_pool(resp)
|
31
49
|
end
|
32
50
|
|
33
|
-
def get_pools
|
34
|
-
|
35
|
-
|
36
|
-
resp_a.each do |resp|
|
37
|
-
pools.push(SendGrid4r::REST::Ips::Pools.create_pool(resp))
|
38
|
-
end
|
39
|
-
pools
|
51
|
+
def get_pools(&block)
|
52
|
+
resp = get(@auth, SendGrid4r::REST::Ips::Pools.url, &block)
|
53
|
+
SendGrid4r::REST::Ips::Pools.create_pools(resp)
|
40
54
|
end
|
41
55
|
|
42
|
-
def get_pool(name)
|
56
|
+
def get_pool(name, &block)
|
43
57
|
resp = get(
|
44
|
-
@auth,
|
58
|
+
@auth, SendGrid4r::REST::Ips::Pools.url(name), &block
|
45
59
|
)
|
46
60
|
SendGrid4r::REST::Ips::Pools.create_pool(resp)
|
47
61
|
end
|
48
62
|
|
49
|
-
def put_pool(name, new_name)
|
63
|
+
def put_pool(name, new_name, &block)
|
50
64
|
resp = put(
|
51
65
|
@auth,
|
52
|
-
|
53
|
-
name: new_name
|
66
|
+
SendGrid4r::REST::Ips::Pools.url(name),
|
67
|
+
name: new_name,
|
68
|
+
&block)
|
54
69
|
SendGrid4r::REST::Ips::Pools.create_pool(resp)
|
55
70
|
end
|
56
71
|
|
57
|
-
def delete_pool(name)
|
58
|
-
delete(@auth,
|
72
|
+
def delete_pool(name, &block)
|
73
|
+
delete(@auth, SendGrid4r::REST::Ips::Pools.url(name), &block)
|
59
74
|
end
|
60
75
|
end
|
61
76
|
end
|
@@ -11,42 +11,61 @@ module SendGrid4r
|
|
11
11
|
#
|
12
12
|
module Warmup
|
13
13
|
include SendGrid4r::REST::Request
|
14
|
-
WarmupIp = Struct.new(:ip, :start_date)
|
15
14
|
|
16
|
-
|
17
|
-
WarmupIp.new(resp['ip'], resp['start_date'])
|
18
|
-
end
|
15
|
+
WarmupIp = Struct.new(:ip, :start_date)
|
19
16
|
|
20
|
-
def
|
17
|
+
def self.create_warmup_ips(resp)
|
18
|
+
return resp if resp.nil?
|
21
19
|
ips = []
|
22
|
-
|
23
|
-
|
24
|
-
ips.push(SendGrid4r::REST::Ips::Warmup.create_warmup_ip(resp))
|
20
|
+
resp.each do |warmup_ip|
|
21
|
+
ips.push(SendGrid4r::REST::Ips::Warmup.create_warmup_ip(warmup_ip))
|
25
22
|
end
|
26
23
|
ips
|
27
24
|
end
|
28
25
|
|
29
|
-
def
|
26
|
+
def self.create_warmup_ip(resp)
|
27
|
+
return resp if resp.nil?
|
28
|
+
WarmupIp.new(
|
29
|
+
resp['ip'],
|
30
|
+
resp['start_date'].nil? ? nil : Time.at(resp['start_date'])
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.url(ip_address = nil)
|
35
|
+
url = "#{SendGrid4r::Client::BASE_URL}/ips/warmup"
|
36
|
+
url = "#{url}/#{ip_address}" unless ip_address.nil?
|
37
|
+
url
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_warmup_ips(&block)
|
41
|
+
resp = get(@auth, SendGrid4r::REST::Ips::Warmup.url, &block)
|
42
|
+
SendGrid4r::REST::Ips::Warmup.create_warmup_ips(resp)
|
43
|
+
end
|
44
|
+
|
45
|
+
def get_warmup_ip(ip_address, &block)
|
30
46
|
resp = get(
|
31
47
|
@auth,
|
32
|
-
|
48
|
+
SendGrid4r::REST::Ips::Warmup.url(ip_address),
|
49
|
+
&block
|
33
50
|
)
|
34
51
|
SendGrid4r::REST::Ips::Warmup.create_warmup_ip(resp)
|
35
52
|
end
|
36
53
|
|
37
|
-
def post_warmup_ip(ip_address)
|
54
|
+
def post_warmup_ip(ip_address, &block)
|
38
55
|
resp = post(
|
39
56
|
@auth,
|
40
|
-
|
41
|
-
ip: ip_address
|
57
|
+
SendGrid4r::REST::Ips::Warmup.url,
|
58
|
+
ip: ip_address,
|
59
|
+
&block
|
42
60
|
)
|
43
61
|
SendGrid4r::REST::Ips::Warmup.create_warmup_ip(resp)
|
44
62
|
end
|
45
63
|
|
46
|
-
def delete_warmup_ip(ip_address)
|
64
|
+
def delete_warmup_ip(ip_address, &block)
|
47
65
|
delete(
|
48
66
|
@auth,
|
49
|
-
|
67
|
+
SendGrid4r::REST::Ips::Warmup.url(ip_address),
|
68
|
+
&block
|
50
69
|
)
|
51
70
|
end
|
52
71
|
end
|
@@ -11,35 +11,32 @@ module SendGrid4r
|
|
11
11
|
# SendGrid Web API v3 Request
|
12
12
|
#
|
13
13
|
module Request
|
14
|
-
|
15
|
-
|
16
|
-
execute(:get, auth, endpoint, params, payload)
|
14
|
+
def get(auth, endpoint, params = nil, payload = nil, &block)
|
15
|
+
execute(:get, auth, endpoint, params, payload, &block)
|
17
16
|
end
|
18
17
|
|
19
|
-
def post(auth, endpoint, payload = nil)
|
20
|
-
execute(:post, auth, endpoint, nil, payload)
|
18
|
+
def post(auth, endpoint, payload = nil, &block)
|
19
|
+
execute(:post, auth, endpoint, nil, payload, &block)
|
21
20
|
end
|
22
21
|
|
23
|
-
def patch(auth, endpoint, payload)
|
24
|
-
execute(:patch, auth, endpoint, nil, payload)
|
22
|
+
def patch(auth, endpoint, payload, &block)
|
23
|
+
execute(:patch, auth, endpoint, nil, payload, &block)
|
25
24
|
end
|
26
25
|
|
27
|
-
def put(auth, endpoint, payload)
|
28
|
-
execute(:put, auth, endpoint, nil, payload)
|
26
|
+
def put(auth, endpoint, payload, &block)
|
27
|
+
execute(:put, auth, endpoint, nil, payload, &block)
|
29
28
|
end
|
30
29
|
|
31
|
-
def delete(auth, endpoint, payload = nil)
|
32
|
-
execute(:delete, auth, endpoint, nil, payload)
|
30
|
+
def delete(auth, endpoint, payload = nil, &block)
|
31
|
+
execute(:delete, auth, endpoint, nil, payload, &block)
|
33
32
|
end
|
34
33
|
|
35
|
-
def execute(method, auth, endpoint, params, payload)
|
36
|
-
args =
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
args[:headers] = { content_type: :json }
|
42
|
-
args[:payload] = payload.to_json unless payload.nil?
|
34
|
+
def execute(method, auth, endpoint, params, payload, &block)
|
35
|
+
args = create_args(method, auth, endpoint, params, payload)
|
36
|
+
if block_given?
|
37
|
+
RestClient::Request.execute(args, &block)
|
38
|
+
return nil
|
39
|
+
end
|
43
40
|
body = RestClient::Request.execute(args)
|
44
41
|
if body.nil? || body.length < 2
|
45
42
|
body
|
@@ -48,6 +45,23 @@ module SendGrid4r
|
|
48
45
|
end
|
49
46
|
end
|
50
47
|
|
48
|
+
def create_args(method, auth, endpoint, params, payload)
|
49
|
+
args = {}
|
50
|
+
args[:method] = method
|
51
|
+
args[:url] = process_url_params(endpoint, params)
|
52
|
+
headers = {}
|
53
|
+
headers[:content_type] = :json
|
54
|
+
if !auth.api_key.nil?
|
55
|
+
headers[:authorization] = "Bearer #{auth.api_key}"
|
56
|
+
else
|
57
|
+
args[:user] = auth.username
|
58
|
+
args[:password] = auth.password
|
59
|
+
end
|
60
|
+
args[:headers] = headers
|
61
|
+
args[:payload] = payload.to_json unless payload.nil?
|
62
|
+
args
|
63
|
+
end
|
64
|
+
|
51
65
|
def process_url_params(endpoint, params)
|
52
66
|
if params.nil? || params.empty?
|
53
67
|
endpoint
|
@@ -14,22 +14,29 @@ module SendGrid4r
|
|
14
14
|
EnforcedTls = Struct.new(:require_tls, :require_valid_cert)
|
15
15
|
|
16
16
|
def self.create_enforced_tls(resp)
|
17
|
+
return resp if resp.nil?
|
17
18
|
EnforcedTls.new(resp['require_tls'], resp['require_valid_cert'])
|
18
19
|
end
|
19
20
|
|
20
|
-
def
|
21
|
+
def self.url
|
22
|
+
"#{SendGrid4r::Client::BASE_URL}/user/settings/enforced_tls"
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_enforced_tls(&block)
|
21
26
|
resp = get(
|
22
27
|
@auth,
|
23
|
-
|
28
|
+
SendGrid4r::REST::Settings::EnforcedTls.url,
|
29
|
+
&block
|
24
30
|
)
|
25
31
|
SendGrid4r::REST::Settings::EnforcedTls.create_enforced_tls(resp)
|
26
32
|
end
|
27
33
|
|
28
|
-
def patch_enforced_tls(params)
|
34
|
+
def patch_enforced_tls(params, &block)
|
29
35
|
resp = patch(
|
30
36
|
@auth,
|
31
|
-
|
32
|
-
params.to_h
|
37
|
+
SendGrid4r::REST::Settings::EnforcedTls.url,
|
38
|
+
params.to_h,
|
39
|
+
&block
|
33
40
|
)
|
34
41
|
SendGrid4r::REST::Settings::EnforcedTls.create_enforced_tls(resp)
|
35
42
|
end
|