Class: PerfectReach::ContactList
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- PerfectReach::ContactList
- Defined in:
- lib/perfect_reach/contact_list.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_contacts(contacts, options = {}) ⇒ Object
- #contacts(options = {}) ⇒ Object
- #delete(options = {}) ⇒ Object
- #email(options = {}) ⇒ Object
- #remove_contacts(contacts, options = {}) ⇒ Object
- #statistics(options = {}) ⇒ Object
- #unsubscribe_contact(*params) ⇒ Object
- #update(options = {}) ⇒ Object
Class Method Details
.all(options = {}) ⇒ Object
59 60 61 62 63 |
# File 'lib/perfect_reach/contact_list.rb', line 59 def all( = {}) (PerfectReach::Api.instance.get('contact_lists', )["contact_lists"] || []).map do |result_hash| self.new(result_hash) end end |
.create(options = {}) ⇒ Object
53 54 55 56 57 |
# File 'lib/perfect_reach/contact_list.rb', line 53 def create( = {}) data = PerfectReach::Api.instance.post('contact_lists', ) throw data['error_msg'] unless 'ok'.eql? data['status'] self.new(.merge(:id => data["id"].to_s)) end |
Instance Method Details
#add_contacts(contacts, options = {}) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/perfect_reach/contact_list.rb', line 10 def add_contacts(contacts, ={}) throw 'Contacts must be an Array' unless contacts.is_a? Array contact_data = [] contacts.each do |p| contact_data << (p.is_a?(PerfectReach::Contact) ? {email: p.email.to_s, name: p.name.to_s} : p) end PerfectReach::Api.instance.post("contact_lists/#{self.id}/add_contacts", .reverse_merge(:contacts => contacts.to_json))["status"] end |
#contacts(options = {}) ⇒ Object
34 35 36 37 38 |
# File 'lib/perfect_reach/contact_list.rb', line 34 def contacts( = {}) PerfectReach::Api.instance.get("contact_lists/#{self.id}/contacts", )["contacts"].map do |contact| PerfectReach::Contact.new(contact) end end |
#delete(options = {}) ⇒ Object
48 49 50 |
# File 'lib/perfect_reach/contact_list.rb', line 48 def delete( = {}) PerfectReach::Api.instance.delete("contact_lists/#{self.id}", )["status"] end |
#email(options = {}) ⇒ Object
40 41 42 |
# File 'lib/perfect_reach/contact_list.rb', line 40 def email( = {}) PerfectReach::Api.instance.get("contact_lists/#{self.id}/email", )["email"] end |
#remove_contacts(contacts, options = {}) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/perfect_reach/contact_list.rb', line 25 def remove_contacts(contacts, ={}) throw 'Contacts must be an Array' unless contacts.is_a? Array contact_data = [] contacts.each do |p| contact_data << (p.is_a?(PerfectReach::Contact) ? {email: p.email.to_s, name: p.name.to_s} : p) end PerfectReach::Api.instance.delete("contact_lists/#{self.id}/remove_contacts", .reverse_merge(:contacts => contacts.to_json))["status"] end |
#statistics(options = {}) ⇒ Object
44 45 46 |
# File 'lib/perfect_reach/contact_list.rb', line 44 def statistics( = {}) PerfectReach::Api.instance.get("contact_lists/#{self.id}/statistics", )["statistics"] end |
#unsubscribe_contact(*params) ⇒ Object
19 20 21 22 23 |
# File 'lib/perfect_reach/contact_list.rb', line 19 def unsubscribe_contact(*params) = params.last.is_a?(Hash) ? params.pop : {} contact = params.map { |p| p.is_a?(PerfectReach::Contact) ? p.email.to_s : p.to_s }.reject(&:blank?).first PerfectReach::Api.instance.post("contact_lists/#{self.id}/unsubscribe_contact", .reverse_merge(:contact => contact))["status"] end |
#update(options = {}) ⇒ Object
6 7 8 |
# File 'lib/perfect_reach/contact_list.rb', line 6 def update( = {}) PerfectReach::Api.instance.put("contact_lists/#{self.id}", )["status"] end |