Method: Osm::Email.get_emails_for_contacts
- Defined in:
- lib/osm/email.rb
.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 |