mautic 2.3.3 → 2.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mautic.rb +19 -4
- data/lib/mautic/engine.rb +3 -1
- data/lib/mautic/proxy.rb +22 -13
- data/lib/mautic/version.rb +1 -1
- data/spec/rails_helper.rb +3 -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: afb8b76cddd73b61cfefac55cd183fd3b84603dfc1681fe00d4c524838cf5bcb
|
4
|
+
data.tar.gz: 8a632817a47a0e2819a4cd74fef4798ebddf80cd9c68fdebad462bb0ca3a570d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb0312a5a188a6619421a33b4768dd5e2aa90ea6ef7764e67a7ad169e9b1ec24bf342c9eb1ce4c22958a24562c22a2c80285daa8f48c14c9df1fc2bca2603dcf
|
7
|
+
data.tar.gz: 4b4b003e569e396529ece6d0971d749131996d0e0692cf33f64af21efa164820dab732b155526d3074d4e136c9ac91648180d540407523f8f4a9e9815de5ca5f
|
data/lib/mautic.rb
CHANGED
@@ -11,12 +11,23 @@ module Mautic
|
|
11
11
|
|
12
12
|
class RequestError < StandardError
|
13
13
|
|
14
|
-
attr_reader :response, :errors
|
14
|
+
attr_reader :response, :errors, :request_url
|
15
15
|
|
16
16
|
def initialize(response, message = nil)
|
17
17
|
@errors ||= []
|
18
18
|
@response = response
|
19
|
-
|
19
|
+
@request_url = response.response&.env&.url
|
20
|
+
body = if response.body.start_with? "<!DOCTYPE html>"
|
21
|
+
response.body.split("\n").last
|
22
|
+
else
|
23
|
+
response.body
|
24
|
+
end
|
25
|
+
|
26
|
+
json_body = begin
|
27
|
+
JSON.parse(body)
|
28
|
+
rescue JSON::ParserError
|
29
|
+
{ "errors" => [{ "code" => response.status, "message" => body }] }
|
30
|
+
end
|
20
31
|
message ||= Array(json_body['errors']).collect do |error|
|
21
32
|
msg = error['code'].to_s
|
22
33
|
msg << " (#{error['type']}):" if error['type']
|
@@ -25,7 +36,7 @@ module Mautic
|
|
25
36
|
msg
|
26
37
|
end.join(', ')
|
27
38
|
|
28
|
-
super(message)
|
39
|
+
super("#{@request_url} => #{message}")
|
29
40
|
end
|
30
41
|
|
31
42
|
end
|
@@ -37,7 +48,11 @@ module Mautic
|
|
37
48
|
|
38
49
|
def initialize(response, message = nil)
|
39
50
|
@response = response
|
40
|
-
json_body =
|
51
|
+
json_body = begin
|
52
|
+
JSON.parse(response.body)
|
53
|
+
rescue ParseError
|
54
|
+
{}
|
55
|
+
end
|
41
56
|
@errors = Array(json_body['errors']).inject({}) { |mem, var| mem.merge!(var['details']); mem }
|
42
57
|
message ||= @errors.collect { |field, msg| "#{field}: #{msg.join(', ')}" }.join('; ')
|
43
58
|
super(response, message)
|
data/lib/mautic/engine.rb
CHANGED
@@ -5,7 +5,8 @@ module Mautic
|
|
5
5
|
config.generators do |g|
|
6
6
|
g.test_framework :rspec, fixture: false
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
|
+
# :nocov:
|
9
10
|
initializer :append_migrations do |app|
|
10
11
|
unless app.root.to_s.match root.to_s
|
11
12
|
config.paths['db/migrate'].expanded.each do |expanded_path|
|
@@ -13,6 +14,7 @@ module Mautic
|
|
13
14
|
end
|
14
15
|
end
|
15
16
|
end
|
17
|
+
# :nocov:
|
16
18
|
|
17
19
|
end
|
18
20
|
end
|
data/lib/mautic/proxy.rb
CHANGED
@@ -23,28 +23,20 @@ module Mautic
|
|
23
23
|
|
24
24
|
def all(options = {}, &block)
|
25
25
|
if options[:limit] == 'all'
|
26
|
-
|
27
26
|
options.delete(:limit)
|
28
|
-
|
29
|
-
records = results = where(options)
|
30
|
-
total = @last_response['total'].to_i
|
31
|
-
while records.any?
|
32
|
-
records.each(&block) if block_given?
|
33
|
-
break if results.size >= total
|
34
|
-
|
35
|
-
records = where(options.merge(start: records.size))
|
36
|
-
results.concat records
|
37
|
-
end
|
27
|
+
limit_all(options, &block)
|
38
28
|
else
|
39
29
|
results = where(options)
|
40
30
|
results.each { |i| yield i } if block_given?
|
31
|
+
results
|
41
32
|
end
|
42
|
-
results
|
43
33
|
end
|
44
34
|
|
35
|
+
# @param [Hash] params
|
36
|
+
# @see https://developer.mautic.org
|
45
37
|
def where(params = {})
|
46
38
|
q = params.reverse_merge(@options[:default_params] || {})
|
47
|
-
json = @connection.request(:get, "api/#{@endpoint}",
|
39
|
+
json = @connection.request(:get, "api/#{@endpoint}", params: q)
|
48
40
|
@count = json["total"].to_i
|
49
41
|
@last_response = json
|
50
42
|
json[data_name].collect do |id, attributes|
|
@@ -69,5 +61,22 @@ module Mautic
|
|
69
61
|
@count = json["total"].to_i
|
70
62
|
end
|
71
63
|
|
64
|
+
protected
|
65
|
+
|
66
|
+
# @param [Hash] options
|
67
|
+
# @option options (see #where)
|
68
|
+
def limit_all(options, &block)
|
69
|
+
records = results = where(options)
|
70
|
+
total = @last_response['total'].to_i
|
71
|
+
while records.any?
|
72
|
+
records.each(&block) if block_given?
|
73
|
+
break if results.size >= total
|
74
|
+
|
75
|
+
records = where(options.merge(start: records.size))
|
76
|
+
results.concat records
|
77
|
+
end
|
78
|
+
results
|
79
|
+
end
|
80
|
+
|
72
81
|
end
|
73
82
|
end
|
data/lib/mautic/version.rb
CHANGED
data/spec/rails_helper.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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lukáš Pokorný
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|