Class: ActionSmser::DeliveryReportsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/action_smser/delivery_reports_controller.rb

Instance Method Summary collapse

Instance Method Details

#admin_access_onlyObject



70
71
72
73
74
75
76
77
# File 'app/controllers/action_smser/delivery_reports_controller.rb', line 70

def admin_access_only
  if !ActionSmser.delivery_options[:admin_access].blank? && ActionSmser.delivery_options[:admin_access].send(:admin_access, self)
    return true
  else
    render :text => "Forbidden, only for admins", :status => 403
    return false
  end
end

#gateway_commitObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/action_smser/delivery_reports_controller.rb', line 4

def gateway_commit

  updated_count = 0

  
  if !ActionSmser.delivery_options[:gateway_commit].blank? &&
      !ActionSmser.delivery_options[:gateway_commit][params['gateway']].blank?

    ActionSmser::Logger.info("Gateway_commit found parser for gateway: #{params['gateway']}")

    dr_var_array = ActionSmser.delivery_options[:gateway_commit][params['gateway']].send(:process_delivery_report, params)
    dr_array = []

    if !dr_var_array.blank?
      dr_var_array.each do |dr_update|
        msg_id = dr_update["msg_id"]
        dr = ActionSmser::DeliveryReport.where(:msg_id => msg_id).first

        if dr
          dr_update.each_pair do |key, value|
            dr.send("#{key}=", value) if dr.attribute_names.include?(key.to_s)
          end

          if dr.save
            updated_count += 1
            dr_array << dr
            ActionSmser::Logger.info("Gateway_commit updated item with id: #{msg_id}, params: #{dr_update.inspect}")
          else
            ActionSmser::Logger.info("Gateway_commit problem updating item with id: #{msg_id}, params: #{dr_update.inspect}")
          end
        else
          ActionSmser::Logger.info("Gateway_commit not found item with id: #{msg_id}, params: #{dr_update.inspect}")
        end
      end
    end

    begin
      ActionSmser.delivery_options[:gateway_commit_observers].each do |observer|
        observer.after_gateway_commit(dr_array)
      end
    rescue Exception => e
      ActionSmser::Logger.error("Problem with gateway_commit_observers: #{e}")
    end


  end

  if updated_count > 0
    render :text => "Updated info for #{updated_count} items"
  else
    render :text => "Not saved"
  end
end

#indexObject



61
62
63
# File 'app/controllers/action_smser/delivery_reports_controller.rb', line 61

def index

end

#listObject



65
66
67
# File 'app/controllers/action_smser/delivery_reports_controller.rb', line 65

def list
  
end