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.
Files changed (99) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +6 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +3 -0
  5. data/.yardopts +6 -0
  6. data/Gemfile +17 -0
  7. data/Gemfile.lock +67 -0
  8. data/LICENSE +22 -0
  9. data/README.md +261 -0
  10. data/Rakefile +12 -0
  11. data/lib/sendgrid/api.rb +7 -0
  12. data/lib/sendgrid/api/client.rb +43 -0
  13. data/lib/sendgrid/api/entities/category.rb +13 -0
  14. data/lib/sendgrid/api/entities/email.rb +13 -0
  15. data/lib/sendgrid/api/entities/entity.rb +83 -0
  16. data/lib/sendgrid/api/entities/list.rb +30 -0
  17. data/lib/sendgrid/api/entities/marketing_email.rb +20 -0
  18. data/lib/sendgrid/api/entities/profile.rb +14 -0
  19. data/lib/sendgrid/api/entities/response.rb +21 -0
  20. data/lib/sendgrid/api/entities/response_insert.rb +23 -0
  21. data/lib/sendgrid/api/entities/response_remove.rb +23 -0
  22. data/lib/sendgrid/api/entities/schedule.rb +13 -0
  23. data/lib/sendgrid/api/entities/sender_address.rb +13 -0
  24. data/lib/sendgrid/api/entities/stats.rb +14 -0
  25. data/lib/sendgrid/api/newsletter/categories.rb +74 -0
  26. data/lib/sendgrid/api/newsletter/emails.rb +69 -0
  27. data/lib/sendgrid/api/newsletter/lists.rb +64 -0
  28. data/lib/sendgrid/api/newsletter/marketing_emails.rb +72 -0
  29. data/lib/sendgrid/api/newsletter/recipients.rb +55 -0
  30. data/lib/sendgrid/api/newsletter/schedule.rb +70 -0
  31. data/lib/sendgrid/api/newsletter/sender_addresses.rb +80 -0
  32. data/lib/sendgrid/api/newsletter/utils.rb +34 -0
  33. data/lib/sendgrid/api/rest/errors/error.rb +66 -0
  34. data/lib/sendgrid/api/rest/resource.rb +58 -0
  35. data/lib/sendgrid/api/rest/response/parse_error.rb +19 -0
  36. data/lib/sendgrid/api/rest/response/parse_json.rb +24 -0
  37. data/lib/sendgrid/api/service.rb +23 -0
  38. data/lib/sendgrid/api/version.rb +5 -0
  39. data/lib/sendgrid/api/web/mail.rb +44 -0
  40. data/lib/sendgrid/api/web/profile.rb +38 -0
  41. data/lib/sendgrid/api/web/stats.rb +36 -0
  42. data/sendgrid-api.gemspec +23 -0
  43. data/spec/fixtures/categories.json +11 -0
  44. data/spec/fixtures/emails/email.json +6 -0
  45. data/spec/fixtures/emails/emails.json +10 -0
  46. data/spec/fixtures/errors/already_exists.json +3 -0
  47. data/spec/fixtures/errors/bad_request.json +6 -0
  48. data/spec/fixtures/errors/database_error.json +3 -0
  49. data/spec/fixtures/errors/does_not_exist.json +3 -0
  50. data/spec/fixtures/errors/forbidden.json +3 -0
  51. data/spec/fixtures/errors/invalid_fields.json +3 -0
  52. data/spec/fixtures/errors/not_scheduled.json +3 -0
  53. data/spec/fixtures/errors/unauthorized.json +6 -0
  54. data/spec/fixtures/lists/list.json +5 -0
  55. data/spec/fixtures/lists/lists.json +11 -0
  56. data/spec/fixtures/marketing_emails/marketing_email.json +19 -0
  57. data/spec/fixtures/marketing_emails/marketing_emails.json +10 -0
  58. data/spec/fixtures/profile.json +18 -0
  59. data/spec/fixtures/recipients.json +8 -0
  60. data/spec/fixtures/schedule.json +3 -0
  61. data/spec/fixtures/sender_addresses/sender_address.json +11 -0
  62. data/spec/fixtures/sender_addresses/sender_addresses.json +11 -0
  63. data/spec/fixtures/stats.json +50 -0
  64. data/spec/fixtures/success.json +3 -0
  65. data/spec/sendgrid/api/client_spec.rb +38 -0
  66. data/spec/sendgrid/api/entities/category_spec.rb +14 -0
  67. data/spec/sendgrid/api/entities/email_spec.rb +15 -0
  68. data/spec/sendgrid/api/entities/entity_spec.rb +279 -0
  69. data/spec/sendgrid/api/entities/list_spec.rb +34 -0
  70. data/spec/sendgrid/api/entities/marketing_email_spec.rb +31 -0
  71. data/spec/sendgrid/api/entities/profile_spec.rb +26 -0
  72. data/spec/sendgrid/api/entities/response_insert_spec.rb +28 -0
  73. data/spec/sendgrid/api/entities/response_remove_spec.rb +28 -0
  74. data/spec/sendgrid/api/entities/response_spec.rb +28 -0
  75. data/spec/sendgrid/api/entities/schedule_spec.rb +14 -0
  76. data/spec/sendgrid/api/entities/sender_address_spec.rb +21 -0
  77. data/spec/sendgrid/api/entities/stats_spec.rb +25 -0
  78. data/spec/sendgrid/api/newsletter/categories_spec.rb +247 -0
  79. data/spec/sendgrid/api/newsletter/emails_spec.rb +265 -0
  80. data/spec/sendgrid/api/newsletter/lists_spec.rb +307 -0
  81. data/spec/sendgrid/api/newsletter/marketing_emails_spec.rb +306 -0
  82. data/spec/sendgrid/api/newsletter/recipients_spec.rb +252 -0
  83. data/spec/sendgrid/api/newsletter/schedule_spec.rb +263 -0
  84. data/spec/sendgrid/api/newsletter/sender_addresses_spec.rb +300 -0
  85. data/spec/sendgrid/api/rest/errors/error_spec.rb +121 -0
  86. data/spec/sendgrid/api/rest/resource_spec.rb +145 -0
  87. data/spec/sendgrid/api/rest/response/parse_error_spec.rb +39 -0
  88. data/spec/sendgrid/api/rest/response/parse_json_spec.rb +45 -0
  89. data/spec/sendgrid/api/service_spec.rb +44 -0
  90. data/spec/sendgrid/api/version_spec.rb +11 -0
  91. data/spec/sendgrid/api/web/mail_spec.rb +111 -0
  92. data/spec/sendgrid/api/web/profile_spec.rb +110 -0
  93. data/spec/sendgrid/api/web/stats_spec.rb +94 -0
  94. data/spec/spec_helper.rb +23 -0
  95. data/spec/support/helpers.rb +23 -0
  96. data/spec/support/mock.rb +30 -0
  97. data/spec/support/online.rb +114 -0
  98. data/spec/support/shared_examples.rb +104 -0
  99. metadata +225 -0
