parity-sendgrid-api 0.0.4
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 +7 -0
- data/.gitignore +6 -0
- data/.rspec +3 -0
- data/.travis.yml +3 -0
- data/.yardopts +6 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +67 -0
- data/LICENSE +22 -0
- data/README.md +261 -0
- data/Rakefile +12 -0
- data/lib/sendgrid/api.rb +7 -0
- data/lib/sendgrid/api/client.rb +43 -0
- data/lib/sendgrid/api/entities/category.rb +13 -0
- data/lib/sendgrid/api/entities/email.rb +13 -0
- data/lib/sendgrid/api/entities/entity.rb +83 -0
- data/lib/sendgrid/api/entities/list.rb +30 -0
- data/lib/sendgrid/api/entities/marketing_email.rb +20 -0
- data/lib/sendgrid/api/entities/profile.rb +14 -0
- data/lib/sendgrid/api/entities/response.rb +21 -0
- data/lib/sendgrid/api/entities/response_insert.rb +23 -0
- data/lib/sendgrid/api/entities/response_remove.rb +23 -0
- data/lib/sendgrid/api/entities/schedule.rb +13 -0
- data/lib/sendgrid/api/entities/sender_address.rb +13 -0
- data/lib/sendgrid/api/entities/stats.rb +14 -0
- data/lib/sendgrid/api/newsletter/categories.rb +74 -0
- data/lib/sendgrid/api/newsletter/emails.rb +69 -0
- data/lib/sendgrid/api/newsletter/lists.rb +64 -0
- data/lib/sendgrid/api/newsletter/marketing_emails.rb +72 -0
- data/lib/sendgrid/api/newsletter/recipients.rb +55 -0
- data/lib/sendgrid/api/newsletter/schedule.rb +70 -0
- data/lib/sendgrid/api/newsletter/sender_addresses.rb +80 -0
- data/lib/sendgrid/api/newsletter/utils.rb +34 -0
- data/lib/sendgrid/api/rest/errors/error.rb +66 -0
- data/lib/sendgrid/api/rest/resource.rb +58 -0
- data/lib/sendgrid/api/rest/response/parse_error.rb +19 -0
- data/lib/sendgrid/api/rest/response/parse_json.rb +24 -0
- data/lib/sendgrid/api/service.rb +23 -0
- data/lib/sendgrid/api/version.rb +5 -0
- data/lib/sendgrid/api/web/mail.rb +44 -0
- data/lib/sendgrid/api/web/profile.rb +38 -0
- data/lib/sendgrid/api/web/stats.rb +36 -0
- data/sendgrid-api.gemspec +23 -0
- data/spec/fixtures/categories.json +11 -0
- data/spec/fixtures/emails/email.json +6 -0
- data/spec/fixtures/emails/emails.json +10 -0
- data/spec/fixtures/errors/already_exists.json +3 -0
- data/spec/fixtures/errors/bad_request.json +6 -0
- data/spec/fixtures/errors/database_error.json +3 -0
- data/spec/fixtures/errors/does_not_exist.json +3 -0
- data/spec/fixtures/errors/forbidden.json +3 -0
- data/spec/fixtures/errors/invalid_fields.json +3 -0
- data/spec/fixtures/errors/not_scheduled.json +3 -0
- data/spec/fixtures/errors/unauthorized.json +6 -0
- data/spec/fixtures/lists/list.json +5 -0
- data/spec/fixtures/lists/lists.json +11 -0
- data/spec/fixtures/marketing_emails/marketing_email.json +19 -0
- data/spec/fixtures/marketing_emails/marketing_emails.json +10 -0
- data/spec/fixtures/profile.json +18 -0
- data/spec/fixtures/recipients.json +8 -0
- data/spec/fixtures/schedule.json +3 -0
- data/spec/fixtures/sender_addresses/sender_address.json +11 -0
- data/spec/fixtures/sender_addresses/sender_addresses.json +11 -0
- data/spec/fixtures/stats.json +50 -0
- data/spec/fixtures/success.json +3 -0
- data/spec/sendgrid/api/client_spec.rb +38 -0
- data/spec/sendgrid/api/entities/category_spec.rb +14 -0
- data/spec/sendgrid/api/entities/email_spec.rb +15 -0
- data/spec/sendgrid/api/entities/entity_spec.rb +279 -0
- data/spec/sendgrid/api/entities/list_spec.rb +34 -0
- data/spec/sendgrid/api/entities/marketing_email_spec.rb +31 -0
- data/spec/sendgrid/api/entities/profile_spec.rb +26 -0
- data/spec/sendgrid/api/entities/response_insert_spec.rb +28 -0
- data/spec/sendgrid/api/entities/response_remove_spec.rb +28 -0
- data/spec/sendgrid/api/entities/response_spec.rb +28 -0
- data/spec/sendgrid/api/entities/schedule_spec.rb +14 -0
- data/spec/sendgrid/api/entities/sender_address_spec.rb +21 -0
- data/spec/sendgrid/api/entities/stats_spec.rb +25 -0
- data/spec/sendgrid/api/newsletter/categories_spec.rb +247 -0
- data/spec/sendgrid/api/newsletter/emails_spec.rb +265 -0
- data/spec/sendgrid/api/newsletter/lists_spec.rb +307 -0
- data/spec/sendgrid/api/newsletter/marketing_emails_spec.rb +306 -0
- data/spec/sendgrid/api/newsletter/recipients_spec.rb +252 -0
- data/spec/sendgrid/api/newsletter/schedule_spec.rb +263 -0
- data/spec/sendgrid/api/newsletter/sender_addresses_spec.rb +300 -0
- data/spec/sendgrid/api/rest/errors/error_spec.rb +121 -0
- data/spec/sendgrid/api/rest/resource_spec.rb +145 -0
- data/spec/sendgrid/api/rest/response/parse_error_spec.rb +39 -0
- data/spec/sendgrid/api/rest/response/parse_json_spec.rb +45 -0
- data/spec/sendgrid/api/service_spec.rb +44 -0
- data/spec/sendgrid/api/version_spec.rb +11 -0
- data/spec/sendgrid/api/web/mail_spec.rb +111 -0
- data/spec/sendgrid/api/web/profile_spec.rb +110 -0
- data/spec/sendgrid/api/web/stats_spec.rb +94 -0
- data/spec/spec_helper.rb +23 -0
- data/spec/support/helpers.rb +23 -0
- data/spec/support/mock.rb +30 -0
- data/spec/support/online.rb +114 -0
- data/spec/support/shared_examples.rb +104 -0
- metadata +225 -0
@@ -0,0 +1,50 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"delivered":4792,
|
4
|
+
"unique_open":308,
|
5
|
+
"spamreport":3,
|
6
|
+
"unique_click":11,
|
7
|
+
"drop":57,
|
8
|
+
"request":5359,
|
9
|
+
"bounce":622,
|
10
|
+
"deferred":1975,
|
11
|
+
"processed":5302,
|
12
|
+
"date":"2013-06-18",
|
13
|
+
"open":481,
|
14
|
+
"click":11,
|
15
|
+
"blocked":29
|
16
|
+
},
|
17
|
+
{
|
18
|
+
"delivered":3,
|
19
|
+
"unique_open":17,
|
20
|
+
"unique_click":1,
|
21
|
+
"deferred":405,
|
22
|
+
"date":"2013-06-19",
|
23
|
+
"open":37,
|
24
|
+
"click":1
|
25
|
+
},
|
26
|
+
{
|
27
|
+
"date":"2013-06-20",
|
28
|
+
"deferred":381,
|
29
|
+
"unique_open":4,
|
30
|
+
"open":7,
|
31
|
+
"bounce":2
|
32
|
+
},
|
33
|
+
{
|
34
|
+
"unique_open":2,
|
35
|
+
"bounce":1,
|
36
|
+
"deferred":113,
|
37
|
+
"date":"2013-06-21",
|
38
|
+
"open":8,
|
39
|
+
"blocked":31
|
40
|
+
},
|
41
|
+
{
|
42
|
+
"date":"2013-06-23",
|
43
|
+
"unique_open":2,
|
44
|
+
"open":2
|
45
|
+
},
|
46
|
+
{
|
47
|
+
"date":"2013-06-24",
|
48
|
+
"open":1
|
49
|
+
}
|
50
|
+
]
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Sendgrid
|
4
|
+
module API
|
5
|
+
describe Client do
|
6
|
+
|
7
|
+
subject { described_class.new(user, key) }
|
8
|
+
let(:user) { 'some user' }
|
9
|
+
let(:key) { 'some key' }
|
10
|
+
|
11
|
+
its(:user) { should == user }
|
12
|
+
its(:key) { should == key }
|
13
|
+
|
14
|
+
it { should respond_to(:profile) }
|
15
|
+
it { should respond_to(:stats) }
|
16
|
+
it { should respond_to(:mail) }
|
17
|
+
it { should respond_to(:lists) }
|
18
|
+
it { should respond_to(:emails) }
|
19
|
+
it { should respond_to(:sender_addresses) }
|
20
|
+
it { should respond_to(:categories) }
|
21
|
+
it { should respond_to(:marketing_emails) }
|
22
|
+
it { should respond_to(:recipients) }
|
23
|
+
it { should respond_to(:schedule) }
|
24
|
+
|
25
|
+
its(:profile) { should_not be_nil }
|
26
|
+
its(:stats) { should_not be_nil }
|
27
|
+
its(:mail) { should_not be_nil }
|
28
|
+
its(:lists) { should_not be_nil }
|
29
|
+
its(:emails) { should_not be_nil }
|
30
|
+
its(:sender_addresses) { should_not be_nil }
|
31
|
+
its(:categories) { should_not be_nil }
|
32
|
+
its(:marketing_emails) { should_not be_nil }
|
33
|
+
its(:recipients) { should_not be_nil }
|
34
|
+
its(:schedule) { should_not be_nil }
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,279 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Sendgrid
|
4
|
+
module API
|
5
|
+
module Entities
|
6
|
+
describe Entity do
|
7
|
+
|
8
|
+
subject { described_class }
|
9
|
+
|
10
|
+
after do
|
11
|
+
described_class.clear_attributes
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '.clear_attributes' do
|
15
|
+
before do
|
16
|
+
subject.attribute :attr1
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should clear the attributes' do
|
20
|
+
subject.clear_attributes
|
21
|
+
subject.attributes.should be_empty
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '.attribute' do
|
26
|
+
context 'when the attributes are empty' do
|
27
|
+
before do
|
28
|
+
subject.clear_attributes
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should set the entity attributes' do
|
32
|
+
subject.attribute :attr1, :attr2
|
33
|
+
subject.attributes.should have(2).items
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'when the attributes are not empty' do
|
38
|
+
before do
|
39
|
+
subject.clear_attributes
|
40
|
+
subject.attribute :attr1
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should add attributes to the entity' do
|
44
|
+
subject.attribute :attr2
|
45
|
+
subject.attributes.should have(2).items
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'when the attributes are repeated' do
|
50
|
+
before do
|
51
|
+
subject.clear_attributes
|
52
|
+
subject.attribute :attr1
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should add distinct attributes to the entity' do
|
56
|
+
subject.attribute :attr1, :attr2
|
57
|
+
subject.attributes.should have(2).items
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#attributes' do
|
63
|
+
before do
|
64
|
+
subject.clear_attributes
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'without attributes' do
|
68
|
+
its(:attributes) { should be_empty }
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'with attributes' do
|
72
|
+
before do
|
73
|
+
subject.attribute :attr1, :attr2
|
74
|
+
end
|
75
|
+
|
76
|
+
its(:attributes) { should have(2).items }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '.from_response' do
|
81
|
+
context 'when response is an array' do
|
82
|
+
before do
|
83
|
+
response.should_receive(:body).and_return([item1, item2])
|
84
|
+
end
|
85
|
+
let(:response) { double('response') }
|
86
|
+
let(:item1) { double('item').as_null_object }
|
87
|
+
let(:item2) { double('item').as_null_object }
|
88
|
+
|
89
|
+
subject { described_class.from_response(response) }
|
90
|
+
|
91
|
+
it { should have(2).items }
|
92
|
+
its([0]) { should be_instance_of(described_class) }
|
93
|
+
its([1]) { should be_instance_of(described_class) }
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'when response is a hash' do
|
97
|
+
before do
|
98
|
+
response.should_receive(:body).and_return(item)
|
99
|
+
end
|
100
|
+
let(:response) { double('response') }
|
101
|
+
let(:item) { Hash.new }
|
102
|
+
|
103
|
+
subject { described_class.from_response(response) }
|
104
|
+
|
105
|
+
it { should be_instance_of(described_class) }
|
106
|
+
end
|
107
|
+
|
108
|
+
context 'when response is a string' do
|
109
|
+
before do
|
110
|
+
response.should_receive(:body).and_return(item)
|
111
|
+
end
|
112
|
+
let(:response) { double('response') }
|
113
|
+
let(:item) { 'some string' }
|
114
|
+
|
115
|
+
subject { described_class.from_response(response) }
|
116
|
+
|
117
|
+
it { should be_nil }
|
118
|
+
end
|
119
|
+
|
120
|
+
context 'when response is a number' do
|
121
|
+
before do
|
122
|
+
response.should_receive(:body).and_return(item)
|
123
|
+
end
|
124
|
+
let(:response) { double('response') }
|
125
|
+
let(:item) { 45 }
|
126
|
+
|
127
|
+
subject { described_class.from_response(response) }
|
128
|
+
|
129
|
+
it { should be_nil }
|
130
|
+
end
|
131
|
+
|
132
|
+
context 'when response is a nil object' do
|
133
|
+
before do
|
134
|
+
response.should_receive(:body).and_return(item)
|
135
|
+
end
|
136
|
+
let(:response) { double('response') }
|
137
|
+
let(:item) { nil }
|
138
|
+
|
139
|
+
subject { described_class.from_response(response) }
|
140
|
+
|
141
|
+
it { should be_nil }
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
describe '.new' do
|
146
|
+
before do
|
147
|
+
described_class.attribute :attr1, :attr2
|
148
|
+
end
|
149
|
+
|
150
|
+
context 'creating entity with no attributes' do
|
151
|
+
subject { entity }
|
152
|
+
let(:entity) { described_class.new }
|
153
|
+
|
154
|
+
it { should respond_to(:attr1) }
|
155
|
+
it { should respond_to(:attr2) }
|
156
|
+
|
157
|
+
its(:attr1) { should be_nil }
|
158
|
+
its(:attr2) { should be_nil }
|
159
|
+
|
160
|
+
it 'should raise error for invalid attributes' do
|
161
|
+
expect { subject.attr3 }.to raise_error(NameError)
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'should set attr1' do
|
165
|
+
subject.attr1 = 'attr1 value'
|
166
|
+
subject.attr1.should == 'attr1 value'
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'should set attr2' do
|
170
|
+
subject.attr1 = 'attr2 value'
|
171
|
+
subject.attr1.should == 'attr2 value'
|
172
|
+
end
|
173
|
+
|
174
|
+
describe '#attributes' do
|
175
|
+
subject { entity.attributes }
|
176
|
+
|
177
|
+
it { should be_empty }
|
178
|
+
end
|
179
|
+
|
180
|
+
describe '#as_json' do
|
181
|
+
subject { entity.as_json }
|
182
|
+
|
183
|
+
it { should be_empty }
|
184
|
+
end
|
185
|
+
|
186
|
+
describe '#to_json' do
|
187
|
+
subject { JSON.parse(entity.to_json) }
|
188
|
+
|
189
|
+
it { should be_empty }
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
context 'creating entity with valid attributes' do
|
194
|
+
subject { entity }
|
195
|
+
let(:entity) { described_class.new(:attr1 => attr1, :attr2 => attr2) }
|
196
|
+
let(:attr1) { 'attr1 value' }
|
197
|
+
let(:attr2) { 'attr2 value' }
|
198
|
+
|
199
|
+
it { should respond_to(:attr1) }
|
200
|
+
it { should respond_to(:attr2) }
|
201
|
+
|
202
|
+
its(:attr1) { should == attr1 }
|
203
|
+
its(:attr2) { should == attr2 }
|
204
|
+
|
205
|
+
describe '#attributes' do
|
206
|
+
subject { entity.attributes }
|
207
|
+
|
208
|
+
it { should have(2).items }
|
209
|
+
it { should include(:attr1) }
|
210
|
+
it { should include(:attr2) }
|
211
|
+
it { should_not include(:attr3) }
|
212
|
+
end
|
213
|
+
|
214
|
+
describe '#as_json' do
|
215
|
+
subject { entity.as_json }
|
216
|
+
|
217
|
+
it { should have(2).items }
|
218
|
+
it { should include(:attr1) }
|
219
|
+
it { should include(:attr2) }
|
220
|
+
it { should_not include(:attr3) }
|
221
|
+
end
|
222
|
+
|
223
|
+
describe '#to_json' do
|
224
|
+
subject { JSON.parse(entity.to_json) }
|
225
|
+
|
226
|
+
it { should have(2).items }
|
227
|
+
it { should include('attr1') }
|
228
|
+
it { should include('attr2') }
|
229
|
+
it { should_not include('attr3') }
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
context 'creating entity with invalid attributes' do
|
234
|
+
subject { entity }
|
235
|
+
let(:entity) { described_class.new(:attr1 => attr1, :attr2 => attr2, :attr3 => attr3) }
|
236
|
+
let(:attr1) { 'attr1 value' }
|
237
|
+
let(:attr2) { 'attr2 value' }
|
238
|
+
let(:attr3) { 'attr3 value' }
|
239
|
+
|
240
|
+
its(:attr1) { should == attr1 }
|
241
|
+
its(:attr2) { should == attr2 }
|
242
|
+
|
243
|
+
it 'should raise error for invalid attributes' do
|
244
|
+
expect { subject.attr3 }.to raise_error(NameError)
|
245
|
+
end
|
246
|
+
|
247
|
+
describe '#attributes' do
|
248
|
+
subject { entity.attributes }
|
249
|
+
|
250
|
+
it { should have(2).items }
|
251
|
+
it { should include(:attr1) }
|
252
|
+
it { should include(:attr2) }
|
253
|
+
it { should_not include(:attr3) }
|
254
|
+
end
|
255
|
+
|
256
|
+
describe '#as_json' do
|
257
|
+
subject { entity.as_json }
|
258
|
+
|
259
|
+
it { should have(2).items }
|
260
|
+
it { should include(:attr1) }
|
261
|
+
it { should include(:attr2) }
|
262
|
+
it { should_not include(:attr3) }
|
263
|
+
end
|
264
|
+
|
265
|
+
describe '#to_json' do
|
266
|
+
subject { JSON.parse(entity.to_json) }
|
267
|
+
|
268
|
+
it { should have(2).items }
|
269
|
+
it { should include('attr1') }
|
270
|
+
it { should include('attr2') }
|
271
|
+
it { should_not include('attr3') }
|
272
|
+
end
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
279
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Sendgrid
|
4
|
+
module API
|
5
|
+
module Entities
|
6
|
+
describe List do
|
7
|
+
subject { described_class.new }
|
8
|
+
|
9
|
+
it { should respond_to(:list) }
|
10
|
+
|
11
|
+
describe '.from_object' do
|
12
|
+
context 'when object is a String' do
|
13
|
+
let(:object) { 'my list name' }
|
14
|
+
subject { described_class.from_object(object) }
|
15
|
+
it { should be_instance_of(described_class) }
|
16
|
+
its(:list) { should == object }
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'when object is a List' do
|
20
|
+
let(:object) { described_class.new(:list => 'my list name') }
|
21
|
+
subject { described_class.from_object(object) }
|
22
|
+
it { should == object }
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'when object is nil' do
|
26
|
+
let(:object) { nil }
|
27
|
+
subject { described_class.from_object(object) }
|
28
|
+
it { should be_nil }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|