Class: ExpressPigeon::Lists
- Inherits:
-
Object
- Object
- ExpressPigeon::Lists
- Includes:
- HTTMultiParty
- Defined in:
- lib/express_pigeon/lists.rb
Overview
Lists
Lists are sets of contacts a campaign can be sent to. A list consists of name, from name, reply-to fields and physical address that will be displayed in newsletter. Lists can be created, read, updated, deleted and filled up with contacts.
Note: each list has properties, including physical address. Such address is merged into footers of newsletters when campaigns are sent to a list. It allows to send to different lists of contacts and display different physical addresses at the bottom of newsletters depending which list such email was sent to. This is a useful feature for agencies who manage email marketing campaigns on behalf of their clients.
Instance Method Summary collapse
-
#create(name:, from_name:, reply_to:) ⇒ Object
Create a new list POST api.expresspigeon.com/lists.
-
#delete(list_id) ⇒ Object
Delete a list DELETE api.expresspigeon.com/lists/list_id.
-
#download_csv(list_id, download_path) ⇒ Object
Download contacts from list GET api.expresspigeon.com/lists/list_id/csv.
- #find_by_name(name) ⇒ Object
-
#index ⇒ Object
Get all lists GET api.expresspigeon.com/lists.
-
#initialize(auth_key) ⇒ Lists
constructor
A new instance of Lists.
-
#update(list_id, name: nil, from_name: nil, reply_to: nil) ⇒ Object
Update existing list PUT api.expresspigeon.com/lists.
-
#upload(list_id, path) ⇒ Object
Upload contacts to list POST api.expresspigeon.com/lists/list_id/upload.
-
#upload_status(upload_id) ⇒ Object
Check the status of list upload GET api.expresspigeon.com/lists/upload_status/upload_id.
Constructor Details
#initialize(auth_key) ⇒ Lists
Returns a new instance of Lists.
21 22 23 |
# File 'lib/express_pigeon/lists.rb', line 21 def initialize(auth_key) self.class.headers('X-auth-key' => auth_key) end |
Instance Method Details
#create(name:, from_name:, reply_to:) ⇒ Object
Create a new list POST api.expresspigeon.com/lists
name: Name of a newly created list from_name: Default “from” name used when sending campaigns to this list reply_to: Default reply To email address used when sending campaigns to this list
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/express_pigeon/lists.rb', line 31 def create(name:, from_name:, reply_to:) = { 'name' => name, 'from_name' => from_name, 'reply_to' => reply_to } self.class.post( '/', body: .to_json, headers: { 'Content-Type' => 'application/json' } ) end |
#delete(list_id) ⇒ Object
Delete a list DELETE api.expresspigeon.com/lists/list_id
77 78 79 |
# File 'lib/express_pigeon/lists.rb', line 77 def delete(list_id) self.class.delete("/#{list_id}") end |
#download_csv(list_id, download_path) ⇒ Object
Download contacts from list GET api.expresspigeon.com/lists/list_id/csv
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/express_pigeon/lists.rb', line 83 def download_csv(list_id, download_path) fail "File found at '#{download_path}' but will not overwrite." if File.exist?(download_path) response = self.class.get("/#{list_id}/csv") File.open(download_path, 'a+') do |f| f.write response.body end response end |
#find_by_name(name) ⇒ Object
57 58 59 60 61 |
# File 'lib/express_pigeon/lists.rb', line 57 def find_by_name(name) index.select do |list| list['name'] == name end end |
#index ⇒ Object
Get all lists GET api.expresspigeon.com/lists
53 54 55 |
# File 'lib/express_pigeon/lists.rb', line 53 def index self.class.get('/') end |
#update(list_id, name: nil, from_name: nil, reply_to: nil) ⇒ Object
Update existing list PUT api.expresspigeon.com/lists
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/express_pigeon/lists.rb', line 97 def update(list_id, name: nil, from_name: nil, reply_to: nil) = {} ['name'] = name unless name.nil? ['from_name'] = from_name unless from_name.nil? ['reply_to'] = reply_to unless reply_to.nil? # if we didn't provide any options then it's a NOOP return nil if .empty? ['id'] = list_id self.class.put( '/', body: .to_json, headers: { 'Content-Type' => 'application/json' } ) end |
#upload(list_id, path) ⇒ Object
Upload contacts to list POST api.expresspigeon.com/lists/list_id/upload
65 66 67 68 69 70 71 72 73 |
# File 'lib/express_pigeon/lists.rb', line 65 def upload(list_id, path) fail "No file found at '#{path}'." unless File.exist?(path) self.class.post( "/#{list_id}/upload", query: { contacts_file: File.new(path, 'r') }, detect_mime_type: true ) end |
#upload_status(upload_id) ⇒ Object
Check the status of list upload GET api.expresspigeon.com/lists/upload_status/upload_id
47 48 49 |
# File 'lib/express_pigeon/lists.rb', line 47 def upload_status(upload_id) self.class.get("/upload_status/#{upload_id}") end |