@@ -0,0 +1,3 @@
1
+ {
2
+ "date": "2013-10-30 18:01:40"
3
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "city": "Anaheim",
3
+ "name": "SendGrid",
4
+ "zip": "92806",
5
+ "replyto": "contact@sendgrid.com",
6
+ "country": "US",
7
+ "state": "CA",
8
+ "address": "1065 N Pacificenter Drive, Suite 425",
9
+ "email": "contact@sendgrid.com",
10
+ "identity": "sendgrid"
11
+ }
@@ -0,0 +1,11 @@
1
+ [
2
+ {
3
+ "identity": "sendgrid"
4
+ },
5
+ {
6
+ "identity": "sendgrid helpdesk"
7
+ },
8
+ {
9
+ "identity": "sendgrid developers"
10
+ }
11
+ ]
@@ -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,3 @@
1
+ {
2
+ "message":"success"
3
+ }
@@ -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,14 @@
1
+ require 'spec_helper'
2
+
3
+ module Sendgrid
4
+ module API
5
+ module Entities
6
+ describe Category do
7
+ subject { described_class.new }
8
+
9
+ it { should respond_to(:category) }
10
+
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ module Sendgrid
4
+ module API
5
+ module Entities
6
+ describe Email do
7
+ subject { described_class.new }
8
+
9
+ it { should respond_to(:email) }
10
+ it { should respond_to(:name) }
11
+
12
+ end
13
+ end
14
+ end
15
+ 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