Class: Osm::Email
- Inherits:
-
Object
- Object
- Osm::Email
- Defined in:
- lib/osm/email.rb
Defined Under Namespace
Classes: DeliveryReport
Constant Summary collapse
- TAGS =
[{id: 'FIRSTNAME', description: "Member's first name"}, {id: 'LASTNAME', description: "Member's last name"}]
Class Method Summary collapse
-
.get_emails_for_contacts(api, section, contacts, members) ⇒ Hash
Get a list of selected email address for selected members ready to pass to send_email method.
-
.send_email(api, section, send_to, cc = '', from, subject, body) ⇒ Boolean
Get a list of selected email address for selected members ready to pass to send_email method.
Class Method Details
.get_emails_for_contacts(api, section, contacts, members) ⇒ Hash
Get a list of selected email address for selected members ready to pass to send_email method
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/osm/email.rb', line 12 def self.get_emails_for_contacts(api, section, contacts, members) # Convert contacts into OSM's format contacts = [*contacts] fail ArgumentError, "You must pass at least one contact" if contacts.none? contact_group_map = { primary: '"contact_primary_1"', secondary: '"contact_primary_2"', member: '"contact_primary_member"' } contacts.map! do |contact| mapped = contact_group_map[contact] fail ArgumentError, "Invalid contact - #{contact.inspect}" if mapped.nil? mapped end # Convert member_ids to array of numbers members = [*members] fail ArgumentError, "You must pass at least one member" if members.none? members.map!{ |member| member.to_i } data = api.perform_query("/ext/members/email/?action=getSelectedEmailsFromContacts§ionid=#{section.to_i}&scouts=#{members.join(',')}", { 'contactGroups' => "[#{contacts.join(',')}]" }) if data.is_a?(Hash) data = data['emails'] return data if data.is_a?(Hash) end return false end |
.send_email(api, section, send_to, cc = '', from, subject, body) ⇒ Boolean
Get a list of selected email address for selected members ready to pass to send_email method
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/osm/email.rb', line 51 def self.send_email(api, section, send_to, cc='', from, subject, body) data = api.perform_query('ext/members/email/?action=send', { 'sectionid' => section.to_i, 'emails' => send_to.to_json, 'scouts' => send_to.keys.join(','), 'cc' => cc, 'from' => from, 'subject' => subject, 'body' => body, }) return data.is_a?(Hash) && data['ok'] end |