Skip to content

Instantly share code, notes, and snippets.

@chebyte
Created June 28, 2012 14:15
Show Gist options
  • Save chebyte/3011623 to your computer and use it in GitHub Desktop.
Save chebyte/3011623 to your computer and use it in GitHub Desktop.
sendgrid_webapi now has sub_users supports
== SubUser
=== Creating client object:
client = SendGridWebApi::Client.new("user_name", "password")
client.sub_user
== Modules
=== Management SubUsers
Retrieve/Create/Enable/Disable your subusers. Change a subuser email address and username.
Create a sub_user
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 => "[email protected]", :country => "US", :phone => "555-555")
Get sub_users list
client.sub_user.management.get
This prevents them from sending out emails with SendGrid
client.sub_user.management.disable(:user => "sub_user")
Enable a subuser so they may start sending out emails again. This call will not enable website access
client.sub_user.management.enable(:user => "sub_user")
Allow a subuser to login to the SendGrid.com website
client.sub_user.management.website_enable(:user => "sub_user")
Disable a subuser to login to the SendGrid.com website
client.sub_user.management.website_disable(:user => "sub_user")
Allows you to update your subusers profile information
client.sub_user.management.update(:user => "sub_user", :first_name => "change_named")
client.sub_user.management.update_password(:user => "sub_user", :password => "somepassword", :confirm_password => "somepassword")
client.sub_user.management.update_username(:user => "sub_user", :username => "newusername")
client.sub_user.management.update_email(:user => "sub_user", :email => "newemail")
* options are available here: http://docs.sendgrid.com/documentation/api/customer-subuser-api/customer-api/subusers/
=== Bounces
This module allows you to manage bounce records of your subusers.
client.sub_user.bounces.get(:user => "sub_user")
client.sub_user.bounces.delete(:user => "sub_user", :email => "[email protected]")
* options are available here: http://docs.sendgrid.com/documentation/api/customer-subuser-api/customer-subuser-api-v1/email-list-management/subuser-bounces/
=== Invalid Email
This module allows you to manage invalid emails of your subusers.
client.sub_user.invalid_emails.get(:user => "sub_user")
client.sub_user.invalid_emails.delete(:user => "sub_user", :email => "[email protected]")
* options are available here: http://docs.sendgrid.com/documentation/api/customer-subuser-api/customer-api/subuser-invalid-emails/
=== Spam Report
This module allows you to manage spam reports of your subusers.
client.sub_user.spam.get(:user => "sub_user")
client.sub_user.spam.delete(:user => "sub_user", :email => "[email protected]")
* options are available here: http://docs.sendgrid.com/documentation/api/customer-subuser-api/customer-subuser-api-v1/email-list-management/subuser-spam-reports/
=== Unsubscribes
This module allows you to manage unsubscribes of your subusers.
client.sub_user.unsubscribes.add(:user => "sub_user", :email => "[email protected]")
client.sub_user.unsubscribes.get(:user => "sub_user")
client.sub_user.unsubscribes.delete(:user => "sub_user", :email => "[email protected]")
* options are available here: http://docs.sendgrid.com/documentation/api/customer-subuser-api/customer-subuser-api-v1/email-list-management/subusers-unsubscribes/
=== Parse Email
This module allows you to setup subusers parse settings
client.sub_user.parse_emails.add(:user => "sub_user", :hostname => "www.example.com", :url => "www.domain.com/parse.php", :spam_check => 1)
client.sub_user.parse_emails.get(:user => "sub_user")
client.sub_user.parse_emails.delete(:user => "sub_user", :hostname => "www.example.com")
* options are available here: http://docs.sendgrid.com/documentation/api/customer-subuser-api/customer-api/parse-settings/
=== Event Notification URL
This module allows you to manage subusers event notification url.
client.sub_user.event_notification.set(:user => "sub_user", :url => "http://www.yourposturlhere.com")
client.sub_user.event_notification.get(:user => "sub_user")
client.sub_user.event_notification.delete(:user => "sub_user", :url => "http://www.yourposturlhere.com")
* options are available here: http://docs.sendgrid.com/documentation/api/customer-subuser-api/customer-api/event-notification-url/
=== Stats
This module allows you to see statistics regarding your subusers.
client.sub_user.stats.get(:user => "sub_user")
* options are available here: http://docs.sendgrid.com/documentation/api/customer-subuser-api/customer-api/statistics/
=== Limits
This module allows you to manage the rate of emails your subusers are able to send
client.sub_user.limits.get(:user => "sub_user")
client.sub_user.limits.set_credits(:user => "sub_user", :credits=> "200", :period=> "daily")
client.sub_user.limits.reset(:user => "sub_user", :credits=> "400", :period=> "daily")
client.sub_user.limits.increment_credits(:user => "sub_user", :credits=> "400")
client.sub_user.limits.decrement_credits(:user => "sub_user", :credits=> "400")
To remove all limits from your sub_user
client.sub_user.limits.delete(:user => "sub_user")
* options are available here: http://docs.sendgrid.com/documentation/api/customer-subuser-api/customer-api/account-limits/
=== Monitor Records
Make sure your subusers arent sending out spam by getting a sample of their outgoing messages
client.sub_user.monitor_records.create(:name => "testmonitor", :frequency => 10000, :email => "[email protected]")
client.sub_user.monitor_records.edit(:name => "testmonitor", :new_frequency => 10)
client.sub_user.monitor_records.add_user(:user => "sub_user", :name => "testmonitor")
* options are available here: http://docs.sendgrid.com/documentation/api/customer-subuser-api/customer-api/monitor-records/
=== IP Management
List all IP addresses you have under your account and retrieve details about them
To obtain a complete list of all IP's and which are free, taken or available. See params in the link
client.sub_user.ip_management.get(:user => "sub_user")
To get the ip that is using your sub_user
client.sub_user.ip_management.usage_ip(:user => "sub_user")
To assign one ip to your sub_user
client.sub_user.ip_management.assign_ip(:user => "sub_user", :ip => ["IP1", "IP2"])
* options are available here: http://docs.sendgrid.com/documentation/api/customer-subuser-api/customer-api/ip-management/
=== WhiteLabel
Manage whitelabel settings for your subusers
To retrieve a list of all whitelabel domains
client.sub_user.whitelabel.get(:user => "sub_user")
To set a subusers whitelabel domain
client.sub_user.whitelabel.add(:user => "sub_user", :mail_domain => "email.sendgrid.com")
* options are available here: http://docs.sendgrid.com/documentation/api/customer-subuser-api/customer-api/whitelabel/
=== IFrame
Allow users to manage your subusers via iframe using our site
client.sub_user.iframe.get(:user => "sub_user")
* options are available here: http://docs.sendgrid.com/documentation/api/customer-subuser-api/customer-api/automatic-login/
=== Parse Email
This module allows you to setup subusers parse settings.
client.sub_user.parse_emails.add(:user => "sub_user", :hostname => "www.example.com", :url => "www.domain.com/parse.php", :spam_check => 1)
client.sub_user.parse_emails.get(:user => "sub_user")
client.sub_user.parse_emails.delete(:user => "sub_user", :hostname => "www.example.com")
* options are available here: http://docs.sendgrid.com/documentation/api/customer-subuser-api/customer-api/parse-settings/
=== Apps
This module allows you to setup subusers app settings.
client.sub_user.apps.list(:user => "sub_user")
client.sub_user.apps.activate(:user => "sub_user", :name => "opentrack")
client.sub_user.apps.deactivate(:user => "sub_user", :name => "opentrack")
client.sub_user.apps.current_settings(:user => "sub_user", :name => "eventnotify")
* options are available here: http://docs.sendgrid.com/documentation/api/customer-subuser-api/customer-api/filter-apps/
== HTTP Return codes
=== 4xx
The API call had an error in the parameters. The gem will return ApiException raise.
=== 5xx
The API call was unsuccessful. The gem will return ApiException raise.
== CONTRIBUTORS:
* Kyle J. Ginavan.
* Mauro Torres - http://github.com/chebyte
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment