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]
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 99
|
Instance Attribute Details
#credits ⇒ Fixnum
Returns thow many credits the SMS cost.
65 |
# File 'lib/osm/sms.rb', line 65 attribute :sms_id, :type => Integer |
#from_name ⇒ String
Returns the name of the person who sent the SMS.
65 |
# File 'lib/osm/sms.rb', line 65 attribute :sms_id, :type => Integer |
#from_number ⇒ String
Returns the number the SMS was ‘sent from’.
65 |
# File 'lib/osm/sms.rb', line 65 attribute :sms_id, :type => Integer |
#last_updated ⇒ DateTime
Returns when this report was last updated.
65 |
# File 'lib/osm/sms.rb', line 65 attribute :sms_id, :type => Integer |
#member_id ⇒ Fixnum
Returns the id of the member the SMS was sent to.
65 |
# File 'lib/osm/sms.rb', line 65 attribute :sms_id, :type => Integer |
#message ⇒ String
Returns the text of the SMS.
65 |
# File 'lib/osm/sms.rb', line 65 attribute :sms_id, :type => Integer |
#scheduled ⇒ DateTime
Returns when the SMS was scheduled to be sent.
65 |
# File 'lib/osm/sms.rb', line 65 attribute :sms_id, :type => Integer |
#section_id ⇒ Fixnum
Returns the id of the section ‘owning’ the SMS.
65 |
# File 'lib/osm/sms.rb', line 65 attribute :sms_id, :type => Integer |
#sms_id ⇒ Fixnum
Returns the id of the SMS.
65 |
# File 'lib/osm/sms.rb', line 65 attribute :sms_id, :type => Integer |
#status ⇒ Symbol
Returns the status of the SMS (usually :sent, :delivered, :not_delivered, :invalid_destination_address or :not_sent).
65 |
# File 'lib/osm/sms.rb', line 65 attribute :sms_id, :type => Integer |
#to_name ⇒ String
Returns the name of the person the message was sent to.
65 |
# File 'lib/osm/sms.rb', line 65 attribute :sms_id, :type => Integer |
#to_number ⇒ String
Returns the number the SMS was sent to.
65 |
# File 'lib/osm/sms.rb', line 65 attribute :sms_id, :type => Integer |
#user_id ⇒ Fixnum
Returns the id of the OSM user who sent the SMS.
65 |
# File 'lib/osm/sms.rb', line 65 attribute :sms_id, :type => Integer |
Class Method Details
.get_for_section(api, section, options = {}) ⇒ Array<Osm::Sms::DeliveryReport>
Get delivery reports
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/osm/sms.rb', line 109 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
173 174 175 176 177 |
# File 'lib/osm/sms.rb', line 173 VALID_STATUSES.each do |attribute| define_method "status_#{attribute}?" do status == attribute end end |
#status_delivered? ⇒ Boolean
Check if the SMS was delivered
173 174 175 176 177 |
# File 'lib/osm/sms.rb', line 173 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
173 174 175 176 177 |
# File 'lib/osm/sms.rb', line 173 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
173 174 175 176 177 |
# File 'lib/osm/sms.rb', line 173 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
173 174 175 176 177 |
# File 'lib/osm/sms.rb', line 173 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
173 174 175 176 177 |
# File 'lib/osm/sms.rb', line 173 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
173 174 175 176 177 |
# File 'lib/osm/sms.rb', line 173 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
173 174 175 176 177 |
# File 'lib/osm/sms.rb', line 173 VALID_STATUSES.each do |attribute| define_method "status_#{attribute}?" do status == attribute end end |
#status_sent? ⇒ Boolean
Check if the SMS was sent
173 174 175 176 177 |
# File 'lib/osm/sms.rb', line 173 VALID_STATUSES.each do |attribute| define_method "status_#{attribute}?" do status == attribute end end |