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,31 @@
1
+ require 'spec_helper'
2
+
3
+ module Sendgrid
4
+ module API
5
+ module Entities
6
+ describe MarketingEmail do
7
+ subject { described_class.new }
8
+
9
+ it { should respond_to(:identity) }
10
+ it { should respond_to(:name) }
11
+ it { should respond_to(:subject) }
12
+ it { should respond_to(:text) }
13
+ it { should respond_to(:html) }
14
+
15
+ it { should respond_to(:can_edit) }
16
+ it { should respond_to(:content_preview) }
17
+ it { should respond_to(:date_schedule) }
18
+ it { should respond_to(:is_deleted) }
19
+ it { should respond_to(:is_split) }
20
+ it { should respond_to(:is_winner) }
21
+ it { should respond_to(:newsletter_id) }
22
+ it { should respond_to(:nl_type) }
23
+ it { should respond_to(:timezone_id) }
24
+ it { should respond_to(:total_recipients) }
25
+ it { should respond_to(:type) }
26
+ it { should respond_to(:winner_sending_time) }
27
+
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ module Sendgrid
4
+ module API
5
+ module Entities
6
+ describe Profile do
7
+ subject { described_class.new }
8
+
9
+ it { should respond_to(:username) }
10
+ it { should respond_to(:email) }
11
+ it { should respond_to(:active) }
12
+ it { should respond_to(:first_name) }
13
+ it { should respond_to(:last_name) }
14
+ it { should respond_to(:address) }
15
+ it { should respond_to(:address2) }
16
+ it { should respond_to(:city) }
17
+ it { should respond_to(:state) }
18
+ it { should respond_to(:zip) }
19
+ it { should respond_to(:country) }
20
+ it { should respond_to(:phone) }
21
+ it { should respond_to(:website) }
22
+ it { should respond_to(:website_access) }
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ module Sendgrid
4
+ module API
5
+ module Entities
6
+ describe ResponseInsert do
7
+ subject { described_class.new }
8
+
9
+ it { should respond_to(:inserted) }
10
+
11
+ context 'with inserts' do
12
+ subject { described_class.new(:inserted => 3) }
13
+
14
+ its(:any?) { should be_true }
15
+ its(:none?) { should be_false }
16
+ end
17
+
18
+ context 'without inserts' do
19
+ subject { described_class.new(:inserted => 0) }
20
+
21
+ its(:any?) { should be_false }
22
+ its(:none?) { should be_true }
23
+ end
24
+
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ module Sendgrid
4
+ module API
5
+ module Entities
6
+ describe ResponseRemove do
7
+ subject { described_class.new }
8
+
9
+ it { should respond_to(:removed) }
10
+
11
+ context 'with removals' do
12
+ subject { described_class.new(:removed => 3) }
13
+
14
+ its(:any?) { should be_true }
15
+ its(:none?) { should be_false }
16
+ end
17
+
18
+ context 'without removals' do
19
+ subject { described_class.new(:removed => 0) }
20
+
21
+ its(:any?) { should be_false }
22
+ its(:none?) { should be_true }
23
+ end
24
+
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ module Sendgrid
4
+ module API
5
+ module Entities
6
+ describe Response do
7
+ subject { described_class.new }
8
+
9
+ it { should respond_to(:message) }
10
+ it { should respond_to(:errors) }
11
+
12
+ context 'message is true' do
13
+ subject { described_class.new(:message => 'success') }
14
+
15
+ its(:success?) { should be_true }
16
+ its(:error?) { should be_false }
17
+ end
18
+
19
+ context 'message is error' do
20
+ subject { described_class.new(:message => 'error') }
21
+
22
+ its(:success?) { should be_false }
23
+ its(:error?) { should be_true }
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ module Sendgrid
4
+ module API
5
+ module Entities
6
+ describe Schedule do
7
+ subject { described_class.new }
8
+
9
+ it { should respond_to(:date) }
10
+
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ module Sendgrid
4
+ module API
5
+ module Entities
6
+ describe SenderAddress do
7
+ subject { described_class.new }
8
+
9
+ it { should respond_to(:identity) }
10
+ it { should respond_to(:name) }
11
+ it { should respond_to(:email) }
12
+ it { should respond_to(:replyto) }
13
+ it { should respond_to(:address) }
14
+ it { should respond_to(:city) }
15
+ it { should respond_to(:state) }
16
+ it { should respond_to(:zip) }
17
+ it { should respond_to(:country) }
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ module Sendgrid
4
+ module API
5
+ module Entities
6
+ describe Stats do
7
+ subject { described_class.new }
8
+
9
+ it { should respond_to(:delivered) }
10
+ it { should respond_to(:request) }
11
+ it { should respond_to(:unique_open) }
12
+ it { should respond_to(:unique_click) }
13
+ it { should respond_to(:processed) }
14
+ it { should respond_to(:date) }
15
+ it { should respond_to(:open) }
16
+ it { should respond_to(:click) }
17
+ it { should respond_to(:blocked) }
18
+ it { should respond_to(:spamreport) }
19
+ it { should respond_to(:drop) }
20
+ it { should respond_to(:bounce) }
21
+ it { should respond_to(:deferred) }
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,247 @@
1
+ require 'spec_helper'
2
+
3
+ module Sendgrid
4
+ module API
5
+ module Newsletter
6
+ module Categories
7
+ describe Services do
8
+
9
+ subject { service }
10
+ let(:service) { described_class.new(resource) }
11
+ let(:resource) { REST::Resource.new(user, key) }
12
+ let(:user) { 'my_user' }
13
+ let(:key) { 'my_key' }
14
+ let(:sg_mock) { Sendgrid::Mock.new(user, key) }
15
+
16
+ describe '#create' do
17
+ let(:url) { 'newsletter/category/create.json' }
18
+ let(:category_name) { 'my category' }
19
+ let(:stub_post) { sg_mock.stub_post(url, :category => category_name) }
20
+ subject { service.create(category_name) }
21
+
22
+ context 'when create a category successfully' do
23
+ context 'with name' do
24
+ it_behaves_like 'a success response'
25
+ end
26
+
27
+ context 'with objects' do
28
+ let(:category) { Entities::Category.new(:category => category_name) }
29
+ subject { service.create(category) }
30
+ it_behaves_like 'a success response'
31
+ end
32
+ end
33
+
34
+ context 'when the category already exists' do
35
+ it_behaves_like 'an already exists unauthorized response'
36
+ end
37
+
38
+ context 'when permission failed' do
39
+ it_behaves_like 'a forbidden response'
40
+ end
41
+ end
42
+
43
+ describe '#add' do
44
+ let(:url) { 'newsletter/category/add.json' }
45
+ let(:category_name) { 'my category' }
46
+ let(:marketing_email_name) { 'my marketing email' }
47
+ let(:stub_post) { sg_mock.stub_post(url, :name => marketing_email_name, :category => category_name) }
48
+ subject { service.add(marketing_email_name, category_name) }
49
+
50
+ context 'when add a category successfully' do
51
+ context 'with name' do
52
+ it_behaves_like 'a success response'
53
+ end
54
+
55
+ context 'with objects' do
56
+ let(:category) { Entities::Category.new(:category => category_name) }
57
+ let(:marketing_email) { Entities::MarketingEmail.new(:name => marketing_email_name) }
58
+ subject { service.add(marketing_email, category) }
59
+ it_behaves_like 'a success response'
60
+ end
61
+ end
62
+
63
+ context 'when the marketing email does not exist' do
64
+ it_behaves_like 'a does not exist response'
65
+ end
66
+
67
+ context 'when permission failed' do
68
+ it_behaves_like 'a forbidden response'
69
+ end
70
+ end
71
+
72
+ describe '#remove' do
73
+ let(:url) { 'newsletter/category/remove.json' }
74
+ let(:category_name) { 'my category' }
75
+ let(:marketing_email_name) { 'my marketing email' }
76
+ let(:stub_post) { sg_mock.stub_post(url, :name => marketing_email_name, :category => category_name) }
77
+ subject { service.remove(marketing_email_name, category_name) }
78
+
79
+ context 'when remove a category successfully' do
80
+ context 'with name' do
81
+ it_behaves_like 'a success response'
82
+ end
83
+
84
+ context 'with objects' do
85
+ let(:category) { Entities::Category.new(:category => category_name) }
86
+ let(:marketing_email) { Entities::MarketingEmail.new(:name => marketing_email_name) }
87
+ subject { service.remove(marketing_email, category) }
88
+ it_behaves_like 'a success response'
89
+ end
90
+ end
91
+
92
+ context 'when the category does not exist' do
93
+ it_behaves_like 'a does not exist response'
94
+ end
95
+
96
+ context 'when the marketing email does not exist' do
97
+ it_behaves_like 'a does not exist response'
98
+ end
99
+
100
+ context 'when permission failed' do
101
+ it_behaves_like 'a forbidden response'
102
+ end
103
+ end
104
+
105
+ describe '#list' do
106
+ let(:url) { 'newsletter/category/list.json' }
107
+ let(:stub_post) { sg_mock.stub_post(url) }
108
+ subject { service.list }
109
+
110
+ context 'when list all categories successfully' do
111
+ before do
112
+ stub_post.to_return(:body => fixture('categories.json'))
113
+ end
114
+
115
+ it { should have(3).items }
116
+
117
+ describe 'first item' do
118
+ subject { service.list.first }
119
+ its(:category) { should == 'sendgrid' }
120
+ end
121
+ end
122
+
123
+ context 'when permission failed' do
124
+ it_behaves_like 'a forbidden response'
125
+ end
126
+ end
127
+
128
+ describe 'online tests', :online => true do
129
+ include_examples 'online tests'
130
+ let(:online) { Online.new(env_user, env_key) }
131
+ let(:category) { online.category_example }
132
+ let(:marketing_email) { online.marketing_email_example }
133
+
134
+ context 'when credentials are valid' do
135
+ before do
136
+ # try to create the test category
137
+ # note: categories can't be removed for now
138
+ begin
139
+ subject.create(category)
140
+ rescue REST::Errors::Unauthorized
141
+ # it already exists, do nothing
142
+ end
143
+ end
144
+ let(:resource) { REST::Resource.new(env_user, env_key) }
145
+
146
+ describe '#create' do
147
+ context 'when the category already exists' do
148
+ it 'raises an error' do
149
+ expect { subject.create(category) }.to raise_error(REST::Errors::Unauthorized)
150
+ end
151
+ end
152
+ end
153
+
154
+ describe '#add' do
155
+ context 'when add a category successfully' do
156
+ before do
157
+ online.add_marketing_email
158
+ end
159
+ after do
160
+ online.delete_marketing_email
161
+ end
162
+ it 'adds the category' do
163
+ subject.add(marketing_email, category).success?.should be_true
164
+ end
165
+ end
166
+
167
+ context 'when the marketing email does not exist' do
168
+ it 'raises an error' do
169
+ expect { subject.add(marketing_email, category) }.to raise_error(REST::Errors::Unauthorized)
170
+ end
171
+ end
172
+ end
173
+
174
+ describe '#remove' do
175
+ context 'when remove a category successfully' do
176
+ before do
177
+ online.add_marketing_email
178
+ subject.add(marketing_email, category)
179
+ end
180
+ after do
181
+ online.delete_marketing_email
182
+ end
183
+ it 'removes the category' do
184
+ subject.remove(marketing_email, category).success?.should be_true
185
+ end
186
+ end
187
+
188
+ context 'when the marketing email does not exist' do
189
+ it 'raises an error' do
190
+ expect { subject.remove(marketing_email, category) }.to raise_error(REST::Errors::Unauthorized)
191
+ end
192
+ end
193
+
194
+ context 'when the category does not exist' do
195
+ before do
196
+ online.add_marketing_email
197
+ end
198
+ after do
199
+ online.delete_marketing_email
200
+ end
201
+ it 'raises an error' do
202
+ expect { subject.remove(marketing_email, category) }.to raise_error(REST::Errors::Unauthorized)
203
+ end
204
+ end
205
+ end
206
+
207
+ describe '#list' do
208
+ context 'when list all categories successfully' do
209
+ it 'get all categories' do
210
+ subject.list.should_not be_empty
211
+ end
212
+ end
213
+ end
214
+ end
215
+
216
+ context 'when credentials are invalid' do
217
+ describe '#create' do
218
+ it 'raises an error' do
219
+ expect { subject.create(category) }.to raise_error(REST::Errors::Forbidden)
220
+ end
221
+ end
222
+
223
+ describe '#add' do
224
+ it 'raises an error' do
225
+ expect { subject.add(marketing_email, category) }.to raise_error(REST::Errors::Forbidden)
226
+ end
227
+ end
228
+
229
+ describe '#remove' do
230
+ it 'raises an error' do
231
+ expect { subject.remove(marketing_email, category) }.to raise_error(REST::Errors::Forbidden)
232
+ end
233
+ end
234
+
235
+ describe '#list' do
236
+ it 'raises an error' do
237
+ expect { subject.list }.to raise_error(REST::Errors::Forbidden)
238
+ end
239
+ end
240
+ end
241
+ end
242
+
243
+ end
244
+ end
245
+ end
246
+ end
247
+ end