Class: Sendgrid::Subuser
- Inherits:
-
Object
- Object
- Sendgrid::Subuser
- Defined in:
- lib/sendgrid_api/subuser.rb
Instance Attribute Summary collapse
-
#activated ⇒ Object
(also: #activated?)
readonly
Returns the value of attribute activated.
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#first_name ⇒ Object
readonly
Returns the value of attribute first_name.
-
#last_name ⇒ Object
readonly
Returns the value of attribute last_name.
Class Method Summary collapse
- .all ⇒ Object
- .client ⇒ Object
- .create(attributes) ⇒ Object
- .defaults ⇒ Object
- .get(email) ⇒ Object
- .search(attributes = {}) ⇒ Object
Instance Method Summary collapse
- #activate ⇒ Object
- #deactivate ⇒ Object
-
#initialize(response = {}) ⇒ Subuser
constructor
A new instance of Subuser.
- #statistics ⇒ Object
Constructor Details
#initialize(response = {}) ⇒ Subuser
Returns a new instance of Subuser.
48 49 50 51 52 53 54 |
# File 'lib/sendgrid_api/subuser.rb', line 48 def initialize(response={}) @first_name = response["first_name"] @last_name = response["last_name"] @email = response["email"] @activated = response["active"] == "true" @errors = response["errors"] || [] end |
Instance Attribute Details
#activated ⇒ Object (readonly) Also known as: activated?
Returns the value of attribute activated.
46 47 48 |
# File 'lib/sendgrid_api/subuser.rb', line 46 def activated @activated end |
#email ⇒ Object (readonly)
Returns the value of attribute email.
46 47 48 |
# File 'lib/sendgrid_api/subuser.rb', line 46 def email @email end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
46 47 48 |
# File 'lib/sendgrid_api/subuser.rb', line 46 def errors @errors end |
#first_name ⇒ Object (readonly)
Returns the value of attribute first_name.
46 47 48 |
# File 'lib/sendgrid_api/subuser.rb', line 46 def first_name @first_name end |
#last_name ⇒ Object (readonly)
Returns the value of attribute last_name.
46 47 48 |
# File 'lib/sendgrid_api/subuser.rb', line 46 def last_name @last_name end |
Class Method Details
.all ⇒ Object
32 33 34 |
# File 'lib/sendgrid_api/subuser.rb', line 32 def self.all search end |
.client ⇒ Object
42 43 44 |
# File 'lib/sendgrid_api/subuser.rb', line 42 def self.client @client ||= Client.new(Sendgrid.api_user, Sendgrid.api_key) end |
.create(attributes) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/sendgrid_api/subuser.rb', line 17 def self.create(attributes) response = client.request("user.add", defaults.merge(attributes)) if response.errors? new(response.body) else get(attributes[:email]) end end |
.defaults ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/sendgrid_api/subuser.rb', line 3 def self.defaults { :username => "", :email => "", :first_name => "", :last_name => "", :website => "", :phone => "Unknown", :address => "Unknown", :city => "Unknown", :state => "Unknown", :country => "Unknown", :zip => "Unknown" } end |
.get(email) ⇒ Object
36 37 38 39 40 |
# File 'lib/sendgrid_api/subuser.rb', line 36 def self.get(email) return nil unless email return nil if (subusers = search("email" => email)).empty? subusers.first end |
.search(attributes = {}) ⇒ Object
26 27 28 29 30 |
# File 'lib/sendgrid_api/subuser.rb', line 26 def self.search(attributes={}) response = client.request("user.profile", attributes.merge!("task" => "get")) return [] if response.errors? response.body.collect { |subuser| new(subuser) } end |
Instance Method Details
#activate ⇒ Object
62 63 64 |
# File 'lib/sendgrid_api/subuser.rb', line 62 def activate client.request("user.enable", {"user" => email}).successful? end |
#deactivate ⇒ Object
58 59 60 |
# File 'lib/sendgrid_api/subuser.rb', line 58 def deactivate client.request("user.disable", {"user" => email}).successful? end |
#statistics ⇒ Object
66 67 68 69 |
# File 'lib/sendgrid_api/subuser.rb', line 66 def statistics response = client.request("user.stats", {"user" => email}) response.errors? ? [] : response.body end |