mautic 2.3.1 → 2.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +59 -49
- data/app/models/mautic/connection.rb +21 -18
- data/app/models/mautic/form.rb +1 -1
- data/app/views/mautic/connections/_form.html.erb +19 -13
- data/app/views/mautic/connections/edit.html.erb +0 -1
- data/lib/mautic/model.rb +32 -19
- data/lib/mautic/proxy.rb +1 -3
- data/lib/mautic/version.rb +1 -1
- metadata +17 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4499d4f66adb74f89f363f1407b0cf917728eaba2e10f9a48183a12ad14d8514
|
4
|
+
data.tar.gz: 2165001c7af680d7f3c9929a1fff7f8d463d8396d9514370f50669d59ac5dcd1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a6de50ca1f0e1b51b0e7b4a547327351c0ac984e64dd23e48e7e55d20523fa6155b1d2aa0737110878e9af8dda916e17cb40ca9b0752d4b3d79033dbd1a76cf
|
7
|
+
data.tar.gz: 8bf7ba6cbe4fe3903b09b2083dda2a9204d49ac2b0187e0bd053259c57b21db29c2aeadcacdce4261f570cd37d9b10e8dc28f6500463a75335fda29ca116b875
|
data/README.md
CHANGED
@@ -1,19 +1,66 @@
|
|
1
|
-
# Mautic rails
|
1
|
+
# Mautic rails
|
2
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/c8cd605b5e021fb841d1/maintainability)](https://codeclimate.com/github/luk4s/mautic-rails/maintainability)
|
3
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/c8cd605b5e021fb841d1/test_coverage)](https://codeclimate.com/github/luk4s/mautic-rails/test_coverage)
|
4
|
+
|
2
5
|
RoR helper / wrapper for Mautic API and forms
|
3
6
|
|
4
7
|
*Rails 4.2.8+, 5.1+ compatible*
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'mautic', '~> 2.3'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
```bash
|
18
|
+
$ bundle
|
19
|
+
```
|
20
|
+
Also you need migrate database:
|
21
|
+
```bash
|
22
|
+
$ rails db:migrate
|
23
|
+
```
|
24
|
+
|
25
|
+
## Configuration
|
26
|
+
|
27
|
+
add to `config/initializers/mautic.rb`:
|
28
|
+
```ruby
|
29
|
+
Mautic.configure do |config|
|
30
|
+
# This is for oauth handshake token url. I need to know where your app listen
|
31
|
+
config.base_url = "https://my-rails-app.com"
|
32
|
+
# OR it can be Proc
|
33
|
+
# *optional* This is your default mautic URL - used in form helper
|
34
|
+
config.mautic_url = "https://mautic.my.app"
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
add to `config/routes.rb`
|
39
|
+
```ruby
|
40
|
+
mount Mautic::Engine => "/mautic"
|
41
|
+
```
|
42
|
+
### Create mautic connection
|
16
43
|
|
44
|
+
1. In your mautic, create new
|
45
|
+
2. Got to `/your-mount-point/connections`
|
46
|
+
3. Create new connection - enter URL to your mautic
|
47
|
+
4. Copy `callback url` then go to you mautic
|
48
|
+
|
49
|
+
> In mautic you need add API oauth2 login.
|
50
|
+
|
51
|
+
> ```
|
52
|
+
> http://localhost:3000/mautic/connections/:ID/oauth2
|
53
|
+
> ```
|
54
|
+
> ID = is your Mautic::Connection ID
|
55
|
+
|
56
|
+
5. Create new **Oauth2** API connections. Use `callback url` from previous step and copy `key` and `secret` to form in your app
|
57
|
+
6. Update and use `Authorize` button for handshake
|
58
|
+
|
59
|
+
> For example of integration check https://github.com/luk4s/redmine_mautic
|
60
|
+
|
61
|
+
|
62
|
+
## Usage
|
63
|
+
|
17
64
|
Find connection which you want to use:
|
18
65
|
```ruby
|
19
66
|
m = Mautic::Connection.last
|
@@ -72,43 +119,6 @@ Receive webhook from mautic, parse it and prepare for use.
|
|
72
119
|
|
73
120
|
post "webhook/:mautic_id", action: "webhook", on: :collection
|
74
121
|
|
75
|
-
|
76
|
-
## Installation
|
77
|
-
Add this line to your application's Gemfile:
|
78
|
-
|
79
|
-
```ruby
|
80
|
-
gem 'mautic', '~>0.1'
|
81
|
-
```
|
82
|
-
|
83
|
-
And then execute:
|
84
|
-
```bash
|
85
|
-
$ bundle
|
86
|
-
```
|
87
|
-
|
88
|
-
Or install it yourself as:
|
89
|
-
```bash
|
90
|
-
$ gem install mautic
|
91
|
-
```
|
92
|
-
|
93
|
-
## Configuration
|
94
|
-
|
95
|
-
add to `config/initializers/mautic.rb`:
|
96
|
-
```ruby
|
97
|
-
Mautic.configure do |config|
|
98
|
-
# This is for oauth handshake token url. I need to know where your app listen
|
99
|
-
config.base_url = "https://my-rails-app.com"
|
100
|
-
# OR it can be Proc
|
101
|
-
# *optional* This is your default mautic URL - used in form helper
|
102
|
-
config.mautic_url = "https://mautic.my.app"
|
103
|
-
end
|
104
|
-
```
|
105
|
-
|
106
|
-
add to `config/routes.rb`
|
107
|
-
```ruby
|
108
|
-
mount Mautic::Engine => "/mautic"
|
109
|
-
|
110
|
-
```
|
111
|
-
|
112
122
|
## Contributing
|
113
123
|
Ideas and pull requests are welcome!
|
114
124
|
|
@@ -66,34 +66,37 @@ module Mautic
|
|
66
66
|
def parse_response(response)
|
67
67
|
case response.status
|
68
68
|
when 400
|
69
|
-
raise Mautic::ValidationError
|
69
|
+
raise Mautic::ValidationError, response
|
70
70
|
when 401
|
71
|
-
|
71
|
+
try_to_refresh_and_parse(response)
|
72
72
|
when 404
|
73
|
-
raise Mautic::RecordNotFound
|
73
|
+
raise Mautic::RecordNotFound, response
|
74
74
|
when 200, 201
|
75
|
-
|
76
|
-
Array(json['errors']).each do |error|
|
77
|
-
case error['code'].to_i
|
78
|
-
when 401
|
79
|
-
json = try_to_refresh_and_parse(response)
|
80
|
-
when 404
|
81
|
-
raise Mautic::RecordNotFound.new(response)
|
82
|
-
else
|
83
|
-
raise Mautic::RequestError.new(response)
|
84
|
-
end
|
85
|
-
end
|
75
|
+
handle_success_response response
|
86
76
|
else
|
87
|
-
raise Mautic::RequestError
|
77
|
+
raise Mautic::RequestError, response
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def handle_success_response(response)
|
82
|
+
json = JSON.parse(response.body) rescue {}
|
83
|
+
Array(json['errors']).each do |error|
|
84
|
+
case error['code'].to_i
|
85
|
+
when 401
|
86
|
+
json = try_to_refresh_and_parse(response)
|
87
|
+
when 404
|
88
|
+
raise Mautic::RecordNotFound, response
|
89
|
+
else
|
90
|
+
raise Mautic::RequestError, response
|
91
|
+
end
|
88
92
|
end
|
89
93
|
|
90
94
|
json
|
91
95
|
end
|
92
96
|
|
93
|
-
private
|
94
|
-
|
95
97
|
def try_to_refresh_and_parse(response)
|
96
|
-
raise Mautic::TokenExpiredError
|
98
|
+
raise Mautic::TokenExpiredError, response if @try_to_refresh
|
99
|
+
|
97
100
|
@try_to_refresh = true
|
98
101
|
refresh!
|
99
102
|
request(*@last_request)
|
data/app/models/mautic/form.rb
CHANGED
@@ -2,7 +2,7 @@ module Mautic
|
|
2
2
|
class Form < Model
|
3
3
|
|
4
4
|
def assign_attributes(source = nil)
|
5
|
-
self.attributes = {name: source['name'], fields: source['fields']} if source.is_a? Hash
|
5
|
+
self.attributes = { name: source['name'], fields: source['fields'] } if source.is_a? Hash
|
6
6
|
end
|
7
7
|
|
8
8
|
end
|
@@ -1,13 +1,13 @@
|
|
1
|
-
<%#= form_with(model: mautic_connection.becomes(Mautic::Connection), local: true) do |form| %>
|
2
1
|
<%= form_for(mautic_connection.becomes(Mautic::Connection)) do |form| %>
|
3
2
|
<% if mautic_connection.errors.any? %>
|
4
3
|
<div id="error_explanation">
|
5
|
-
<h2><%= pluralize(mautic_connection.errors.count, "error") %> prohibited this mautic_connection from being
|
4
|
+
<h2><%= pluralize(mautic_connection.errors.count, "error") %> prohibited this mautic_connection from being
|
5
|
+
saved:</h2>
|
6
6
|
|
7
7
|
<ul>
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
<% mautic_connection.errors.full_messages.each do |message| %>
|
9
|
+
<li><%= message %></li>
|
10
|
+
<% end %>
|
11
11
|
</ul>
|
12
12
|
</div>
|
13
13
|
<% end %>
|
@@ -21,17 +21,23 @@
|
|
21
21
|
<%= form.label :url %>
|
22
22
|
<%= form.text_field :url, id: :mautic_connection_url %>
|
23
23
|
</div>
|
24
|
+
<% if form.object.persisted? %>
|
25
|
+
<div class="field">
|
26
|
+
<label>Now generate pair of tokens with this callback url:</label>
|
27
|
+
<pre><%= @mautic_connection.send :callback_url %></pre>
|
28
|
+
</div>
|
24
29
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
30
|
+
<div class="field">
|
31
|
+
<%= form.label :client_id %>
|
32
|
+
<%= form.text_field :client_id, id: :mautic_connection_client_id %>
|
33
|
+
</div>
|
29
34
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
35
|
+
<div class="field">
|
36
|
+
<%= form.label :secret %>
|
37
|
+
<%= form.text_field :secret, id: :mautic_connection_secret %>
|
38
|
+
</div>
|
34
39
|
|
40
|
+
<% end %>
|
35
41
|
<div class="actions">
|
36
42
|
<%= form.submit %>
|
37
43
|
</div>
|
data/lib/mautic/model.rb
CHANGED
@@ -40,7 +40,7 @@ module Mautic
|
|
40
40
|
attr_reader :connection
|
41
41
|
|
42
42
|
# @param [Mautic::Connection] connection
|
43
|
-
def initialize(connection, hash=nil)
|
43
|
+
def initialize(connection, hash = nil)
|
44
44
|
@connection = connection
|
45
45
|
@table = MauticHash.new
|
46
46
|
self.attributes = { id: hash['id'], created_at: hash['dateAdded']&.to_time, updated_at: hash['dateModified']&.to_time } if hash
|
@@ -59,7 +59,7 @@ module Mautic
|
|
59
59
|
def update(force = false)
|
60
60
|
return false if changes.blank?
|
61
61
|
begin
|
62
|
-
json = @connection.request((force && :put || :patch), "api/#{endpoint}/#{id}/edit", { body:
|
62
|
+
json = @connection.request((force && :put || :patch), "api/#{endpoint}/#{id}/edit", { body: to_mautic })
|
63
63
|
self.attributes = json[endpoint.singularize]
|
64
64
|
clear_changes
|
65
65
|
rescue ValidationError => e
|
@@ -71,7 +71,7 @@ module Mautic
|
|
71
71
|
|
72
72
|
def create
|
73
73
|
begin
|
74
|
-
json = @connection.request(:post, "api/#{endpoint}/#{id && "#{id}/"}new", { body:
|
74
|
+
json = @connection.request(:post, "api/#{endpoint}/#{id && "#{id}/"}new", { body: to_mautic })
|
75
75
|
self.attributes = json[endpoint.singularize]
|
76
76
|
clear_changes
|
77
77
|
rescue ValidationError => e
|
@@ -106,6 +106,12 @@ module Mautic
|
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
|
+
def to_mautic
|
110
|
+
@table.each_with_object({}) do |(key,val), mem|
|
111
|
+
mem[key] = val.is_a?(Array) ? val.join("|") : val
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
109
115
|
private
|
110
116
|
|
111
117
|
def clear_changes
|
@@ -119,27 +125,34 @@ module Mautic
|
|
119
125
|
def assign_attributes(source = nil)
|
120
126
|
@mautic_attributes = []
|
121
127
|
source ||= {}
|
128
|
+
|
129
|
+
data = if (fields = source['fields'])
|
130
|
+
attributes_from_fields(fields)
|
131
|
+
elsif source
|
132
|
+
source
|
133
|
+
end
|
134
|
+
self.attributes = data
|
135
|
+
end
|
136
|
+
|
137
|
+
def attributes_from_fields(fields)
|
122
138
|
data = {}
|
139
|
+
if fields['all']
|
140
|
+
@mautic_attributes = fields['all'].collect do |key, value|
|
141
|
+
data[key] = value
|
142
|
+
Attribute.new(alias: key, value: value)
|
143
|
+
end
|
144
|
+
else
|
145
|
+
fields.each do |_group, pairs|
|
146
|
+
next unless pairs.is_a?(Hash)
|
123
147
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
data[key] = value
|
128
|
-
Attribute.new(alias: key, value: value)
|
129
|
-
end
|
130
|
-
else
|
131
|
-
fields.each do |_group, pairs|
|
132
|
-
next unless pairs.is_a?(Hash)
|
133
|
-
pairs.each do |key, attrs|
|
134
|
-
@mautic_attributes << (a = Attribute.new(attrs))
|
135
|
-
data[key] = a.value
|
136
|
-
end
|
148
|
+
pairs.each do |key, attrs|
|
149
|
+
@mautic_attributes << (a = Attribute.new(attrs))
|
150
|
+
data[key] = a.value
|
137
151
|
end
|
138
152
|
end
|
139
|
-
elsif source
|
140
|
-
data = source
|
141
153
|
end
|
142
|
-
|
154
|
+
|
155
|
+
data
|
143
156
|
end
|
144
157
|
|
145
158
|
end
|
data/lib/mautic/proxy.rb
CHANGED
@@ -29,9 +29,7 @@ module Mautic
|
|
29
29
|
records = results = where(options)
|
30
30
|
total = @last_response['total'].to_i
|
31
31
|
while records.any?
|
32
|
-
if block_given?
|
33
|
-
records.each &block
|
34
|
-
end
|
32
|
+
records.each(&block) if block_given?
|
35
33
|
break if results.size >= total
|
36
34
|
|
37
35
|
records = where(options.merge(start: records.size))
|
data/lib/mautic/version.rb
CHANGED
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: 2.3.
|
4
|
+
version: 2.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lukáš Pokorný
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -58,84 +58,84 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 1.
|
61
|
+
version: '1.4'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 1.
|
68
|
+
version: '1.4'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec-rails
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '3.
|
75
|
+
version: '3.9'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '3.
|
82
|
+
version: '3.9'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: factory_bot_rails
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '5.1'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '5.1'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: database_cleaner
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '1.
|
103
|
+
version: '1.7'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '1.
|
110
|
+
version: '1.7'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: faker
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
117
|
+
version: '2.7'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
124
|
+
version: '2.7'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: webmock
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - "~>"
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: '3.
|
131
|
+
version: '3.7'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: '3.
|
138
|
+
version: '3.7'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: pry-rails
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -205,7 +205,8 @@ files:
|
|
205
205
|
homepage: https://github.com/luk4s/mautic-rails
|
206
206
|
licenses:
|
207
207
|
- MIT
|
208
|
-
metadata:
|
208
|
+
metadata:
|
209
|
+
allowed_push_host: https://rubygems.org
|
209
210
|
post_install_message:
|
210
211
|
rdoc_options: []
|
211
212
|
require_paths:
|
@@ -221,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
221
222
|
- !ruby/object:Gem::Version
|
222
223
|
version: '0'
|
223
224
|
requirements: []
|
224
|
-
rubygems_version: 3.0.
|
225
|
+
rubygems_version: 3.0.4
|
225
226
|
signing_key:
|
226
227
|
specification_version: 4
|
227
228
|
summary: Ruby on Rails Mautic integration
|