Class: Osm::Sms
- Inherits:
-
Object
- Object
- Osm::Sms
- Defined in:
- lib/osm/sms.rb
Defined Under Namespace
Classes: DeliveryReport
Class Method Summary collapse
-
.number_selected(api, section, members) ⇒ Fixnum
Get the number of SMS credits which will be used sending a message to the passed members.
-
.remaining_credits(api, section, options = {}) ⇒ Fixnum
Get the number of remaining SMS credits for a section.
-
.send_sms(api, section, members, source_address, message) ⇒ Boolean
Send an SMS to some members on their enabled numbers.
Class Method Details
.number_selected(api, section, members) ⇒ Fixnum
Get the number of SMS credits which will be used sending a message to the passed members
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/osm/sms.rb', line 59 def self.number_selected(api, section, members) Osm::Model.require_access_to_section(api, section) members = [*members] data = api.perform_query("ext/members/sms/?action=getNumbers§ionid=#{section.to_i}&type=", { 'scouts' => [*members.map{ |m| m.to_i }].join(',') }) Osm::Model.cache_write(api, ['sms_credits', section.to_i], data['sms_remaining']) return data['numbers'] end |
.remaining_credits(api, section, options = {}) ⇒ Fixnum
Get the number of remaining SMS credits for a section
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/osm/sms.rb', line 37 def self.remaining_credits(api, section, ={}) Osm::Model.require_access_to_section(api, section) cache_key = ['sms_credits', section.to_i] if ![:no_cache] && Osm::Model.cache_exist?(api, cache_key) return Osm::Model.cache_read(api, cache_key) end data = api.perform_query("ext/members/sms/?action=getNumbers§ionid=#{section.to_i}&type=", { 'scouts' => '0' }) data = data['sms_remaining'] Osm::Model.cache_write(api, cache_key, data) return data end |
.send_sms(api, section, members, source_address, message) ⇒ Boolean
Send an SMS to some members on their enabled numbers
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/osm/sms.rb', line 13 def self.send_sms(api, section, members, source_address, ) Osm::Model.require_access_to_section(api, section) raise Osm::Error, 'You do not have enough credits to send that message.' if number_selected(api, section, members) > remaining_credits(api, section) members = [*members] data = api.perform_query("ext/members/sms/?action=sendText§ionid=#{section.to_i}", { 'msg' => , 'scouts' => [*members.map{ |m| m.to_i }].join(','), 'source' => source_address, 'type' => '', }) if data.is_a?(Hash) && data['result'] Osm::Model.cache_write(api, ['sms_credits', section.to_i], data['msg'].match(/\A[^\d]*(\d+)[^\d]*\Z/)[1]) return true end return false end |