mautic 2.3.9 → 2.3.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/mautic/contact.rb +3 -3
- data/app/models/mautic/tag.rb +28 -0
- data/lib/mautic/model.rb +18 -4
- data/lib/mautic/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b00390acf94aa6294ef58fbfeab2d3a0198544c52b162c837134adf79e8c3ad
|
4
|
+
data.tar.gz: 3efd6bea9cdc79cd58b535489edc1a6cd11ae5539797b2246feaa1760662009f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc3eb999f11d813f81047485875e194acd8c41f9de2910f87df449af5be27a90d577eab222651acbe3565c804e7c9510a458cfc0e0a7f643c9217f049f035e59
|
7
|
+
data.tar.gz: dc2eeb43ce4ad5f5805e92e4bc452f91abbd3fbd2e16df28a6b1abdc78a9fd1975ac9faa1bdd7756d118feb792d20c0eec4e405e257cffff1d46828ac5eb50a4
|
@@ -41,8 +41,9 @@ module Mautic
|
|
41
41
|
|
42
42
|
if source
|
43
43
|
self.owner = source['owner'] || {}
|
44
|
+
tags = (source['tags'] || []).map { |t| Mautic::Tag.new(self, t) }.sort_by(&:name)
|
44
45
|
self.attributes = {
|
45
|
-
tags:
|
46
|
+
tags: Tag::Collection.new(self, *tags),
|
46
47
|
doNotContact: source['doNotContact'] || [],
|
47
48
|
owner: owner['id'],
|
48
49
|
}
|
@@ -51,7 +52,6 @@ module Mautic
|
|
51
52
|
|
52
53
|
def to_mautic(data = @table)
|
53
54
|
data.delete(:doNotContact)
|
54
|
-
data.delete(:tags)
|
55
55
|
super(data)
|
56
56
|
end
|
57
57
|
|
@@ -96,7 +96,7 @@ module Mautic
|
|
96
96
|
self.errors = e.errors
|
97
97
|
end
|
98
98
|
|
99
|
-
|
99
|
+
errors.blank?
|
100
100
|
end
|
101
101
|
|
102
102
|
alias add_dnc do_not_contact!
|
data/app/models/mautic/tag.rb
CHANGED
@@ -1,6 +1,34 @@
|
|
1
1
|
module Mautic
|
2
2
|
class Tag < Model
|
3
3
|
|
4
|
+
class Collection < Array
|
5
|
+
attr_reader :model
|
6
|
+
|
7
|
+
# @param [Mautic::Model] model
|
8
|
+
def initialize(model, *several_variants)
|
9
|
+
@model = model
|
10
|
+
@tags_to_remove = []
|
11
|
+
super(several_variants)
|
12
|
+
end
|
13
|
+
|
14
|
+
def <<(item)
|
15
|
+
@model.changed = true
|
16
|
+
item = Tag.new(@model, { tag: item }) if item.is_a?(String)
|
17
|
+
super(item)
|
18
|
+
end
|
19
|
+
|
20
|
+
def remove(item)
|
21
|
+
@model.changed = true
|
22
|
+
item = detect { |t| t.name == item } if item.is_a?(String)
|
23
|
+
@tags_to_remove << "-#{item}"
|
24
|
+
delete item
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_mautic
|
28
|
+
map(&:name) + @tags_to_remove
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
4
32
|
# alias for attribute :tag
|
5
33
|
def name
|
6
34
|
tag
|
data/lib/mautic/model.rb
CHANGED
@@ -39,6 +39,7 @@ module Mautic
|
|
39
39
|
|
40
40
|
attr_reader :connection
|
41
41
|
attr_accessor :errors
|
42
|
+
attr_writer :changed
|
42
43
|
|
43
44
|
# @param [Mautic::Connection] connection
|
44
45
|
def initialize(connection, hash = nil)
|
@@ -58,7 +59,7 @@ module Mautic
|
|
58
59
|
end
|
59
60
|
|
60
61
|
def update(force = false)
|
61
|
-
return false
|
62
|
+
return false unless changed?
|
62
63
|
|
63
64
|
begin
|
64
65
|
json = @connection.request((force && :put || :patch), "api/#{endpoint}/#{id}/edit", body: to_mautic)
|
@@ -68,7 +69,7 @@ module Mautic
|
|
68
69
|
self.errors = e.errors
|
69
70
|
end
|
70
71
|
|
71
|
-
|
72
|
+
errors.blank?
|
72
73
|
end
|
73
74
|
|
74
75
|
def update_columns(attributes = {})
|
@@ -88,7 +89,7 @@ module Mautic
|
|
88
89
|
self.errors = e.errors
|
89
90
|
end
|
90
91
|
|
91
|
-
|
92
|
+
errors.blank?
|
92
93
|
end
|
93
94
|
|
94
95
|
def destroy
|
@@ -105,6 +106,12 @@ module Mautic
|
|
105
106
|
@table.changes
|
106
107
|
end
|
107
108
|
|
109
|
+
def changed?
|
110
|
+
return @changed unless @changed.nil?
|
111
|
+
|
112
|
+
@changed = !changes.empty?
|
113
|
+
end
|
114
|
+
|
108
115
|
def attributes
|
109
116
|
@table.to_h
|
110
117
|
end
|
@@ -118,13 +125,20 @@ module Mautic
|
|
118
125
|
|
119
126
|
def to_mautic(data = @table)
|
120
127
|
data.each_with_object({}) do |(key, val), mem|
|
121
|
-
mem[key] = val.
|
128
|
+
mem[key] = if val.respond_to?(:to_mautic)
|
129
|
+
val.to_mautic
|
130
|
+
elsif val.is_a?(Array)
|
131
|
+
val.join("|")
|
132
|
+
else
|
133
|
+
val
|
134
|
+
end
|
122
135
|
end
|
123
136
|
end
|
124
137
|
|
125
138
|
private
|
126
139
|
|
127
140
|
def clear_changes
|
141
|
+
@changed = nil
|
128
142
|
@table.instance_variable_set(:@changes, nil)
|
129
143
|
end
|
130
144
|
|
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.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lukáš Pokorný
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|