mautic 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ba8f8a30689a990362470a3af955dec9806de43e
4
- data.tar.gz: 6bfa9b65f2f37fb3d04ca4b796fbca69d6adb59b
3
+ metadata.gz: 7ffe887a24a76b7478220db1f4acfa84f0fdb7a9
4
+ data.tar.gz: 53130ea996b7e93e54a537c80dd489abbd1c8c5c
5
5
  SHA512:
6
- metadata.gz: 574a39ff9fa73874b6d80d0781cccf2528aff12fc7c9acc6cb94febc3b3859fccbafd7b094e96add0b8f685fa2c45e45bfc9e724f3c2a8ef782b7b20391f9cd5
7
- data.tar.gz: bd728bc2be94076c71abb072fa899dd401b58e3e371cad41b0c25fbf74c2e2589d7fa47311814fdda0b7f56c623a087be44cd702bf1fab4f3619fa0ff9bfc735
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 contacts emails forms messages notes notifications pages points roles stats users).each do |entity|
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
@@ -0,0 +1,13 @@
1
+ module Mautic
2
+ class Contact < Model
3
+
4
+ def self.in(connection)
5
+ Proxy.new(connection, endpoint, default_params: { search: '!is:anonymous' })
6
+ end
7
+
8
+ def name
9
+ "#{firstname} #{lastname}"
10
+ end
11
+
12
+ end
13
+ end
@@ -27,7 +27,4 @@ module Mautic
27
27
  end
28
28
  # Your code goes here...
29
29
 
30
- class Contact < Model
31
-
32
- end
33
30
  end
@@ -69,6 +69,10 @@ module Mautic
69
69
  @table.changes
70
70
  end
71
71
 
72
+ def attributes
73
+ @table.to_h
74
+ end
75
+
72
76
  private
73
77
 
74
78
  def endpoint
@@ -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
- where(options)
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(arg = '')
20
- params = case arg
21
- when ::String
22
- { search: arg } if arg.present?
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
 
@@ -1,3 +1,3 @@
1
1
  module Mautic
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
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.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-01 00:00:00.000000000 Z
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