Class: Mautic::ConnectionsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/mautic/connections_controller.rb

Instance Method Summary collapse

Instance Method Details

#authorizeObject

 ==–==–==–==–



80
81
82
# File 'app/controllers/mautic/connections_controller.rb', line 80

def authorize
  redirect_to @mautic_connection.authorize
end

#createObject

POST /mautic_connections



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/mautic/connections_controller.rb', line 37

def create
  @mautic_connection = Connection.new(mautic_connection_params)

  respond_to do |format|
    if @mautic_connection.save
      format.html { redirect_to mautic.connection_path(@mautic_connection), notice: t('mautic.text_mautic_connection_created') }
      format.js { head :no_content }
      format.json { render json: @mautic_connection }
    else
      format.html { render :new }
      format.js { head :unprocessable_entity }
      format.json { render json: @mautic_connection.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /mautic_connections/1



69
70
71
72
73
74
75
76
# File 'app/controllers/mautic/connections_controller.rb', line 69

def destroy
  @mautic_connection.destroy
  respond_to do |format|
    format.html { redirect_to :connections, notice: t('mautic.text_mautic_connection_destroyed') }
    format.js { render js: "document.getElementById('#{view_context.dom_id(@mautic_connection)}').remove()" }
    format.json { render json: @mautic_connection }
  end
end

#editObject

GET /mautic_connections/1/edit



30
31
32
33
34
# File 'app/controllers/mautic/connections_controller.rb', line 30

def edit
  respond_to do |format|
    format.html { render layout: !request.xhr? }
  end
end

#indexObject

GET /mautic_connections



6
7
8
9
10
11
12
# File 'app/controllers/mautic/connections_controller.rb', line 6

def index
  @mautic_connections = Connection.order(:url)
  respond_to do |format|
    format.html { render layout: !request.xhr? }
    format.json { render json: @mautic_connections }
  end
end

#newObject

GET /mautic_connections/new



22
23
24
25
26
27
# File 'app/controllers/mautic/connections_controller.rb', line 22

def new
  @mautic_connection = Connection.new
  respond_to do |format|
    format.html { render layout: !request.xhr? }
  end
end

#oauth2Object



84
85
86
87
88
89
90
91
92
93
94
# File 'app/controllers/mautic/connections_controller.rb', line 84

def oauth2
  begin
    response = @mautic_connection.get_code(params.require(:code))
    @mautic_connection.update(token: response.token, refresh_token: response.refresh_token)
    return render plain: t('mautic.text_mautic_authorize_successfully')
  rescue OAuth2::Error => e
    flash[:error] = e.message
  end

  render :show
end

#showObject

GET /mautic_connections/1



15
16
17
18
19
# File 'app/controllers/mautic/connections_controller.rb', line 15

def show
  respond_to do |format|
    format.html { render layout: !request.xhr? }
  end
end

#updateObject

PATCH/PUT /mautic_connections/1



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/mautic/connections_controller.rb', line 54

def update
  respond_to do |format|
    if @mautic_connection.update(mautic_connection_params)
      format.html { redirect_to mautic.connection_path(@mautic_connection), notice: t('mautic.text_mautic_connection_updated') }
      format.js { head :no_content }
      format.json { render json: @mautic_connection }
    else
      format.html { render :edit }
      format.js { head :unprocessable_entity }
      format.json { render json: @mautic_connection.errors, status: :unprocessable_entity }
    end
  end
end