Class: Osm::Sms::DeliveryReport
Constant Summary collapse
- VALID_STATUSES =
[:sent, :not_sent, :delivered, :not_delivered, :invalid_destination_address, :invalid_source_address, :invalid_message_format, :route_not_available, :not_allowed]
Constants inherited from Model
Instance Attribute Summary collapse
-
#credits ⇒ Fixnum
Thow many credits the SMS cost.
-
#from_name ⇒ String
The name of the person who sent the SMS.
-
#from_number ⇒ String
The number the SMS was ‘sent from’.
-
#last_updated ⇒ DateTime
When this report was last updated.
-
#member_id ⇒ Fixnum
The id of the member the SMS was sent to.
-
#message ⇒ String
The text of the SMS.
-
#scheduled ⇒ DateTime
When the SMS was scheduled to be sent.
-
#section_id ⇒ Fixnum
The id of the section ‘owning’ the SMS.
-
#sms_id ⇒ Fixnum
The id of the SMS.
-
#status ⇒ Symbol
The status of the SMS (usually :sent, :delivered, :not_delivered, :invalid_destination_address or :not_sent).
-
#to_name ⇒ String
The name of the person the message was sent to.
-
#to_number ⇒ String
The number the SMS was sent to.
-
#user_id ⇒ Fixnum
The id of the OSM user who sent the SMS.
Class Method Summary collapse
-
.get_for_section(api, section, options = {}) ⇒ Array<Osm::Sms::DeliveryReport>
Get delivery reports.
Instance Method Summary collapse
-
#initialize ⇒ Object
constructor
Initialize a new Badge.
-
#route_not_available? ⇒ Boolean
Check if the SMS sending service could not route the message.
-
#status_delivered? ⇒ Boolean
Check if the SMS was delivered.
-
#status_invalid_destination_address? ⇒ Boolean
Check if the SMS had an invalid destination address.
-
#status_invalid_message_format? ⇒ Boolean
Check if the SMS message was in an invalid format.
-
#status_invalid_source_address? ⇒ Boolean
Check if the SMS had an invalid source address.
-
#status_not_allowed? ⇒ Boolean
Check if the SMS sending service refused to send the message.
-
#status_not_delivered? ⇒ Boolean
Check if the SMS was not delivered.
-
#status_not_sent? ⇒ Boolean
Check if the SMS was not sent.
-
#status_sent? ⇒ Boolean
Check if the SMS was sent.
Methods inherited from Model
#<, #<=, #<=>, #>, #>=, #between?, #changed_attributes, configure, #reset_changed_attributes, #to_i
Constructor Details
#initialize ⇒ Object
Initialize a new Badge
|
# File 'lib/osm/sms.rb', line 134
|
Instance Attribute Details
#credits ⇒ Fixnum
Returns thow many credits the SMS cost.
101 |
# File 'lib/osm/sms.rb', line 101 attribute :sms_id, :type => Integer |
#from_name ⇒ String
Returns the name of the person who sent the SMS.
101 |
# File 'lib/osm/sms.rb', line 101 attribute :sms_id, :type => Integer |
#from_number ⇒ String
Returns the number the SMS was ‘sent from’.
101 |
# File 'lib/osm/sms.rb', line 101 attribute :sms_id, :type => Integer |
#last_updated ⇒ DateTime
Returns when this report was last updated.
101 |
# File 'lib/osm/sms.rb', line 101 attribute :sms_id, :type => Integer |
#member_id ⇒ Fixnum
Returns the id of the member the SMS was sent to.
101 |
# File 'lib/osm/sms.rb', line 101 attribute :sms_id, :type => Integer |
#message ⇒ String
Returns the text of the SMS.
101 |
# File 'lib/osm/sms.rb', line 101 attribute :sms_id, :type => Integer |
#scheduled ⇒ DateTime
Returns when the SMS was scheduled to be sent.
101 |
# File 'lib/osm/sms.rb', line 101 attribute :sms_id, :type => Integer |
#section_id ⇒ Fixnum
Returns the id of the section ‘owning’ the SMS.
101 |
# File 'lib/osm/sms.rb', line 101 attribute :sms_id, :type => Integer |
#sms_id ⇒ Fixnum
Returns the id of the SMS.
101 |
# File 'lib/osm/sms.rb', line 101 attribute :sms_id, :type => Integer |
#status ⇒ Symbol
Returns the status of the SMS (usually :sent, :delivered, :not_delivered, :invalid_destination_address or :not_sent).
101 |
# File 'lib/osm/sms.rb', line 101 attribute :sms_id, :type => Integer |
#to_name ⇒ String
Returns the name of the person the message was sent to.
101 |
# File 'lib/osm/sms.rb', line 101 attribute :sms_id, :type => Integer |
#to_number ⇒ String
Returns the number the SMS was sent to.
101 |
# File 'lib/osm/sms.rb', line 101 attribute :sms_id, :type => Integer |
#user_id ⇒ Fixnum
Returns the id of the OSM user who sent the SMS.
101 |
# File 'lib/osm/sms.rb', line 101 attribute :sms_id, :type => Integer |
Class Method Details
.get_for_section(api, section, options = {}) ⇒ Array<Osm::Sms::DeliveryReport>
Get delivery reports
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/osm/sms.rb', line 144 def self.get_for_section(api, section, ={}) require_access_to_section(api, section, ) section_id = section.to_i cache_key = ['sms_delivery_reports', section_id] if ![:no_cache] && Osm::Model.cache_exist?(api, cache_key) return cache_read(api, cache_key) end reports = [] get_name_number_regex = /\A(?<name>.*\w)\W+(?<number>\d*)\Z/ data = api.perform_query("sms.php?action=deliveryReports§ionid=#{section_id}&dateFormat=generic") data['items'].each do |report| from = report['from'].match(get_name_number_regex) to = report['to'].match(get_name_number_regex) reports.push new( :sms_id => Osm.to_i_or_nil(report['smsid']), :user_id => Osm.to_i_or_nil(report['userid']), :member_id => Osm.to_i_or_nil(report['scoutid']), :section_id => Osm.to_i_or_nil(report['sectionid']), :from_name => from[:name], :from_number => "+#{from[:number]}", :to_name => to[:name], :to_number => "+#{to[:number]}", :message => report['message'], :scheduled => Osm.parse_datetime(report['schedule']), :last_updated => Osm.parse_datetime(report['lastupdated']), :credits => Osm.to_i_or_nil(report['credits']), :status => (report['status'] || 'error').downcase.to_sym, ) end cache_write(api, cache_key, reports) return reports end |
Instance Method Details
#route_not_available? ⇒ Boolean
Check if the SMS sending service could not route the message
208 209 210 211 212 |
# File 'lib/osm/sms.rb', line 208 VALID_STATUSES.each do |attribute| define_method "status_#{attribute}?" do status == attribute end end |
#status_delivered? ⇒ Boolean
Check if the SMS was delivered
208 209 210 211 212 |
# File 'lib/osm/sms.rb', line 208 VALID_STATUSES.each do |attribute| define_method "status_#{attribute}?" do status == attribute end end |
#status_invalid_destination_address? ⇒ Boolean
Check if the SMS had an invalid destination address
208 209 210 211 212 |
# File 'lib/osm/sms.rb', line 208 VALID_STATUSES.each do |attribute| define_method "status_#{attribute}?" do status == attribute end end |
#status_invalid_message_format? ⇒ Boolean
Check if the SMS message was in an invalid format
208 209 210 211 212 |
# File 'lib/osm/sms.rb', line 208 VALID_STATUSES.each do |attribute| define_method "status_#{attribute}?" do status == attribute end end |
#status_invalid_source_address? ⇒ Boolean
Check if the SMS had an invalid source address
208 209 210 211 212 |
# File 'lib/osm/sms.rb', line 208 VALID_STATUSES.each do |attribute| define_method "status_#{attribute}?" do status == attribute end end |
#status_not_allowed? ⇒ Boolean
Check if the SMS sending service refused to send the message
208 209 210 211 212 |
# File 'lib/osm/sms.rb', line 208 VALID_STATUSES.each do |attribute| define_method "status_#{attribute}?" do status == attribute end end |
#status_not_delivered? ⇒ Boolean
Check if the SMS was not delivered
208 209 210 211 212 |
# File 'lib/osm/sms.rb', line 208 VALID_STATUSES.each do |attribute| define_method "status_#{attribute}?" do status == attribute end end |
#status_not_sent? ⇒ Boolean
Check if the SMS was not sent
208 209 210 211 212 |
# File 'lib/osm/sms.rb', line 208 VALID_STATUSES.each do |attribute| define_method "status_#{attribute}?" do status == attribute end end |
#status_sent? ⇒ Boolean
Check if the SMS was sent
208 209 210 211 212 |
# File 'lib/osm/sms.rb', line 208 VALID_STATUSES.each do |attribute| define_method "status_#{attribute}?" do status == attribute end end |