Class: Caboose::SnsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/caboose/sns_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#add_ga_event, #admin_bulk_add, #admin_bulk_delete, #admin_bulk_update, #admin_edit, #admin_json, #admin_json_single, #before_action, #before_before_action, #hashify_query_string, #init_cart, #logged_in?, #logged_in_user, #login_user, #logout_user, #parse_url_params, #reject_param, #under_construction_or_forwarding_domain?, #user_is_allowed, #user_is_allowed_to, #validate_cookie, #validate_token, #var, #verify_logged_in

Instance Method Details

#admin_addObject

POST /admin/sns



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
# File 'app/controllers/caboose/sns_controller.rb', line 12

def admin_add
  body = JSON.parse(request.raw_post, {symbolize_names: true})      
  if body[:Type] && body[:Type] == "SubscriptionConfirmation"
    Caboose.log("SNS Subscription SubscribeURL\n#{body[:SubscribeURL]}")
  elsif body[:Subject] == 'Amazon S3 Notification'
    msg = JSON.parse(body[:Message])
    if msg['Records']
      msg['Records'].each do |r|
        if r['eventName'] && r['eventName'].starts_with?('ObjectCreated')          
          if r['s3'] && r['s3']['object'] && r['s3']['object']['key']
                            
            key = URI.decode(r['s3']['object']['key']).gsub('+', ' ')
            Caboose.log("Processing #{key}")

            arr = key.split('_')
            media_category_id = arr.shift
            original_name = arr.join('_')  
            name = Caboose::Media.upload_name(original_name)
                                                                  
            m = Media.where(:media_category_id => media_category_id, :original_name => original_name, :name => name).first
            m = Media.create(:media_category_id => media_category_id, :original_name => original_name, :name => name, :processed => false) if m.nil?                
            m.process
  
          end
        end                  
      end
    end
  end
  render :json => true
end

#admin_confirmObject

GET /admin/sns/confirm POST /admin/sns/confirm



45
46
47
# File 'app/controllers/caboose/sns_controller.rb', line 45

def admin_confirm      
  render :json => true
end

#admin_deleteObject

DELETE /admin/sns/:id



55
56
57
# File 'app/controllers/caboose/sns_controller.rb', line 55

def admin_delete                        
  render :json => true
end

#admin_indexObject

GET /admin/sns



7
8
9
# File 'app/controllers/caboose/sns_controller.rb', line 7

def admin_index      
  render :json => true
end

#admin_updateObject

PUT /admin/sns/:id



50
51
52
# File 'app/controllers/caboose/sns_controller.rb', line 50

def admin_update
  render :json => true
end