Class: WcoEmail::MessageStubsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/wco_email/message_stubs_controller.rb

Instance Method Summary collapse

Instance Method Details

#churnObject



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
# File 'app/controllers/wco_email/message_stubs_controller.rb', line 4

def churn
  @stub = WcoEmail::MessageStub.find params[:id]
  authorize! :churn, @stub

  if 'json' == @stub.format
    @stub.do_process_json ## postal server
  else
    @stub.do_process
  end

=begin
  # WcoEmail::MessageIntakeJob.perform_async( @stub.id.to_s )
  begin
    if 'json' == @stub.format
      @stub.do_process_json ## postal server
    else
      @stub.do_process
    end
  rescue => err
    @stub.update({ status: WcoEmail::MessageStub::STATUS_FAILED })
    puts! err, "WcoEmail::MessageIntakeJob error"
    ::ExceptionNotifier.notify_exception(
      err,
      data: { stub: @stub }
    )
  end
=end

  flash_notice "Churned 1 stub."
  redirect_to request.referrer
end

#createObject



36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/wco_email/message_stubs_controller.rb', line 36

def create
  @stub = WcoEmail::MessageStub.new params[:stub].permit!
  authorize! :create, @stub
  if @stub.save
    flash_notice 'saved.'
    redirect_to action: 'show'
  else
    flash_alert "Cannot save stub: #{@stub.errors.full_messages}"
    render 'new'
  end
end

#editObject



48
49
50
51
# File 'app/controllers/wco_email/message_stubs_controller.rb', line 48

def edit
  @stub = WcoEmail::MessageStub.find params[:id]
  authorize! :edit, @stub
end

#indexObject



53
54
55
56
57
# File 'app/controllers/wco_email/message_stubs_controller.rb', line 53

def index
  authorize! :index, WcoEmail::MessageStub
  @stubs = WcoEmail::MessageStub.all.page( params[:stubs_page] )
  render '_index_table'
end

#newObject



59
60
61
62
# File 'app/controllers/wco_email/message_stubs_controller.rb', line 59

def new
  @stub = WcoEmail::MessageStub.new
  authorize! :new, @stub
end

#showObject



64
65
66
67
68
69
70
# File 'app/controllers/wco_email/message_stubs_controller.rb', line 64

def show
  @stub = WcoEmail::MessageStub.find params[:id]
  authorize! :show, @stub

  @client ||= Aws::S3::Client.new(::SES_S3_CREDENTIALS)
  @json = JSON.parse( @client.get_object( bucket: @stub.bucket, key: @stub.object_key ).body.read )
end

#updateObject



72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/controllers/wco_email/message_stubs_controller.rb', line 72

def update
  @stub = WcoEmail::MessageStub.find params[:id]
  authorize! :update, @stub
  flag = @stub.update_attributes params[:stub].permit!
  if flag
    flash_notice 'success'
    redirect_to action: 'show'
  else
    flash_alert "Cannot save stub: #{@stub.errors.full_messages}"
    render 'edit'
  end
end