mautic 2.2.2 → 2.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/concerns/mautic/receive_web_hooks.rb +1 -1
- data/app/models/mautic/connection.rb +13 -5
- data/app/models/mautic/contact.rb +5 -1
- data/app/models/mautic/event.rb +23 -0
- data/app/models/mautic/web_hook.rb +1 -1
- data/app/views/mautic/connections/edit.html.erb +1 -0
- data/config/routes.rb +1 -1
- data/lib/mautic/proxy.rb +24 -9
- data/lib/mautic/submissions/form.rb +10 -4
- data/lib/mautic/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50cf7b5fa5dcc376ddb8a7e50a37c521d00ffcab8cef1b17b2e1bac598eb70aa
|
4
|
+
data.tar.gz: 6a6f4890c25207a24ac1eaa0b30834e8059fec5c0f14e0392e7e902016882688
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37cd5dae4578a9bffa5f16a9ac4341b7f9c22bf1e1f0bdbd86aab0e7ac76932d5e1106c2c33f50214f8ec9e0f51102cb68d1c718d952c42cdbaf38e24c8b6b2e
|
7
|
+
data.tar.gz: ee5be0217d9e2797778ab93ff29b9bc39a23e8c0bc92bbd7aa2df59ae46008a5eb60624d4743001ef4d2e1cbda15ddd7eb24c9c2a44b495d177ff8ea53235f7e
|
@@ -10,7 +10,7 @@ module Mautic
|
|
10
10
|
|
11
11
|
# @param [ActionController::Parameters] params
|
12
12
|
def self.receive_webhook(params)
|
13
|
-
WebHook.new(find(params.require(:
|
13
|
+
WebHook.new(find(params.require(:mautic_connection_id)), params)
|
14
14
|
end
|
15
15
|
|
16
16
|
def client
|
@@ -67,6 +67,8 @@ module Mautic
|
|
67
67
|
case response.status
|
68
68
|
when 400
|
69
69
|
raise Mautic::ValidationError.new(response)
|
70
|
+
when 401
|
71
|
+
json = try_to_refresh_and_parse(response)
|
70
72
|
when 404
|
71
73
|
raise Mautic::RecordNotFound.new(response)
|
72
74
|
when 200, 201
|
@@ -74,10 +76,7 @@ module Mautic
|
|
74
76
|
Array(json['errors']).each do |error|
|
75
77
|
case error['code'].to_i
|
76
78
|
when 401
|
77
|
-
|
78
|
-
@try_to_refresh = true
|
79
|
-
refresh!
|
80
|
-
json = request(*@last_request)
|
79
|
+
json = try_to_refresh_and_parse(response)
|
81
80
|
when 404
|
82
81
|
raise Mautic::RecordNotFound.new(response)
|
83
82
|
else
|
@@ -91,5 +90,14 @@ module Mautic
|
|
91
90
|
json
|
92
91
|
end
|
93
92
|
|
93
|
+
private
|
94
|
+
|
95
|
+
def try_to_refresh_and_parse(response)
|
96
|
+
raise Mautic::TokenExpiredError.new(response) if @try_to_refresh
|
97
|
+
@try_to_refresh = true
|
98
|
+
refresh!
|
99
|
+
request(*@last_request)
|
100
|
+
end
|
101
|
+
|
94
102
|
end
|
95
103
|
end
|
@@ -14,9 +14,13 @@ module Mautic
|
|
14
14
|
def assign_attributes(source = nil)
|
15
15
|
super
|
16
16
|
self.attributes = {
|
17
|
-
tags: (source['tags'] || []).collect{|t| Mautic::Tag.new(@connection, t)}
|
17
|
+
tags: (source['tags'] || []).collect { |t| Mautic::Tag.new(@connection, t) }.sort_by(&:name)
|
18
18
|
} if source
|
19
19
|
end
|
20
20
|
|
21
|
+
def events
|
22
|
+
@proxy_events ||= Proxy.new(connection, "contacts/#{id}/events", klass: "Mautic::Event")
|
23
|
+
end
|
24
|
+
|
21
25
|
end
|
22
26
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Mautic
|
2
|
+
class Event < Model
|
3
|
+
|
4
|
+
def initialize(connection, hash = nil)
|
5
|
+
hash["id"] ||= hash["eventId"]
|
6
|
+
hash["dateAdded"] ||= hash["timestamp"]&.to_time
|
7
|
+
super
|
8
|
+
end
|
9
|
+
|
10
|
+
def event_label
|
11
|
+
eventLabel
|
12
|
+
end
|
13
|
+
|
14
|
+
def label
|
15
|
+
event_label.is_a?(Hash) && event_label["label"] || event_label.to_s
|
16
|
+
end
|
17
|
+
|
18
|
+
def source_url
|
19
|
+
event_label.is_a?(Hash) ? "#{connection.url}#{event_label["href"]}" : nil
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -12,7 +12,7 @@ module Mautic
|
|
12
12
|
|
13
13
|
def form_submissions
|
14
14
|
@forms ||= Array.wrap(@params.require("mautic.form_on_submit")).collect do |data|
|
15
|
-
p = data.permit(submission: [:id, form: {}, lead: {}]).to_h
|
15
|
+
p = data.permit(submission: [:id, form: {}, lead: {}, results: {}]).to_h
|
16
16
|
::Mautic::Submissions::Form.new(@connection, p["submission"]) if p["submission"]
|
17
17
|
end.compact
|
18
18
|
end
|
data/config/routes.rb
CHANGED
data/lib/mautic/proxy.rb
CHANGED
@@ -2,15 +2,23 @@ module Mautic
|
|
2
2
|
class Proxy
|
3
3
|
|
4
4
|
def initialize(connection, endpoint, options = nil)
|
5
|
+
@options = options || {}
|
5
6
|
@connection = connection
|
6
|
-
klass = "Mautic::#{endpoint.classify}"
|
7
|
+
klass = @options.delete(:klass) || "Mautic::#{endpoint.classify}"
|
7
8
|
@target = klass.safe_constantize || Mautic.const_set(endpoint.classify, Class.new(Mautic::Model))
|
8
9
|
@endpoint = endpoint
|
9
|
-
@options = options || {}
|
10
10
|
end
|
11
11
|
|
12
12
|
def new(attributes = {})
|
13
|
-
|
13
|
+
build_instance attributes
|
14
|
+
end
|
15
|
+
|
16
|
+
def data_name
|
17
|
+
@endpoint.split("/").last
|
18
|
+
end
|
19
|
+
|
20
|
+
def build_instance(data)
|
21
|
+
@target.new(@connection, data)
|
14
22
|
end
|
15
23
|
|
16
24
|
def all(options = {}, &block)
|
@@ -31,17 +39,18 @@ module Mautic
|
|
31
39
|
end
|
32
40
|
else
|
33
41
|
results = where(options)
|
34
|
-
results.each{|i| yield i } if block_given?
|
42
|
+
results.each { |i| yield i } if block_given?
|
35
43
|
end
|
36
44
|
results
|
37
45
|
end
|
38
46
|
|
39
47
|
def where(params = {})
|
40
|
-
q =
|
41
|
-
json = @connection.request(:get, "api/#{@endpoint}", {params: q })
|
48
|
+
q = params.reverse_merge(@options[:default_params] || {})
|
49
|
+
json = @connection.request(:get, "api/#{@endpoint}", { params: q })
|
50
|
+
@count = json["total"].to_i
|
42
51
|
@last_response = json
|
43
|
-
json[
|
44
|
-
|
52
|
+
json[data_name].collect do |id, attributes|
|
53
|
+
build_instance attributes || id
|
45
54
|
end
|
46
55
|
end
|
47
56
|
|
@@ -52,9 +61,15 @@ module Mautic
|
|
52
61
|
def find(id)
|
53
62
|
json = @connection.request(:get, "api/#{@endpoint}/#{id}")
|
54
63
|
@last_response = json
|
55
|
-
|
64
|
+
build_instance json[data_name.singularize]
|
56
65
|
end
|
57
66
|
|
67
|
+
def count
|
68
|
+
return @count if defined? @count
|
69
|
+
|
70
|
+
json = @connection.request(:get, "api/#{@endpoint}", { limit: 1 })
|
71
|
+
@count = json["total"].to_i
|
72
|
+
end
|
58
73
|
|
59
74
|
end
|
60
75
|
end
|
@@ -3,26 +3,32 @@ module Mautic
|
|
3
3
|
class Form
|
4
4
|
attr_reader :id
|
5
5
|
|
6
|
+
# @param [Mautic::Connection] connection
|
7
|
+
# @param [Hash] data
|
6
8
|
def initialize(connection, data)
|
7
9
|
@connection = connection
|
8
10
|
@raw = data
|
9
|
-
@id = data["id"]
|
11
|
+
@id = data["id"].to_i
|
10
12
|
end
|
11
13
|
|
14
|
+
# @return [Integer]
|
12
15
|
def form_id
|
13
|
-
@raw["form"]["id"]
|
16
|
+
@form_id ||= @raw["form"]["id"].to_i
|
14
17
|
end
|
15
18
|
|
19
|
+
# @return [Integer]
|
16
20
|
def contact_id
|
17
|
-
@raw["lead"]["id"]
|
21
|
+
@contact_id ||= @raw["lead"]["id"]
|
18
22
|
end
|
19
23
|
|
24
|
+
# @return [Mautic::Form]
|
20
25
|
def form
|
21
26
|
@form ||= @connection.forms.new(@raw["form"].merge("fields" => @raw["results"]))
|
22
27
|
end
|
23
28
|
|
29
|
+
# @return [Mautic::Contact]
|
24
30
|
def contact
|
25
|
-
@connection.contacts.new(@raw["lead"])
|
31
|
+
@contact ||= @connection.contacts.new(@raw["lead"])
|
26
32
|
end
|
27
33
|
end
|
28
34
|
end
|
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.
|
4
|
+
version: 2.3.1
|
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-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 1.3.6
|
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:
|
68
|
+
version: 1.3.6
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec-rails
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -177,6 +177,7 @@ files:
|
|
177
177
|
- app/models/mautic/connection.rb
|
178
178
|
- app/models/mautic/connections/oauth2.rb
|
179
179
|
- app/models/mautic/contact.rb
|
180
|
+
- app/models/mautic/event.rb
|
180
181
|
- app/models/mautic/form.rb
|
181
182
|
- app/models/mautic/tag.rb
|
182
183
|
- app/models/mautic/web_hook.rb
|
@@ -220,8 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
220
221
|
- !ruby/object:Gem::Version
|
221
222
|
version: '0'
|
222
223
|
requirements: []
|
223
|
-
|
224
|
-
rubygems_version: 2.7.6
|
224
|
+
rubygems_version: 3.0.2
|
225
225
|
signing_key:
|
226
226
|
specification_version: 4
|
227
227
|
summary: Ruby on Rails Mautic integration
|