Class: Sendgrid::List
- Inherits:
-
Object
- Object
- Sendgrid::List
- Defined in:
- lib/sendgrid/list.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#recipient_count ⇒ Object
readonly
Returns the value of attribute recipient_count.
Instance Method Summary collapse
-
#add_recipient(recipient_id, list_id = nil) ⇒ void
Add a user to a list.
-
#find(id) ⇒ Hash?
find a list.
-
#initialize(data = {}) ⇒ List
constructor
A new instance of List.
Constructor Details
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
2 3 4 |
# File 'lib/sendgrid/list.rb', line 2 def errors @errors end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
2 3 4 |
# File 'lib/sendgrid/list.rb', line 2 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/sendgrid/list.rb', line 3 def name @name end |
#recipient_count ⇒ Object (readonly)
Returns the value of attribute recipient_count.
2 3 4 |
# File 'lib/sendgrid/list.rb', line 2 def recipient_count @recipient_count end |
Instance Method Details
#add_recipient(recipient_id, list_id = nil) ⇒ void
This method returns an undefined value.
Add a user to a list
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/sendgrid/list.rb', line 34 def add_recipient(recipient_id, list_id = nil) if recipient_id && (list_id || @id) list_id ||= @id response = @api.client.contactdb.lists._(list_id).recipients._(recipient_id).post() if response.status_code != "201" @errors = { status: response.status_code, body: JSON.parse(response.body)["errors"] } end end nil end |
#find(id) ⇒ Hash?
find a list
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/sendgrid/list.rb', line 15 def find(id) list = nil response = @api.client.contactdb.lists._(id).get() if response.status_code == "200" list = JSON.parse(response.body) @id = list["id"] @name = list["name"] @recipient_count = list["recipient_count"] else reset_properties @errors = { status: response.status_code, body: JSON.parse(response.body)["errors"] } end list end |