mautic 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ae603a459a430f1c56f626d53b5e124d8b8c8c7c
4
- data.tar.gz: 2fe7b84ed8f84132d9de88d087f3c19be9289d14
2
+ SHA256:
3
+ metadata.gz: 69e12653c1733475492f305f2fbb677898ac30997c8e145d9d83222890a5084b
4
+ data.tar.gz: 61448d97dd30a0b94b9f5898e64d37316176d4497f1a4bebf2da86d6b05fe830
5
5
  SHA512:
6
- metadata.gz: f8e55980f0f3f508459e071848fdb177b90a084eb7931b6c0e34a9b9fddd57ebe34c3a08aae02a2a96d247ede0dd161610c7e565b9d316823653f4f7b6746058
7
- data.tar.gz: 5505b22d15af7b959b536a1ec00e437051a4a49ac1281593bee90e3bc64cb52b9013886cd9981d5835574c07ad293d70895477649efdb105d454087e0600d78d
6
+ metadata.gz: e8a174aff3f060c0659a8ec1a2b04861ee9ddba6a246f50ae60f1e913dbcfed96263bb831d417aa143d2476933c3d3876421976270073ce56cc414543c5527af
7
+ data.tar.gz: acc8e875b58b23d8d0eba9a416fff6a3823218993162be99f2b55602c7a3d3f7d53a98818e30063703f747a1eb02f396daa4f23f452decaab5f4a8c57de2af5a
@@ -0,0 +1,118 @@
1
+ module Mautic
2
+ module ConnectionsControllerConcern
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+
7
+ before_action :set_mautic_connection, only: [:show, :edit, :update, :destroy, :oauth2, :authorize]
8
+
9
+ end
10
+
11
+
12
+ # GET /mautic_connections
13
+ def index
14
+ @mautic_connections = Mautic::Connection.order(:url)
15
+ respond_to do |format|
16
+ format.html { render layout: !request.xhr? }
17
+ format.json { render json: @mautic_connections }
18
+ end
19
+ end
20
+
21
+ # GET /mautic_connections/1
22
+ def show
23
+ respond_to do |format|
24
+ format.html { render layout: !request.xhr? }
25
+ end
26
+ end
27
+
28
+ # GET /mautic_connections/new
29
+ def new
30
+ @mautic_connection = Mautic::Connection.new
31
+ respond_to do |format|
32
+ format.html { render layout: !request.xhr? }
33
+ end
34
+ end
35
+
36
+ # GET /mautic_connections/1/edit
37
+ def edit
38
+ respond_to do |format|
39
+ format.html { render layout: !request.xhr? }
40
+ end
41
+ end
42
+
43
+ # POST /mautic_connections
44
+ def create
45
+ @mautic_connection = Mautic::Connection.new(mautic_connection_params)
46
+
47
+ respond_to do |format|
48
+ if @mautic_connection.save
49
+ format.html { render(:edit, notice: t('mautic.text_mautic_connection_created')) }
50
+ format.js { head :no_content }
51
+ format.json { render json: @mautic_connection }
52
+ else
53
+ format.html { render :new }
54
+ format.js { head :unprocessable_entity }
55
+ format.json { render json: @mautic_connection.errors, status: :unprocessable_entity }
56
+ end
57
+ end
58
+ end
59
+
60
+ # PATCH/PUT /mautic_connections/1
61
+ def update
62
+ respond_to do |format|
63
+ if @mautic_connection.update(mautic_connection_params)
64
+ format.html { redirect_to({ action: :index }, notice: t('mautic.text_mautic_connection_updated')) }
65
+ format.js { head :no_content }
66
+ format.json { render json: @mautic_connection }
67
+ else
68
+ format.html { render :edit }
69
+ format.js { head :unprocessable_entity }
70
+ format.json { render json: @mautic_connection.errors, status: :unprocessable_entity }
71
+ end
72
+ end
73
+ end
74
+
75
+ # DELETE /mautic_connections/1
76
+ def destroy
77
+ @mautic_connection.destroy
78
+ respond_to do |format|
79
+ format.html { redirect_to action: "index", notice: t('mautic.text_mautic_connection_destroyed') }
80
+ format.js { render js: "document.getElementById('#{view_context.dom_id(@mautic_connection)}').remove()" }
81
+ format.json { render json: @mautic_connection }
82
+ end
83
+ end
84
+
85
+ # ==--==--==--==--
86
+
87
+ def authorize
88
+ redirect_to @mautic_connection.authorize
89
+ end
90
+
91
+ def oauth2
92
+ begin
93
+ response = @mautic_connection.get_code(params.require(:code))
94
+ @mautic_connection.update(token: response.token, refresh_token: response.refresh_token)
95
+ return render plain: t('mautic.text_mautic_authorize_successfully')
96
+ rescue OAuth2::Error => e
97
+ flash[:error] = e.message
98
+ end
99
+
100
+ render :show
101
+ end
102
+
103
+ private
104
+
105
+ # Use callbacks to share common setup or constraints between actions.
106
+ def set_mautic_connection
107
+ @mautic_connection = Mautic::Connection.find(params[:id])
108
+ rescue ActiveRecord::RecordNotFound => e
109
+ return render head: 404, plain: e.message
110
+ end
111
+
112
+ # Only allow a trusted parameter "white list" through.
113
+ def mautic_connection_params
114
+ params.require(:connection).permit(:url, :client_id, :secret, :type)
115
+ end
116
+
117
+ end
118
+ end
@@ -1,109 +1,5 @@
1
1
  module Mautic
2
2
  class ConnectionsController < ApplicationController
