mautic 0.1.1 → 0.1.2
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 +4 -4
- data/app/models/mautic/connection.rb +5 -1
- data/app/models/mautic/contact.rb +13 -0
- data/lib/mautic.rb +0 -3
- data/lib/mautic/model.rb +4 -0
- data/lib/mautic/proxy.rb +28 -11
- data/lib/mautic/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ffe887a24a76b7478220db1f4acfa84f0fdb7a9
|
4
|
+
data.tar.gz: 53130ea996b7e93e54a537c80dd489abbd1c8c5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9430d72187f8fa3aaac4d3d96f00b5b206e8a41f1fd5914d48d83b38d2f2b41e66ea02b49f23fbf1915fb7d10d473075c04ee59f1696abe0069042c3bd27b9a
|
7
|
+
data.tar.gz: 0f5ba996476345d15e19d71c379cc6285b137a3049dbf15362b609904a699b8e66a4eddbe7cb70f325c15770ed6582585d40b06b78c75043e3056fce07fc4bb8
|
@@ -28,12 +28,16 @@ module Mautic
|
|
28
28
|
raise NotImplementedError
|
29
29
|
end
|
30
30
|
|
31
|
-
%w(assets campaigns categories companies
|
31
|
+
%w(assets campaigns categories companies emails forms messages notes notifications pages points roles stats users).each do |entity|
|
32
32
|
define_method entity do
|
33
33
|
Proxy.new(self, entity)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
+
def contacts
|
38
|
+
Proxy.new(self, 'contacts', default_params: { search: '!is:anonymous' })
|
39
|
+
end
|
40
|
+
|
37
41
|
def request(type, path, params = {})
|
38
42
|
raise NotImplementedError
|
39
43
|
end
|
data/lib/mautic.rb
CHANGED
data/lib/mautic/model.rb
CHANGED
data/lib/mautic/proxy.rb
CHANGED
@@ -1,29 +1,45 @@
|
|
1
1
|
module Mautic
|
2
2
|
class Proxy
|
3
3
|
|
4
|
-
def initialize(connection, endpoint)
|
4
|
+
def initialize(connection, endpoint, options = nil)
|
5
5
|
@connection = connection
|
6
6
|
klass = "Mautic::#{endpoint.classify}"
|
7
7
|
@target = klass.safe_constantize || Mautic.const_set(endpoint.classify, Class.new(Mautic::Model))
|
8
8
|
@endpoint = endpoint
|
9
|
+
@options = options || {}
|
9
10
|
end
|
10
11
|
|
11
12
|
def new(attributes = {})
|
12
13
|
@target.new(@connection, attributes)
|
13
14
|
end
|
14
15
|
|
15
|
-
def all(options={})
|
16
|
-
|
16
|
+
def all(options = {}, &block)
|
17
|
+
if options[:limit] == 'all'
|
18
|
+
|
19
|
+
options.delete(:limit)
|
20
|
+
|
21
|
+
records = results = where(options)
|
22
|
+
total = @last_response['total'].to_i
|
23
|
+
while records.any?
|
24
|
+
if block_given?
|
25
|
+
records.each &block
|
26
|
+
end
|
27
|
+
break if results.size >= total
|
28
|
+
|
29
|
+
records = where(options.merge(start: records.size))
|
30
|
+
results.concat records
|
31
|
+
end
|
32
|
+
else
|
33
|
+
results = where(options)
|
34
|
+
results.each{|i| yield i } if block_given?
|
35
|
+
end
|
36
|
+
results
|
17
37
|
end
|
18
38
|
|
19
|
-
def where(
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
when ::Hash
|
24
|
-
arg
|
25
|
-
end
|
26
|
-
json = @connection.request(:get, "api/#{@endpoint}", { params: params })
|
39
|
+
def where(params = {})
|
40
|
+
q = params.reverse_merge(@options[:default_params] || {})
|
41
|
+
json = @connection.request(:get, "api/#{@endpoint}", {params: q })
|
42
|
+
@last_response = json
|
27
43
|
json[@endpoint].collect do |id, attributes|
|
28
44
|
@target.new(@connection, attributes || id)
|
29
45
|
end
|
@@ -35,6 +51,7 @@ module Mautic
|
|
35
51
|
|
36
52
|
def find(id)
|
37
53
|
json = @connection.request(:get, "api/#{@endpoint}/#{id}")
|
54
|
+
@last_response = json
|
38
55
|
@target.new(@connection, json[@endpoint.singularize])
|
39
56
|
end
|
40
57
|
|
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: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lukáš Pokorný
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -195,6 +195,7 @@ files:
|
|
195
195
|
- app/models/mautic/application_record.rb
|
196
196
|
- app/models/mautic/connection.rb
|
197
197
|
- app/models/mautic/connections/oauth2.rb
|
198
|
+
- app/models/mautic/contact.rb
|
198
199
|
- app/models/mautic/form.rb
|
199
200
|
- app/views/layouts/mautic/application.html.erb
|
200
201
|
- app/views/mautic/connections/_form.html.erb
|