action_smser 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/app/helpers/action_smser/application_helper.rb +9 -0
- data/app/models/action_smser/delivery_report.rb +3 -6
- data/app/views/action_smser/delivery_reports/index.html.erb +52 -34
- data/app/views/layouts/action_smser/delivery_reports.html.erb +6 -0
- data/lib/action_smser/base.rb +5 -1
- data/lib/action_smser/delivery_methods/nexmo.rb +21 -18
- data/lib/action_smser/version.rb +1 -1
- data/lib/action_smser.rb +1 -1
- data/test/dummy/log/test.log +9959 -0
- data/test/unit/action_smser/base_test.rb +9 -0
- data/test/unit/action_smser/delivery_methods/nexmo_test.rb +5 -8
- data/test/unit/action_smser/delivery_report_test.rb +7 -7
- metadata +7 -6
@@ -43,7 +43,8 @@ module ActionSmser
|
|
43
43
|
sms_new
|
44
44
|
end
|
45
45
|
|
46
|
-
|
46
|
+
# This updates re_delivered attribute for itself
|
47
|
+
def re_delivarable_sms(changed_delivery_options = {})
|
47
48
|
ActionSmser::Logger.info("Re_delivering: #{self.inspect}")
|
48
49
|
self.update_attribute(:re_delivered, true)
|
49
50
|
|
@@ -51,11 +52,7 @@ module ActionSmser
|
|
51
52
|
sms_new.sms_type = "#{sms_new.sms_type}.re_delivery"
|
52
53
|
sms_new.re_delivery_of_delivery_report_id = self.id
|
53
54
|
|
54
|
-
|
55
|
-
sms_new.delivery_options[:delivery_method] = gateway
|
56
|
-
end
|
57
|
-
|
58
|
-
[sms_new, sms_new.deliver]
|
55
|
+
sms_new
|
59
56
|
end
|
60
57
|
|
61
58
|
end
|
@@ -1,60 +1,78 @@
|
|
1
1
|
|
2
2
|
<%
|
3
|
-
params['time_span'] ||= 'Last
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
3
|
+
params['time_span'] ||= 'Last week'
|
4
|
+
params['redeliveries'] ||= 'Include normally'
|
5
|
+
|
6
|
+
time_span = case params['time_span'].to_s.downcase
|
7
|
+
when 'week before that'
|
8
|
+
2.weeks.ago..1.week.ago
|
9
|
+
when 'last month'
|
10
|
+
1.month.ago..10.minutes.ago
|
11
|
+
when 'last 24 hours'
|
12
|
+
1.day.ago..10.minutes.ago
|
13
|
+
when '24 hours before that'
|
14
|
+
2.days.ago..1.day.ago
|
15
|
+
else
|
16
|
+
1.week.ago..10.minutes.ago
|
17
|
+
end
|
17
18
|
|
18
19
|
ar_timespan = ActionSmser::DeliveryReport.where(:created_at => time_span)
|
19
20
|
|
20
|
-
|
21
|
+
ar_redeliveries = case params['redeliveries'].to_s.downcase
|
22
|
+
when 'ignore redeliveries'
|
23
|
+
ar_timespan.where("re_delivery_of_delivery_report_id IS NULL")
|
24
|
+
when 'only redeliveries'
|
25
|
+
ar_timespan.where("re_delivery_of_delivery_report_id IS NOT NULL")
|
26
|
+
else
|
27
|
+
ar_timespan
|
28
|
+
end
|
29
|
+
|
30
|
+
ar_gateway = ar_redeliveries
|
21
31
|
ar_gateway = ar_gateway.where(:gateway => params[:gateway]) if (params[:gateway] && params[:gateway].to_s != 'all')
|
22
32
|
|
23
33
|
%>
|
24
34
|
|
25
35
|
|
26
|
-
<h1>Delivery Reports Summary for
|
36
|
+
<h1>Delivery Reports Summary for
|
37
|
+
(<span style="font-size: smaller"><%= "#{time_span.first.to_s(:db)} => #{time_span.last.to_s(:db)}" %></span>)
|
38
|
+
<%= "for #{params[:gateway]}" unless params[:gateway].blank? %>
|
39
|
+
</h1>
|
27
40
|
|
28
|
-
<p>
|
29
|
-
Show summary
|
30
|
-
|
31
|
-
<%= link_to
|
32
|
-
|
33
|
-
<%= link_to 'Week before that', delivery_reports_path(:time_span => 'Previous Week', :gateway => params[:gateway]) %> or
|
34
|
-
<%= link_to 'Last month', delivery_reports_path(:time_span => 'Last Month', :gateway => params[:gateway]) %>.
|
41
|
+
<p class="selection_links">
|
42
|
+
<strong>Show summary:</strong>
|
43
|
+
<% ['Last 24 hours', '24 hours before that', 'Last week', 'Week before that', 'Last month'].each do |key| %>
|
44
|
+
<%= link_to key, dr_summary_url(:time_span => key), :class => (key == params['time_span'] ? 'selected' : 'not_selected') %>
|
45
|
+
<% end %>
|
35
46
|
</p>
|
36
47
|
|
37
|
-
<
|
48
|
+
<p class="selection_links">
|
49
|
+
<strong>Redeliveries:</strong>
|
50
|
+
|
51
|
+
<% ['Include normally', 'Ignore redeliveries', 'Only redeliveries'].each do |key| %>
|
52
|
+
<%= link_to key, dr_summary_url(:redeliveries => key), :class => (key == params['redeliveries'] ? 'selected' : 'not_selected') %>
|
53
|
+
<% end %>
|
54
|
+
</p>
|
38
55
|
|
39
|
-
<
|
56
|
+
<h2>Select gateway</h2>
|
57
|
+
<ul class="selection_links" style="width: 500px;">
|
40
58
|
<li>
|
41
59
|
<strong>
|
42
|
-
<%= link_to('all',
|
60
|
+
<%= link_to('all', dr_summary_url(:gateway => nil) ) %>
|
43
61
|
</strong>
|
44
62
|
|
63
|
+
<%= total = ar_redeliveries.count %> sms
|
64
|
+
|
45
65
|
(you can select only gateways that have messages in this period)
|
46
66
|
</li>
|
47
|
-
<%
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
<strong>
|
52
|
-
<%= link_to(key, delivery_reports_path(:time_span => params[:time_span], :gateway => key) ) %>
|
53
|
-
</strong>
|
67
|
+
<% ar_redeliveries.group(:gateway).count.each do |key, val| %>
|
68
|
+
<li class="<%= (key == params['gateway'] ? 'selected' : 'not_selected') -%>">
|
69
|
+
<%= link_to(key, dr_summary_url(:gateway => key) ) %>
|
70
|
+
|
54
71
|
|
55
72
|
<%= val %> sms
|
56
73
|
|
57
74
|
(<strong><%= number_to_percentage(100.0 * val / total, :precision => 2) %></strong>)
|
75
|
+
<% if params[:gateway] == key %><strong style="padding-left: 50px;">(selected)</strong><% end %>
|
58
76
|
</li>
|
59
77
|
<% end %>
|
60
78
|
</ul>
|
@@ -125,7 +143,7 @@ Show summary:
|
|
125
143
|
<td><strong><%= key %></strong></td>
|
126
144
|
<td><%= val %></td>
|
127
145
|
<td><strong><%= number_to_percentage(100.0 * val / total, :precision => 2) %></strong></td>
|
128
|
-
<td><%= sms_count =
|
146
|
+
<td><%= sms_count = ar_gateway.where(:sms_type => key).where(:status => 'delivered').count %></td>
|
129
147
|
<td><strong><%= number_to_percentage(100.0 * sms_count / val, :precision => 2) %></strong></td>
|
130
148
|
</tr>
|
131
149
|
<% end %>
|
@@ -30,6 +30,12 @@
|
|
30
30
|
}
|
31
31
|
hr { margin-top: 20px; margin-bottom: 10px; }
|
32
32
|
|
33
|
+
.selection_links { font-weight: strong; }
|
34
|
+
.selection_links a { font-size: 12px; font-weight: normal; padding-left: 10px; padding-right: 10px;}
|
35
|
+
.selection_links a.selected { font-size: 14px; font-weight: bold; color: black; }
|
36
|
+
li.selected {background-color: #ddd;}
|
37
|
+
|
38
|
+
|
33
39
|
.menu { margin-top: 30px; }
|
34
40
|
.menu a { margin-right: 20px; font-size: 16px; }
|
35
41
|
|
data/lib/action_smser/base.rb
CHANGED
@@ -40,7 +40,7 @@ class ActionSmser::Base
|
|
40
40
|
##################################################################
|
41
41
|
## INSTANCE METHODS
|
42
42
|
|
43
|
-
attr_accessor :body, :to, :from, :sms_type, :re_delivery_of_delivery_report_id
|
43
|
+
attr_accessor :body, :to, :from, :sms_type, :re_delivery_of_delivery_report_id, :ttl
|
44
44
|
|
45
45
|
# Initialized to duplicate of ActionSmser.delivery_options
|
46
46
|
attr_accessor :delivery_options
|
@@ -131,6 +131,10 @@ class ActionSmser::Base
|
|
131
131
|
from.to_s.gsub(/^(\+|0)/, "")
|
132
132
|
end
|
133
133
|
|
134
|
+
def ttl_to_i
|
135
|
+
ttl.blank? ? ActionSmser.delivery_options[:default_ttl] : ttl.to_i
|
136
|
+
end
|
137
|
+
|
134
138
|
def logger
|
135
139
|
ActionSmser::Logger
|
136
140
|
end
|
@@ -12,45 +12,48 @@ module ActionSmser::DeliveryMethods
|
|
12
12
|
logger.info "Delivering sms by https"
|
13
13
|
|
14
14
|
options = sms.delivery_options[:nexmo] || {}
|
15
|
+
options = options.dup
|
15
16
|
|
16
17
|
options[:server] = 'rest.nexmo.com'
|
17
18
|
options[:use_ssl] = true
|
18
|
-
options[:ttl] ||= 60*1000
|
19
19
|
options[:status_report_req] ||= sms.delivery_options[:save_delivery_reports]
|
20
20
|
|
21
|
-
|
21
|
+
logger.info("Nexmo delivery with #{sms.to_numbers_array.count} recipients")
|
22
|
+
to_original = sms.to
|
22
23
|
|
23
|
-
|
24
|
+
sms.delivery_info = []
|
25
|
+
delivery_reports = []
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
|
27
|
+
sms.to_numbers_array.each do |to|
|
28
|
+
deliver_path = self.deliver_path(sms, to, options)
|
29
|
+
response = self.deliver_http_request(sms, options, deliver_path)
|
28
30
|
|
29
|
-
|
31
|
+
logger.info "Nexmo delivery http ||| #{deliver_path} ||| #{response.inspect}"
|
32
|
+
logger.info response.body if !response.blank?
|
30
33
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
sms.delivery_info.push(response)
|
35
|
+
|
36
|
+
result = JSON.parse(response.body)["messages"].first
|
37
|
+
|
38
|
+
# Results include sms_id or error code in each line
|
39
|
+
if sms.delivery_options[:save_delivery_reports]
|
36
40
|
dr = ActionSmser::DeliveryReport.build_from_sms(sms, to, result["message-id"])
|
37
41
|
if result["status"].to_i > 0
|
38
42
|
dr.status = "SENT_ERROR_#{result["status"]}"
|
39
43
|
dr.log += "nexmo_error: #{result["error-text"]}"
|
40
44
|
end
|
41
45
|
dr.save
|
42
|
-
|
43
46
|
delivery_reports << dr
|
44
47
|
end
|
45
|
-
return delivery_reports
|
46
|
-
else
|
47
|
-
return results
|
48
48
|
end
|
49
49
|
|
50
|
+
sms.to = to_original
|
51
|
+
|
52
|
+
sms.delivery_options[:save_delivery_reports] ? delivery_reports : sms.delivery_info
|
50
53
|
end
|
51
54
|
|
52
|
-
def self.deliver_path(sms, options)
|
53
|
-
"/sms/json?username=#{options[:username]}&password=#{options[:password]}&ttl=#{
|
55
|
+
def self.deliver_path(sms, to, options)
|
56
|
+
"/sms/json?username=#{options[:username]}&password=#{options[:password]}&ttl=#{sms.ttl_to_i*1000}&status-report-req=#{options[:status_report_req]}&from=#{sms.from_encoded}&to=#{to}&text=#{sms.body_escaped}"
|
54
57
|
end
|
55
58
|
|
56
59
|
# Callback message status handling
|
data/lib/action_smser/version.rb
CHANGED
data/lib/action_smser.rb
CHANGED
@@ -8,7 +8,7 @@ require "action_smser/delivery_methods/nexmo"
|
|
8
8
|
module ActionSmser
|
9
9
|
|
10
10
|
mattr_accessor :delivery_options
|
11
|
-
self.delivery_options= {:delivery_method => :test_array, :save_delivery_reports => false}
|
11
|
+
self.delivery_options= {:delivery_method => :test_array, :save_delivery_reports => false, :default_ttl => (24*60*60) }
|
12
12
|
self.delivery_options[:gateway_commit] = {}
|
13
13
|
self.delivery_options[:gateway_commit_observers] = []
|
14
14
|
|