3
- before_action :set_mautic_connection, only: [:show, :edit, :update, :destroy, :oauth2, :authorize]
4
-
5
- # GET /mautic_connections
6
- def index
7
- @mautic_connections = Connection.order(:url)
8
- respond_to do |format|
9
- format.html { render layout: !request.xhr? }
10
- format.json { render json: @mautic_connections }
11
- end
12
- end
13
-
14
- # GET /mautic_connections/1
15
- def show
16
- respond_to do |format|
17
- format.html { render layout: !request.xhr? }
18
- end
19
- end
20
-
21
- # GET /mautic_connections/new
22
- def new
23
- @mautic_connection = Connection.new
24
- respond_to do |format|
25
- format.html { render layout: !request.xhr? }
26
- end
27
- end
28
-
29
- # GET /mautic_connections/1/edit
30
- def edit
31
- respond_to do |format|
32
- format.html { render layout: !request.xhr? }
33
- end
34
- end
35
-
36
- # POST /mautic_connections
37
- def create
38
- @mautic_connection = Connection.new(mautic_connection_params)
39
-
40
- respond_to do |format|
41
- if @mautic_connection.save
42
- format.html { redirect_to mautic.connection_path(@mautic_connection), notice: t('mautic.text_mautic_connection_created') }
43
- format.js { head :no_content }
44
- format.json { render json: @mautic_connection }
45
- else
46
- format.html { render :new }
47
- format.js { head :unprocessable_entity }
48
- format.json { render json: @mautic_connection.errors, status: :unprocessable_entity }
49
- end
50
- end
51
- end
52
-
53
- # PATCH/PUT /mautic_connections/1
54
- def update
55
- respond_to do |format|
56
- if @mautic_connection.update(mautic_connection_params)
57
- format.html { redirect_to mautic.connection_path(@mautic_connection), notice: t('mautic.text_mautic_connection_updated') }
58
- format.js { head :no_content }
59
- format.json { render json: @mautic_connection }
60
- else
61
- format.html { render :edit }
62
- format.js { head :unprocessable_entity }
63
- format.json { render json: @mautic_connection.errors, status: :unprocessable_entity }
64
- end
65
- end
66
- end
67
-
68
- # DELETE /mautic_connections/1
69
- def destroy
70
- @mautic_connection.destroy
71
- respond_to do |format|
72
- format.html { redirect_to :connections, notice: t('mautic.text_mautic_connection_destroyed') }
73
- format.js { render js: "document.getElementById('#{view_context.dom_id(@mautic_connection)}').remove()" }
74
- format.json { render json: @mautic_connection }
75
- end
76
- end
77
-
78
- # ==--==--==--==--
79
-
80
- def authorize
81
- redirect_to @mautic_connection.authorize
82
- end
83
-
84
- def oauth2
85
- begin
86
- response = @mautic_connection.get_code(params.require(:code))
87
- @mautic_connection.update(token: response.token, refresh_token: response.refresh_token)
88
- return render plain: t('mautic.text_mautic_authorize_successfully')
89
- rescue OAuth2::Error => e
90
- flash[:error] = e.message
91
- end
92
-
93
- render :show
94
- end
95
-
96
- private
97
- # Use callbacks to share common setup or constraints between actions.
98
- def set_mautic_connection
99
- @mautic_connection = Connection.find(params[:id])
100
- rescue ActiveRecord::RecordNotFound => e
101
- return render head: 404, plain: e.message
102
- end
103
-
104
- # Only allow a trusted parameter "white list" through.
105
- def mautic_connection_params
106
- params.require(:connection).permit(:url, :client_id, :secret, :type)
107
- end
3
+ include ::Mautic::ConnectionsControllerConcern
108
4
  end
109
5
  end
@@ -3,8 +3,8 @@ module Mautic
3
3
 
4
4
  self.table_name = 'mautic_connections'
5
5
 
6
- validates :url, :client_id, :secret, presence: true
7
- validates :url, format: URI::regexp(%w(http https))
6
+ validates :url, presence: true, format: URI::regexp(%w(http https))
7
+ validates :client_id, :secret, presence: true, unless: :new_record?
8
8
 
9
9
  alias_attribute :access_token, :token
10
10
 
data/lib/mautic/model.rb CHANGED
@@ -62,7 +62,7 @@ module Mautic
62
62
 
63
63
  def create
64
64
  begin
65
- json = @connection.request(:post, "api/#{endpoint}/#{id}/new", { body: to_h })
65
+ json = @connection.request(:post, "api/#{endpoint}/#{id && "#{id}/"}new", { body: to_h })
66
66
  self.attributes = json[endpoint.singularize]
67
67
  clear_changes
68
68
  rescue ValidationError => e
@@ -1,3 +1,3 @@
1
1
  module Mautic
2
- VERSION = '0.1.6'
2
+ VERSION = '0.1.7'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mautic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lukáš Pokorný
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-26 00:00:00.000000000 Z
11
+ date: 2018-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -186,6 +186,7 @@ files:
186
186
  - app/assets/stylesheets/mautic/application.css
187
187
  - app/assets/stylesheets/mautic/mautic_connections.css
188
188
  - app/assets/stylesheets/scaffold.css
189
+ - app/controllers/concerns/mautic/connections_controller_concern.rb
189
190
  - app/controllers/mautic/application_controller.rb
190
191
  - app/controllers/mautic/connections_controller.rb
191
192
  - app/helpers/mautic/application_helper.rb
@@ -234,7 +235,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
234
235
  version: '0'
235
236
  requirements: []
236
237
  rubyforge_project:
237
- rubygems_version: 2.6.14
238
+ rubygems_version: 2.7.3
238
239
  signing_key:
239
240
  specification_version: 4
240
241
  summary: Ruby on Rails Mautic integration