Class: Osm::Sms::DeliveryReport

Inherits:
Model
  • Object
show all
Defined in:
lib/osm/sms.rb

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#<, #<=, #<=>, #>, #>=, #between?, #changed_attributes, configure, #reset_changed_attributes, #to_i

Constructor Details

#initializeObject

Initialize a new Badge

Parameters:

  • attributes (Hash)

    The hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)



# File 'lib/osm/sms.rb', line 99

Instance Attribute Details

#creditsFixnum

Returns thow many credits the SMS cost.

Returns:

  • (Fixnum)

    thow many credits the SMS cost



65
# File 'lib/osm/sms.rb', line 65

attribute :sms_id, :type => Integer

#from_nameString

Returns the name of the person who sent the SMS.

Returns:

  • (String)

    the name of the person who sent the SMS



65
# File 'lib/osm/sms.rb', line 65

attribute :sms_id, :type => Integer

#from_numberString

Returns the number the SMS was ‘sent from’.

Returns:

  • (String)

    the number the SMS was ‘sent from’



65
# File 'lib/osm/sms.rb', line 65

attribute :sms_id, :type => Integer

#last_updatedDateTime

Returns when this report was last updated.

Returns:

  • (DateTime)

    when this report was last updated



65
# File 'lib/osm/sms.rb', line 65

attribute :sms_id, :type => Integer

#member_idFixnum

Returns the id of the member the SMS was sent to.

Returns:

  • (Fixnum)

    the id of the member the SMS was sent to



65
# File 'lib/osm/sms.rb', line 65

attribute :sms_id, :type => Integer

#messageString

Returns the text of the SMS.

Returns:

  • (String)

    the text of the SMS



65
# File 'lib/osm/sms.rb', line 65

attribute :sms_id, :type => Integer

#scheduledDateTime

Returns when the SMS was scheduled to be sent.

Returns:

  • (DateTime)

    when the SMS was scheduled to be sent



65
# File 'lib/osm/sms.rb', line 65

attribute :sms_id, :type => Integer

#section_idFixnum

Returns the id of the section ‘owning’ the SMS.

Returns:

  • (Fixnum)

    the id of the section ‘owning’ the SMS



65
# File 'lib/osm/sms.rb', line 65

attribute :sms_id, :type => Integer

#sms_idFixnum

Returns the id of the SMS.

Returns:

  • (Fixnum)

    the id of the SMS



65
# File 'lib/osm/sms.rb', line 65

attribute :sms_id, :type => Integer

#statusSymbol

Returns the status of the SMS (usually :sent, :delivered, :not_delivered, :invalid_destination_address or :not_sent).

Returns:

  • (Symbol)

    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_nameString

Returns the name of the person the message was sent to.

Returns:

  • (String)

    the name of the person the message was sent to



65
# File 'lib/osm/sms.rb', line 65

attribute :sms_id, :type => Integer

#to_numberString

Returns the number the SMS was sent to.

Returns:

  • (String)

    the number the SMS was sent to



65
# File 'lib/osm/sms.rb', line 65

attribute :sms_id, :type => Integer

#user_idFixnum

Returns the id of the OSM user who sent the SMS.

Returns:

  • (Fixnum)

    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

Parameters:

  • api (Osm::Api)

    The api to use to make the request

  • section (Osm::Section, Fixnum, #to_i)

    The section (or its ID) to get the reports for

Returns:



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, options={})
  require_access_to_section(api, section, options)
  section_id = section.to_i
  cache_key = ['sms_delivery_reports', section_id]

  if !options[: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&sectionid=#{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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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