Class: Scrunchie::Blast
- Inherits:
-
Object
- Object
- Scrunchie::Blast
- Defined in:
- lib/scrunchie.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#listname ⇒ Object
Returns the value of attribute listname.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
-
#add_contact(params = {}) ⇒ Object
Add an email already in the database to a listname.
-
#create_contact(params = {}) ⇒ Object
Create email in the database.
-
#create_list(params = {}) ⇒ Object
Create an empty list.
-
#delete_contact(params = {}) ⇒ Object
Delete email from the database.
-
#delete_list(params = {}) ⇒ Object
Delete a list, but does not remove contacts.
-
#download(format = nil) ⇒ Object
Get a CSV file containing all the contacts from @listname.
-
#get_contacts(params = {}) ⇒ Object
Get a list of emails with possible firstname and lastname attributes from the list.
-
#get_lists ⇒ Object
Returns XML message constructed as { lists: { list: [{ name: “listname”, contact: number }, { … }] }..
-
#initialize(username = nil, api_key = nil, listname = nil) ⇒ Blast
constructor
Take optional username, api_key, and listname and assign them to instance variables, or obtain those information from the environment if set.
-
#remove_contact(params = {}) ⇒ Object
Remove an email from a list, but does not delete the email.
-
#upload_contacts(params = {}) ⇒ Object
This is not tested yet.
Constructor Details
#initialize(username = nil, api_key = nil, listname = nil) ⇒ Blast
Take optional username, api_key, and listname and assign them to instance variables, or obtain those information from the environment if set.
10 11 12 13 14 15 16 |
# File 'lib/scrunchie.rb', line 10 def initialize(username=nil, api_key=nil, listname=nil) @username = username || ENV['USERNAME'] @api_key = api_key || ENV['API_KEY'] @listname = listname || "Charm" @obj = Faraday.new('https://api.elasticemail.com/lists') @auth = { username: @username, api_key: @api_key } end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
6 7 8 |
# File 'lib/scrunchie.rb', line 6 def api_key @api_key end |
#listname ⇒ Object
Returns the value of attribute listname.
6 7 8 |
# File 'lib/scrunchie.rb', line 6 def listname @listname end |
#username ⇒ Object
Returns the value of attribute username.
6 7 8 |
# File 'lib/scrunchie.rb', line 6 def username @username end |
Instance Method Details
#add_contact(params = {}) ⇒ Object
Add an email already in the database to a listname. Returns error if no email.
39 40 41 |
# File 'lib/scrunchie.rb', line 39 def add_contact(params={}) @obj.put('add-contact', @auth.merge(params)) end |
#create_contact(params = {}) ⇒ Object
Create email in the database.
19 20 21 |
# File 'lib/scrunchie.rb', line 19 def create_contact(params={}) @obj.post('create-contact', @auth.merge(params)) end |
#create_list(params = {}) ⇒ Object
Create an empty list.
29 30 31 |
# File 'lib/scrunchie.rb', line 29 def create_list(params={}) @obj.post('create-list', @auth.merge(params)) end |
#delete_contact(params = {}) ⇒ Object
Delete email from the database.
24 25 26 |
# File 'lib/scrunchie.rb', line 24 def delete_contact(params={}) @obj.delete('delete-contact', @auth.merge(params)) end |
#delete_list(params = {}) ⇒ Object
Delete a list, but does not remove contacts.
34 35 36 |
# File 'lib/scrunchie.rb', line 34 def delete_list(params={}) @obj.delete('delete', @auth.merge(params)) end |
#download(format = nil) ⇒ Object
Get a CSV file containing all the contacts from @listname.
65 66 67 68 69 70 71 |
# File 'lib/scrunchie.rb', line 65 def download(format=nil) if format == 'csv' @obj.get('download', @auth.merge(format: format)) else @obj.get('download', @auth) end end |
#get_contacts(params = {}) ⇒ Object
Get a list of emails with possible firstname and lastname attributes from the list.
60 61 62 |
# File 'lib/scrunchie.rb', line 60 def get_contacts(params={}) @obj.get('get-contacts', @auth.merge(params)) end |
#get_lists ⇒ Object
Returns XML message constructed as { lists: { list: [{ name: “listname”, contact: number }, { … }] }.
55 56 57 |
# File 'lib/scrunchie.rb', line 55 def get_lists @obj.get('get', @auth) end |
#remove_contact(params = {}) ⇒ Object
Remove an email from a list, but does not delete the email.
44 45 46 |
# File 'lib/scrunchie.rb', line 44 def remove_contact(params={}) @obj.put('remove-contact', @auth.merge(params)) end |
#upload_contacts(params = {}) ⇒ Object
This is not tested yet. Theoretically can upload a CSV of contact emails with optional fields
50 51 52 |
# File 'lib/scrunchie.rb', line 50 def upload_contacts(params={}) @obj.post('upload-contacts', @auth.merge(params)) # file: UploadIO.new(filepath, 'text/csv') end |