sendgrid_webapi 0.0.1
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.
- data/.gitignore +5 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/README.rdoc +389 -0
- data/Rakefile +5 -0
- data/lib/base.rb +41 -0
- data/lib/helper.rb +36 -0
- data/lib/middlewares/sendgrid_response.rb +42 -0
- data/lib/sendgrid_webapi.rb +5 -0
- data/lib/sub_user/apps.rb +31 -0
- data/lib/sub_user/auth.rb +10 -0
- data/lib/sub_user/bounces.rb +15 -0
- data/lib/sub_user/event_notification.rb +20 -0
- data/lib/sub_user/iframe.rb +8 -0
- data/lib/sub_user/invalid_emails.rb +15 -0
- data/lib/sub_user/ip_management.rb +23 -0
- data/lib/sub_user/limits.rb +35 -0
- data/lib/sub_user/management.rb +57 -0
- data/lib/sub_user/modules.rb +68 -0
- data/lib/sub_user/monitor_records.rb +35 -0
- data/lib/sub_user/parse.rb +20 -0
- data/lib/sub_user/spam.rb +15 -0
- data/lib/sub_user/stats.rb +8 -0
- data/lib/sub_user/unsubscribes.rb +21 -0
- data/lib/sub_user/white_label.rb +16 -0
- data/lib/subuser_client.rb +11 -0
- data/lib/web_api/blocks.rb +13 -0
- data/lib/web_api/bounces.rb +13 -0
- data/lib/web_api/event_notification.rb +18 -0
- data/lib/web_api/invalid_emails.rb +13 -0
- data/lib/web_api/mail.rb +8 -0
- data/lib/web_api/modules.rb +50 -0
- data/lib/web_api/parse.rb +18 -0
- data/lib/web_api/profile.rb +29 -0
- data/lib/web_api/spam.rb +13 -0
- data/lib/web_api/stats.rb +8 -0
- data/lib/web_api/unsubscribes.rb +18 -0
- data/lib/web_api/version.rb +3 -0
- data/lib/webapi_client.rb +12 -0
- data/sendgrid_webapi.gemspec +27 -0
- data/spec/cassettes/client/_modules/_block/should_get_block_emails.yml +48 -0
- data/spec/cassettes/client/_modules/_block/should_try_delete_not_existing_block_email.yml +49 -0
- data/spec/cassettes/client/_modules/_bounce/should_get_bounce_emails.yml +40 -0
- data/spec/cassettes/client/_modules/_bounce/should_try_delete_not_existing_bounce_email.yml +41 -0
- data/spec/cassettes/client/_modules/_event_notification/should_delete_event_notification_url.yml +49 -0
- data/spec/cassettes/client/_modules/_event_notification/should_get_event_notification_url.yml +49 -0
- data/spec/cassettes/client/_modules/_event_notification/should_set_event_notification_url.yml +49 -0
- data/spec/cassettes/client/_modules/_invalid_email/should_get_invalid_emails.yml +40 -0
- data/spec/cassettes/client/_modules/_invalid_email/should_try_delete_not_existing_invalid_emails.yml +41 -0
- data/spec/cassettes/client/_modules/_parse_email/should_delete_parse_email.yml +94 -0
- data/spec/cassettes/client/_modules/_parse_email/should_get_parse_email.yml +50 -0
- data/spec/cassettes/client/_modules/_parse_email/should_set_parse_email.yml +49 -0
- data/spec/cassettes/client/_modules/_profile/should_get_profile.yml +52 -0
- data/spec/cassettes/client/_modules/_profile/should_set_first_name.yml +144 -0
- data/spec/cassettes/client/_modules/_spam/should_get_spam_emails.yml +40 -0
- data/spec/cassettes/client/_modules/_spam/should_try_delete_not_existing_spam_emails.yml +41 -0
- data/spec/cassettes/client/_modules/_unsubscribe/should_add_unsubscribe_emails.yml +40 -0
- data/spec/cassettes/client/_modules/_unsubscribe/should_delete_unsubscribe_email.yml +40 -0
- data/spec/cassettes/client/_modules/_unsubscribe/should_get_unsubscribe_emails.yml +41 -0
- data/spec/cassettes/client/_modules/_unsubscribe/should_try_delete_not_existing_unsubscribe_emails.yml +41 -0
- data/spec/cassettes/helper/_create_sub_user_account/should_create_sub_user_account.yml +318 -0
- data/spec/cassettes/helper/_run_sendgrid_query/should_raise_with_unsucessfull_request.yml +46 -0
- data/spec/cassettes/helper/_run_sendgrid_query/should_run_sendgrid_request.yml +49 -0
- data/spec/cassettes/sub_user/_apps/should_activate_app.yml +49 -0
- data/spec/cassettes/sub_user/_apps/should_deactivate_app.yml +49 -0
- data/spec/cassettes/sub_user/_apps/should_get_current_setting_from_one_app.yml +50 -0
- data/spec/cassettes/sub_user/_apps/should_return_available_apps.yml +64 -0
- data/spec/cassettes/sub_user/_apps/should_set_current_app.yml +90 -0
- data/spec/cassettes/sub_user/_authentication/should_auth_a_sub_user.yml +49 -0
- data/spec/cassettes/sub_user/_authentication/should_return_error_with_a_bad_sub_user.yml +49 -0
- data/spec/cassettes/sub_user/_bounces/should_returns_bounce_emails.yml +48 -0
- data/spec/cassettes/sub_user/_bounces/should_tries_to_delete_unexisting_bounce_emails.yml +49 -0
- data/spec/cassettes/sub_user/_event_notification/should_add_event_notification_url.yml +49 -0
- data/spec/cassettes/sub_user/_event_notification/should_delete_event_notification_url.yml +49 -0
- data/spec/cassettes/sub_user/_event_notification/should_get_event_notification_url.yml +49 -0
- data/spec/cassettes/sub_user/_invalid_emails/should_return_invalid_emails.yml +48 -0
- data/spec/cassettes/sub_user/_invalid_emails/should_tries_to_delete_unexisting_invalid_mail.yml +49 -0
- data/spec/cassettes/sub_user/_ip_management/should_return_all_ips_available.yml +49 -0
- data/spec/cassettes/sub_user/_ip_management/should_show_ip_subuser.yml +49 -0
- data/spec/cassettes/sub_user/_limits/should_decrements_credits_for_a_sub_user.yml +95 -0
- data/spec/cassettes/sub_user/_limits/should_delete_all_limits_for_a_sub_user.yml +94 -0
- data/spec/cassettes/sub_user/_limits/should_increments_credits_for_a_sub_user.yml +95 -0
- data/spec/cassettes/sub_user/_limits/should_list_the_limits_for_a_sub_user.yml +49 -0
- data/spec/cassettes/sub_user/_limits/should_reset_all_limits_for_a_sub_user.yml +95 -0
- data/spec/cassettes/sub_user/_limits/should_returns_limits_for_a_sub_user.yml +49 -0
- data/spec/cassettes/sub_user/_limits/should_set_total_credits.yml +49 -0
- data/spec/cassettes/sub_user/_management/should_add_new_subuser.yml +49 -0
- data/spec/cassettes/sub_user/_management/should_disable_sub_user_for_send_email.yml +49 -0
- data/spec/cassettes/sub_user/_management/should_enable_sub_user_for_access_to_website.yml +49 -0
- data/spec/cassettes/sub_user/_management/should_enable_sub_user_for_send_email.yml +49 -0
- data/spec/cassettes/sub_user/_management/should_get_all_subusers.yml +54 -0
- data/spec/cassettes/sub_user/_management/should_update_sub_user.yml +49 -0
- data/spec/cassettes/sub_user/_monitor_records/should_add_existing_sub_user_to_monitor_record.yml +96 -0
- data/spec/cassettes/sub_user/_monitor_records/should_create_a_new_monitor_record.yml +96 -0
- data/spec/cassettes/sub_user/_monitor_records/should_delete_a_monitor_record.yml +94 -0
- data/spec/cassettes/sub_user/_monitor_records/should_edit_a_monitor_record.yml +96 -0
- data/spec/cassettes/sub_user/_monitor_records/should_remove_existing_sub_user_from_monitor_record.yml +96 -0
- data/spec/cassettes/sub_user/_parse_email/should_delete_parse_email.yml +94 -0
- data/spec/cassettes/sub_user/_parse_email/should_get_parse_email.yml +50 -0
- data/spec/cassettes/sub_user/_parse_email/should_set_parse_email.yml +49 -0
- data/spec/cassettes/sub_user/_spam/should_return_spam_mails.yml +48 -0
- data/spec/cassettes/sub_user/_spam/should_tries_to_delete_unexisting_spam_mail.yml +49 -0
- data/spec/cassettes/sub_user/_unsubscribes/should_add_bounce_email.yml +49 -0
- data/spec/cassettes/sub_user/_unsubscribes/should_delete_existing_bounce_email.yml +49 -0
- data/spec/cassettes/sub_user/_unsubscribes/should_delete_unexisting_bounce_email.yml +49 -0
- data/spec/cassettes/sub_user/_unsubscribes/should_returns_bounce_emails.yml +49 -0
- data/spec/client_spec.rb +132 -0
- data/spec/helper_spec.rb +47 -0
- data/spec/spec_helper.rb +13 -0
- data/spec/sub_user_spec.rb +270 -0
- metadata +290 -0
data/.rspec
ADDED
data/Gemfile
ADDED
data/README.rdoc
ADDED
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
= SendGrid WEB API gem for Rails 3 {<img src="https://secure.travis-ci.org/kylejginavan/sendgrid_webapi.png"/>}[http://travis-ci.org/kylejginavan/sendgrid_webapi]
|
|
2
|
+
|
|
3
|
+
SendGrid WEB API gem allow you to retrieve information such as statistics, bounces, spam reports, unsubscribes, send email and other information.
|
|
4
|
+
|
|
5
|
+
== Rails 3 configuration
|
|
6
|
+
|
|
7
|
+
In your Gemfile:
|
|
8
|
+
|
|
9
|
+
gem 'sendgrid_webapi'
|
|
10
|
+
|
|
11
|
+
== Usage examples
|
|
12
|
+
|
|
13
|
+
=== Creating client object:
|
|
14
|
+
|
|
15
|
+
client = SendGridWebApi::Client.new("user_name", "password")
|
|
16
|
+
|
|
17
|
+
== Modules
|
|
18
|
+
|
|
19
|
+
=== Bounces
|
|
20
|
+
This module allows you to retrieve and delete email addresses that have bounced from emails that you've delivered.
|
|
21
|
+
|
|
22
|
+
client.bounces.get(options)
|
|
23
|
+
|
|
24
|
+
client.bounces.delete(:email => "email@example.com", :foor => "bar")
|
|
25
|
+
|
|
26
|
+
* options are available here: http://docs.sendgrid.com/documentation/api/web-api/webapibounces
|
|
27
|
+
|
|
28
|
+
=== Blocks
|
|
29
|
+
This module allows you to retrieve and delete email addresses that were blocked by their ISP. These emails are not suppressed and are just for information.
|
|
30
|
+
|
|
31
|
+
client.blocks.get(options)
|
|
32
|
+
|
|
33
|
+
client.blocks.delete(:email => "email@example.com", :foor => "bar")
|
|
34
|
+
|
|
35
|
+
* options are available here: http://docs.sendgrid.com/documentation/api/web-api/webapiblocks
|
|
36
|
+
|
|
37
|
+
=== Invalid Email
|
|
38
|
+
This module allows you to retrieve and delete email addresses that you've sent to that are invalid email addresses.
|
|
39
|
+
|
|
40
|
+
client.invalid_emails.get(options)
|
|
41
|
+
|
|
42
|
+
client.invalid_emails.delete(:email => "email@example.com", :foor => "bar")
|
|
43
|
+
|
|
44
|
+
* options are available here: http://docs.sendgrid.com/documentation/api/web-api/webapiinvalidemails
|
|
45
|
+
|
|
46
|
+
=== Spam Report
|
|
47
|
+
This module allows you to retrieve and delete email addresses that have marked your emails as SPAM.
|
|
48
|
+
|
|
49
|
+
client.spam.get(options)
|
|
50
|
+
|
|
51
|
+
client.spam.delete(:email => "email@example.com", :foor => "bar")
|
|
52
|
+
|
|
53
|
+
* options are available here: http://docs.sendgrid.com/documentation/api/web-api/webapispamreports
|
|
54
|
+
|
|
55
|
+
=== Unsubscribes
|
|
56
|
+
This module allows you to add, retrieve and delete email addresses that were unsubscribed from your emails.
|
|
57
|
+
|
|
58
|
+
client.unsubscribes.add(:email => "email@example.com", :foor => "bar")
|
|
59
|
+
|
|
60
|
+
client.unsubscribes.get(options)
|
|
61
|
+
|
|
62
|
+
client.unsubscribes.delete(:email => "email@example.com", :foor => "bar")
|
|
63
|
+
|
|
64
|
+
* options are available here: http://docs.sendgrid.com/documentation/api/web-api/webapiunsubscribes
|
|
65
|
+
|
|
66
|
+
=== Parse Email
|
|
67
|
+
This module allows you to add, edit, or delete your email parse settings.
|
|
68
|
+
|
|
69
|
+
client.parse_emails.add(:hostname => "www.example.com", :url => "www.domain.com/parse.php", :spam_check => 1)
|
|
70
|
+
|
|
71
|
+
client.parse_emails.get(options)
|
|
72
|
+
|
|
73
|
+
client.parse_emails.delete(:hostname => "www.example.com")
|
|
74
|
+
|
|
75
|
+
* options are available here: http://docs.sendgrid.com/documentation/api/web-api/webapiparse
|
|
76
|
+
|
|
77
|
+
=== Event Notification URL
|
|
78
|
+
This module allows you to add, edit, or delete an event notification URL for your account.
|
|
79
|
+
|
|
80
|
+
client.event_notification.set(:url => "http://www.yourposturlhere.com")
|
|
81
|
+
|
|
82
|
+
client.event_notification.get(options)
|
|
83
|
+
|
|
84
|
+
client.event_notification.delete(options)
|
|
85
|
+
|
|
86
|
+
* options are available here: http://docs.sendgrid.com/documentation/api/web-api/event-notification-url
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
=== Stats
|
|
90
|
+
This module allows you to retrieve statistical data on a range of metrics including requests, bounces, spam reports, categories, and others.
|
|
91
|
+
|
|
92
|
+
client.stats.get(options)
|
|
93
|
+
|
|
94
|
+
* options are available here: http://docs.sendgrid.com/documentation/api/web-api/event-notification-url
|
|
95
|
+
|
|
96
|
+
=== Profile
|
|
97
|
+
This module allows you to retrieve and update your profile information such as credentials and email address.
|
|
98
|
+
|
|
99
|
+
client.profile.get(options)
|
|
100
|
+
|
|
101
|
+
client.profile.set(options)
|
|
102
|
+
|
|
103
|
+
client.profile.set_password(:password => "foo", :confirm_password => "foo")
|
|
104
|
+
|
|
105
|
+
client.profile.set_username(:username => "yournewusername@domain.com")
|
|
106
|
+
|
|
107
|
+
client.profile.set_email(:email => "yournewusername@domain.com")
|
|
108
|
+
|
|
109
|
+
* options are available here: http://docs.sendgrid.com/documentation/api/web-api/webapiprofile
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
=== Mail
|
|
113
|
+
This module allows you to send email.
|
|
114
|
+
|
|
115
|
+
client.mail.send(:to => "test@test.com", :subject => "test", :text => "some body", :from => "test@example.com")
|
|
116
|
+
|
|
117
|
+
* options are available here: http://docs.sendgrid.com/documentation/api/web-api/mail/
|
|
118
|
+
|
|
119
|
+
== SubUser
|
|
120
|
+
|
|
121
|
+
=== Creating client object:
|
|
122
|
+
|
|
123
|
+
client = SendGridWebApi::Client.new("user_name", "password")
|
|
124
|
+
|
|
125
|
+
client.sub_user
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
== Modules
|
|
129
|
+
|
|
130
|
+
=== Management SubUsers
|
|
131
|
+
Retrieve/Create/Enable/Disable your subusers. Change a subuser email address and username.
|
|
132
|
+
|
|
133
|
+
Create a sub_user
|
|
134
|
+
|
|
135
|
+
client.sub_user.management.add(:username => "sub_user", :website => "example.com", :password => "somepass", :confirm_password => "somepass", :first_name => "homero", :last_name => "simpson", :address => "555 anystreet", :city => "any city",:state => "CA", :zip => "91234", :email => "sub_user@example.com", :country => "US", :phone => "555-555")
|
|
136
|
+
|
|
137
|
+
Get sub_users list
|
|
138
|
+
|
|
139
|
+
client.sub_user.management.get
|
|
140
|
+
|
|
141
|
+
This prevents them from sending out emails with SendGrid
|
|
142
|
+
|
|
143
|
+
client.sub_user.management.disable(:user => "sub_user")
|
|
144
|
+
|
|
145
|
+
Enable a subuser so they may start sending out emails again. This call will not enable website access
|
|
146
|
+
|
|
147
|
+
client.sub_user.management.enable(:user => "sub_user")
|
|
148
|
+
|
|
149
|
+
Allow a subuser to login to the SendGrid.com website
|
|
150
|
+
|
|
151
|
+
client.sub_user.management.website_enable(:user => "sub_user")
|
|
152
|
+
|
|
153
|
+
Disable a subuser to login to the SendGrid.com website
|
|
154
|
+
|
|
155
|
+
client.sub_user.management.website_disable(:user => "sub_user")
|
|
156
|
+
|
|
157
|
+
Allows you to update your subusers profile information
|
|
158
|
+
|
|
159
|
+
client.sub_user.management.update(:user => "sub_user", :first_name => "change_named")
|
|
160
|
+
|
|
161
|
+
client.sub_user.management.update_password(:user => "sub_user", :password => "somepassword", :confirm_password => "somepassword")
|
|
162
|
+
|
|
163
|
+
client.sub_user.management.update_username(:user => "sub_user", :username => "newusername")
|
|
164
|
+
|
|
165
|
+
client.sub_user.management.update_email(:user => "sub_user", :email => "newemail")
|
|
166
|
+
|
|
167
|
+
* options are available here: http://docs.sendgrid.com/documentation/api/customer-subuser-api/customer-api/subusers/
|
|
168
|
+
|
|
169
|
+
=== Bounces
|
|
170
|
+
This module allows you to manage bounce records of your subusers.
|
|
171
|
+
|
|
172
|
+
client.sub_user.bounces.get(:user => "sub_user")
|
|
173
|
+
|
|
174
|
+
client.sub_user.bounces.delete(:user => "sub_user", :email => "email@example.com")
|
|
175
|
+
|
|
176
|
+
* options are available here: http://docs.sendgrid.com/documentation/api/customer-subuser-api/customer-subuser-api-v1/email-list-management/subuser-bounces/
|
|
177
|
+
|
|
178
|
+
=== Invalid Email
|
|
179
|
+
This module allows you to manage invalid emails of your subusers.
|
|
180
|
+
|
|
181
|
+
client.sub_user.invalid_emails.get(:user => "sub_user")
|
|
182
|
+
|
|
183
|
+
client.sub_user.invalid_emails.delete(:user => "sub_user", :email => "email@example.com")
|
|
184
|
+
|
|
185
|
+
* options are available here: http://docs.sendgrid.com/documentation/api/customer-subuser-api/customer-api/subuser-invalid-emails/
|
|
186
|
+
|
|
187
|
+
=== Spam Report
|
|
188
|
+
This module allows you to manage spam reports of your subusers.
|
|
189
|
+
|
|
190
|
+
client.sub_user.spam.get(:user => "sub_user")
|
|
191
|
+
|
|
192
|
+
client.sub_user.spam.delete(:user => "sub_user", :email => "email@example.com")
|
|
193
|
+
|
|
194
|
+
* options are available here: http://docs.sendgrid.com/documentation/api/customer-subuser-api/customer-subuser-api-v1/email-list-management/subuser-spam-reports/
|
|
195
|
+
|
|
196
|
+
=== Unsubscribes
|
|
197
|
+
This module allows you to manage unsubscribes of your subusers.
|
|
198
|
+
|
|
199
|
+
client.sub_user.unsubscribes.add(:user => "sub_user", :email => "email@example.com")
|
|
200
|
+
|
|
201
|
+
client.sub_user.unsubscribes.get(:user => "sub_user")
|
|
202
|
+
|
|
203
|
+
client.sub_user.unsubscribes.delete(:user => "sub_user", :email => "email@example.com")
|
|
204
|
+
|
|
205
|
+
* options are available here: http://docs.sendgrid.com/documentation/api/customer-subuser-api/customer-subuser-api-v1/email-list-management/subusers-unsubscribes/
|
|
206
|
+
|
|
207
|
+
=== Parse Email
|
|
208
|
+
This module allows you to setup subusers parse settings
|
|
209
|
+
|
|
210
|
+
client.sub_user.parse_emails.add(:user => "sub_user", :hostname => "www.example.com", :url => "www.domain.com/parse.php", :spam_check => 1)
|
|
211
|
+
|
|
212
|
+
client.sub_user.parse_emails.get(:user => "sub_user")
|
|
213
|
+
|
|
214
|
+
client.sub_user.parse_emails.delete(:user => "sub_user", :hostname => "www.example.com")
|
|
215
|
+
|
|
216
|
+
* options are available here: http://docs.sendgrid.com/documentation/api/customer-subuser-api/customer-api/parse-settings/
|
|
217
|
+
|
|
218
|
+
=== Event Notification URL
|
|
219
|
+
This module allows you to manage subusers event notification url.
|
|
220
|
+
|
|
221
|
+
client.sub_user.event_notification.set(:user => "sub_user", :url => "http://www.yourposturlhere.com")
|
|
222
|
+
|
|
223
|
+
client.sub_user.event_notification.get(:user => "sub_user")
|
|
224
|
+
|
|
225
|
+
client.sub_user.event_notification.delete(:user => "sub_user", :url => "http://www.yourposturlhere.com")
|
|
226
|
+
|
|
227
|
+
* options are available here: http://docs.sendgrid.com/documentation/api/customer-subuser-api/customer-api/event-notification-url/
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
=== Stats
|
|
231
|
+
This module allows you to see statistics regarding your subusers.
|
|
232
|
+
|
|
233
|
+
client.sub_user.stats.get(:user => "sub_user")
|
|
234
|
+
|
|
235
|
+
* options are available here: http://docs.sendgrid.com/documentation/api/customer-subuser-api/customer-api/statistics/
|
|
236
|
+
|
|
237
|
+
=== Limits
|
|
238
|
+
This module allows you to manage the rate of emails your subusers are able to send
|
|
239
|
+
|
|
240
|
+
client.sub_user.limits.get(:user => "sub_user")
|
|
241
|
+
|
|
242
|
+
client.sub_user.limits.set_credits(:user => "sub_user", :credits=> "200", :period=> "daily")
|
|
243
|
+
|
|
244
|
+
client.sub_user.limits.reset(:user => "sub_user", :credits=> "400", :period=> "daily")
|
|
245
|
+
|
|
246
|
+
client.sub_user.limits.increment_credits(:user => "sub_user", :credits=> "400")
|
|
247
|
+
|
|
248
|
+
client.sub_user.limits.decrement_credits(:user => "sub_user", :credits=> "400")
|
|
249
|
+
|
|
250
|
+
To remove all limits from your sub_user
|
|
251
|
+
|
|
252
|
+
client.sub_user.limits.delete(:user => "sub_user")
|
|
253
|
+
|
|
254
|
+
* options are available here: http://docs.sendgrid.com/documentation/api/customer-subuser-api/customer-api/account-limits/
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
=== Monitor Records
|
|
258
|
+
Make sure your subusers arent sending out spam by getting a sample of their outgoing messages
|
|
259
|
+
|
|
260
|
+
client.sub_user.monitor_records.create(:name => "testmonitor", :frequency => 10000, :email => "test@test.com")
|
|
261
|
+
|
|
262
|
+
client.sub_user.monitor_records.edit(:name => "testmonitor", :new_frequency => 10)
|
|
263
|
+
|
|
264
|
+
client.sub_user.monitor_records.add_user(:user => "sub_user", :name => "testmonitor")
|
|
265
|
+
|
|
266
|
+
* options are available here: http://docs.sendgrid.com/documentation/api/customer-subuser-api/customer-api/monitor-records/
|
|
267
|
+
|
|
268
|
+
=== IP Management
|
|
269
|
+
List all IP addresses you have under your account and retrieve details about them
|
|
270
|
+
|
|
271
|
+
To obtain a complete list of all IP's and which are free, taken or available. See params in the link
|
|
272
|
+
|
|
273
|
+
client.sub_user.ip_management.get(:user => "sub_user")
|
|
274
|
+
|
|
275
|
+
To get the ip that is using your sub_user
|
|
276
|
+
|
|
277
|
+
client.sub_user.ip_management.usage_ip(:user => "sub_user")
|
|
278
|
+
|
|
279
|
+
To assign one ip to your sub_user
|
|
280
|
+
|
|
281
|
+
client.sub_user.ip_management.assign_ip(:user => "sub_user", :ip => ["IP1", "IP2"])
|
|
282
|
+
|
|
283
|
+
* options are available here: http://docs.sendgrid.com/documentation/api/customer-subuser-api/customer-api/ip-management/
|
|
284
|
+
|
|
285
|
+
=== WhiteLabel
|
|
286
|
+
Manage whitelabel settings for your subusers
|
|
287
|
+
|
|
288
|
+
To retrieve a list of all whitelabel domains
|
|
289
|
+
|
|
290
|
+
client.sub_user.whitelabel.get(:user => "sub_user")
|
|
291
|
+
|
|
292
|
+
To set a subusers whitelabel domain
|
|
293
|
+
|
|
294
|
+
client.sub_user.whitelabel.add(:user => "sub_user", :mail_domain => "email.sendgrid.com")
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
* options are available here: http://docs.sendgrid.com/documentation/api/customer-subuser-api/customer-api/whitelabel/
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
=== IFrame
|
|
301
|
+
Allow users to manage your subusers via iframe using our site
|
|
302
|
+
|
|
303
|
+
client.sub_user.iframe.get(:user => "sub_user")
|
|
304
|
+
|
|
305
|
+
* options are available here: http://docs.sendgrid.com/documentation/api/customer-subuser-api/customer-api/automatic-login/
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
=== Parse Email
|
|
309
|
+
This module allows you to setup subusers parse settings.
|
|
310
|
+
|
|
311
|
+
client.sub_user.parse_emails.add(:user => "sub_user", :hostname => "www.example.com", :url => "www.domain.com/parse.php", :spam_check => 1)
|
|
312
|
+
|
|
313
|
+
client.sub_user.parse_emails.get(:user => "sub_user")
|
|
314
|
+
|
|
315
|
+
client.sub_user.parse_emails.delete(:user => "sub_user", :hostname => "www.example.com")
|
|
316
|
+
|
|
317
|
+
* options are available here: http://docs.sendgrid.com/documentation/api/customer-subuser-api/customer-api/parse-settings/
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
=== Authentication
|
|
321
|
+
This module allows you to check subusers password to see if its valid.
|
|
322
|
+
|
|
323
|
+
client.sub_user.auth.login(:user => "sub_user", :password => "somepass").
|
|
324
|
+
|
|
325
|
+
* options are available here: http://docs.sendgrid.com/documentation/api/customer-subuser-api/customer-api/authenticate-a-subuser/
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
=== Apps
|
|
329
|
+
This module allows you to setup subusers app settings.
|
|
330
|
+
|
|
331
|
+
client.sub_user.apps.list(:user => "sub_user")
|
|
332
|
+
|
|
333
|
+
client.sub_user.apps.activate(:user => "sub_user", :name => "opentrack")
|
|
334
|
+
|
|
335
|
+
client.sub_user.apps.deactivate(:user => "sub_user", :name => "opentrack")
|
|
336
|
+
|
|
337
|
+
client.sub_user.apps.current_settings(:user => "sub_user", :name => "eventnotify")
|
|
338
|
+
|
|
339
|
+
client.sub_user.apps.customize(:user => "sub_user", :name => "eventnotify", :processed => "0", :dropped => "1", :deferred => "1", :delivered => "0", :bounce => "1", :click => "1", :open => "1", :unsubscribe => "1", :spamreport => "1", :url => "http://someurl.com/listener"))
|
|
340
|
+
|
|
341
|
+
* options are available here: http://docs.sendgrid.com/documentation/api/customer-subuser-api/customer-api/filter-apps/
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
== Helper
|
|
345
|
+
|
|
346
|
+
=== Create Sub User
|
|
347
|
+
this helper allows you to create a sub_user and enable apps that you want, passing a array with the sub_user data
|
|
348
|
+
|
|
349
|
+
define the data
|
|
350
|
+
|
|
351
|
+
user_hash = {:website => "someurl.com", :password => "somepass", :confirm_password => "somepass",
|
|
352
|
+
:first_name => "home", :last_name => "simpson", :address => "555 anystreet", :city => "any city",
|
|
353
|
+
:state => "CA" , :zip => "91234", :email => "email@email.com", :country => "US", :phone => "555-555"}
|
|
354
|
+
|
|
355
|
+
apps = { :opentrack => {:name => "eventnotify", :processed => "0", :dropped => "1", :deferred => "1",
|
|
356
|
+
:delivered => "0", :bounce => "1", :click => "1", :open => "1", :unsubscribe => "1", :spamreport => "1",
|
|
357
|
+
:url => "https://agencieshq.com/sendgrid/v1/listener"},
|
|
358
|
+
:clicktrack => {:enable_text => "1"},
|
|
359
|
+
:opentrack => {}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
users = {"username" => {:account => user_hash, :applications => apps, :assigned_ips => ["IP"]}}
|
|
363
|
+
|
|
364
|
+
call the helper
|
|
365
|
+
|
|
366
|
+
create_sub_user_account("sendgrid user", "sendgrid pass", users)
|
|
367
|
+
|
|
368
|
+
=== Run SendGrid Query
|
|
369
|
+
this helper allows you run a sengrid request and raise if it doesn't return successfull
|
|
370
|
+
|
|
371
|
+
run_sendgrid_query("sendgrid user", "sendgrid pass") do
|
|
372
|
+
#some sendgrid request
|
|
373
|
+
@client.sub_user.apps.activate(:user => "user", :name => "twitter")
|
|
374
|
+
end
|
|
375
|
+
|
|
376
|
+
== HTTP Return codes
|
|
377
|
+
|
|
378
|
+
=== 4xx
|
|
379
|
+
|
|
380
|
+
The API call had an error in the parameters. The gem will return ApiException raise.
|
|
381
|
+
|
|
382
|
+
=== 5xx
|
|
383
|
+
|
|
384
|
+
The API call was unsuccessful. The gem will return ApiException raise.
|
|
385
|
+
|
|
386
|
+
== CONTRIBUTORS:
|
|
387
|
+
|
|
388
|
+
* Kyle J. Ginavan.
|
|
389
|
+
* Mauro Torres - http://github.com/chebyte
|
data/Rakefile
ADDED
data/lib/base.rb
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module SendGridWebApi
|
|
2
|
+
autoload :Faraday, 'middlewares/sendgrid_response'
|
|
3
|
+
|
|
4
|
+
class Base
|
|
5
|
+
attr_accessor :api_user, :api_key
|
|
6
|
+
|
|
7
|
+
def initialize api_user, api_key
|
|
8
|
+
@api_user = api_user
|
|
9
|
+
@api_key = api_key
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def make_request_url url, options
|
|
13
|
+
"#{url}?#{builder_options(options)}"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def builder_options options
|
|
17
|
+
options.merge!(:api_user => @api_user, :api_key => @api_key)
|
|
18
|
+
to_query(options)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def query_api url, options
|
|
22
|
+
session.get(make_request_url(url, options)).body
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def query_post_api url, options
|
|
26
|
+
builder_options(options)
|
|
27
|
+
session.post(url, builder_options(options)).body
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def to_query(options)
|
|
31
|
+
Faraday::Utils.build_nested_query(options)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def session
|
|
35
|
+
@connection ||= ::Faraday.new base_url do |conn|
|
|
36
|
+
conn.use Faraday::Response::SendGridWebApi
|
|
37
|
+
conn.adapter Faraday.default_adapter
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
data/lib/helper.rb
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module SendGridWebApi::Helper
|
|
2
|
+
extend self
|
|
3
|
+
|
|
4
|
+
def run_sendgrid_query(username, password)
|
|
5
|
+
@client = SendGridWebApi::Client.new(username, password)
|
|
6
|
+
result = yield
|
|
7
|
+
raise "it returns the following errors: #{result}" unless result.eql?({"message"=>"success"})
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
###this accepts subuser array
|
|
11
|
+
def create_sub_user_account(username, password, users)
|
|
12
|
+
users.each do |user, data|
|
|
13
|
+
#load users
|
|
14
|
+
run_sendgrid_query(username, password) do
|
|
15
|
+
@client.sub_user.management.add(data[:account].merge!(:username => user))
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
#active user for send email
|
|
19
|
+
run_sendgrid_query(username, password){@client.sub_user.management.enable(:user => user)}
|
|
20
|
+
|
|
21
|
+
#assign ip
|
|
22
|
+
unless data[:assigned_ips].empty?
|
|
23
|
+
run_sendgrid_query(username, password){@client.sub_user.ip_management.assign_ip :user => user, :ip => data[:assigned_ips]}
|
|
24
|
+
end
|
|
25
|
+
#load apps
|
|
26
|
+
unless data[:applications].empty?
|
|
27
|
+
data[:applications].each do |app_name, options|
|
|
28
|
+
run_sendgrid_query(username, password){@client.sub_user.apps.activate(:user => user, :name => app_name)}
|
|
29
|
+
unless options.empty?
|
|
30
|
+
run_sendgrid_query(username, password){@client.sub_user.apps.customize(options.merge!(:user => user, :name => app_name))}
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require 'json' unless defined?(JSON)
|
|
2
|
+
|
|
3
|
+
#api exception
|
|
4
|
+
class ApiException < StandardError;end
|
|
5
|
+
class AuthenticationError < StandardError;end
|
|
6
|
+
|
|
7
|
+
module Faraday
|
|
8
|
+
class Response::SendGridWebApi < Response::Middleware
|
|
9
|
+
|
|
10
|
+
def error_message(result)
|
|
11
|
+
if result[/^[a-z ]+$/i]
|
|
12
|
+
error_msg = result
|
|
13
|
+
else
|
|
14
|
+
error_msg = JSON.parse(result)["error"] || JSON.parse(result)["errors"]
|
|
15
|
+
end
|
|
16
|
+
error_msg.to_s
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def parse_body(body)
|
|
20
|
+
JSON.parse(body)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def check_status(env)
|
|
24
|
+
status = env[:status].to_s
|
|
25
|
+
if status == "403" || status == "401"
|
|
26
|
+
raise AuthenticationError.new(error_message(env[:body]))
|
|
27
|
+
elsif status =~ /^5/
|
|
28
|
+
raise ApiException.new("The API call was unsuccessful. You should retry later.")
|
|
29
|
+
elsif status =~ /^4/
|
|
30
|
+
raise ApiException.new(error_message(env[:body]))
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def call(env)
|
|
35
|
+
@app.call(env).on_complete do
|
|
36
|
+
check_status(env)
|
|
37
|
+
env[:body] = parse_body(env[:body])
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module SendGridWebApi::SubUserModules
|
|
2
|
+
class App < SendGridWebApi::SubUser
|
|
3
|
+
APP_URL = "apiv2/customer.apps.json"
|
|
4
|
+
|
|
5
|
+
def list options = {}
|
|
6
|
+
options.merge!({:task => "getavailable"}) unless options[:task]
|
|
7
|
+
query_api(APP_URL, options)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def activate options = {}
|
|
11
|
+
options.merge!({:task => "activate"}) unless options[:task]
|
|
12
|
+
query_api(APP_URL, options)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def deactivate options = {}
|
|
16
|
+
options.merge!({:task => "deactivate"}) unless options[:task]
|
|
17
|
+
query_api(APP_URL, options)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def current_settings options = {}
|
|
21
|
+
options.merge!({:task => "getsettings"}) unless options[:task]
|
|
22
|
+
query_api(APP_URL, options)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def customize options = {}
|
|
26
|
+
options.merge!({:task => "setup"}) unless options[:task]
|
|
27
|
+
query_post_api(APP_URL, options)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module SendGridWebApi::SubUserModules
|
|
2
|
+
class Bounce < SendGridWebApi::SubUser
|
|
3
|
+
BOUNCE_URL = "api/user.bounces.json"
|
|
4
|
+
|
|
5
|
+
def get options = {}
|
|
6
|
+
options.merge!({:task => "get"}) unless options[:task]
|
|
7
|
+
query_api(BOUNCE_URL, options)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def delete options = {}
|
|
11
|
+
options.merge!({:task => "delete"}) unless options[:task]
|
|
12
|
+
query_api(BOUNCE_URL, options)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module SendGridWebApi::SubUserModules
|
|
2
|
+
class EventNotification < SendGridWebApi::SubUser
|
|
3
|
+
EVENT_URL = "apiv2/customer.eventposturl.json"
|
|
4
|
+
|
|
5
|
+
def get options = {}
|
|
6
|
+
options.merge!({:task => "get"}) unless options[:task]
|
|
7
|
+
query_api(EVENT_URL, options)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def set options = {}
|
|
11
|
+
options.merge!({:task => "set"}) unless options[:task]
|
|
12
|
+
query_api(EVENT_URL, options)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def delete options = {}
|
|
16
|
+
options.merge!({:task => "delete"}) unless options[:task]
|
|
17
|
+
query_api(EVENT_URL, options)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module SendGridWebApi::SubUserModules
|
|
2
|
+
class InvalidEmail < SendGridWebApi::SubUser
|
|
3
|
+
INVALID_EMAILS_URL = "apiv2/customer.invalidemails.json"
|
|
4
|
+
|
|
5
|
+
def get options = {}
|
|
6
|
+
options.merge!({:task => "get"}) unless options[:task]
|
|
7
|
+
query_api(INVALID_EMAILS_URL, options)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def delete options = {}
|
|
11
|
+
options.merge!({:task => "delete"}) unless options[:task]
|
|
12
|
+
query_api(INVALID_EMAILS_URL, options)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module SendGridWebApi::SubUserModules
|
|
2
|
+
class IpManagement < SendGridWebApi::SubUser
|
|
3
|
+
def get options = {}
|
|
4
|
+
options.merge!({:list => "all"}) unless options[:list]
|
|
5
|
+
ip_management_get_url = "apiv2/customer.ip.json"
|
|
6
|
+
query_api(ip_management_get_url, options)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def usage_ip options = {}
|
|
10
|
+
options.merge!({:task => "list"}) unless options[:task]
|
|
11
|
+
ip_management_get_url = "apiv2/customer.sendip.json"
|
|
12
|
+
query_api(ip_management_get_url, options)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def assign_ip options = {}
|
|
16
|
+
options.merge!({:task => "append"}) unless options[:task]
|
|
17
|
+
options.merge!({:set => "specify"}) unless options[:set]
|
|
18
|
+
ip_management_get_url = "apiv2/customer.sendip.json"
|
|
19
|
+
query_api(ip_management_get_url, options)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
end
|