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


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/caboose/sns_controller.rb', line 12

def admin_add
  body = JSON.parse(request.raw_post, {symbolize_names: true})
  Caboose.log(body)
  if body && body[:Records]
    body[: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.delay(:queue => 'caboose_media', :priority => 3).process
        end
      end                  
    end
  end
  render :json => true
end

#admin_confirmObject


37
38
39
# File 'app/controllers/caboose/sns_controller.rb', line 37

def admin_confirm      
  render :json => true
end

#admin_deleteObject


47
48
49
# File 'app/controllers/caboose/sns_controller.rb', line 47

def admin_delete                        
  render :json => true
end

#admin_indexObject


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

def admin_index
  render :json => true
end

#admin_updateObject


42
43
44
# File 'app/controllers/caboose/sns_controller.rb', line 42

def admin_update
  render :json => true
end