active_campaign_crm 0.1.4 → 0.2.0
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/Gemfile.lock +1 -1
- data/lib/active_campaign_crm/client/contact_fields.rb +15 -3
- data/lib/active_campaign_crm/client/tags.rb +10 -1
- data/lib/active_campaign_crm/configuration.rb +5 -0
- data/lib/active_campaign_crm/connection.rb +1 -1
- data/lib/active_campaign_crm/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: fc71868e69c1e667eae14b5d488bc04577a0e2c8d2536b1afe309fcf8026239a
|
4
|
+
data.tar.gz: ae89c15ca8ae6f10886f0683ac8e3d90a48b177c32505a5a44ec29d7ac409a1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4de6163a5a43118d1040357c76d8ebb010f27ff38b80d94f38bf8c2332a6c447ba10abd9407f1bf99c0d5be7bcebf563066741bcbb88ed59275dd762f45a98a
|
7
|
+
data.tar.gz: 9194fa0346cf3b0b37397dca183b808372c50192c09b427f1f00ce3cd3273eacc991cbd52ba76763f057e97e0d187f2416ca27948a51cd6d70f8a777601d6bfd
|
data/Gemfile.lock
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module ActiveCampaignCrm
|
2
2
|
class Client
|
3
|
-
#Contact Fields Interface
|
3
|
+
# Contact Fields Interface
|
4
4
|
module ContactFields
|
5
5
|
def contact_fields(params = {})
|
6
6
|
response = @connection.get('fields', params)
|
@@ -14,19 +14,31 @@ module ActiveCampaignCrm
|
|
14
14
|
|
15
15
|
def create_contact_field(properties)
|
16
16
|
response = @connection.post('fields', contact_field_body(properties))
|
17
|
+
field = response['field']
|
18
|
+
ActiveCampaignCrm.cache[:contact_fields][perstag] = field['id']
|
17
19
|
response['field']
|
18
20
|
end
|
19
21
|
|
22
|
+
def cached_contact_field_id(perstag)
|
23
|
+
ActiveCampaignCrm.cache.dig(:contact_fields, perstag)
|
24
|
+
end
|
25
|
+
|
20
26
|
def find_or_create_contact_field(perstag, properties)
|
21
27
|
fields = contact_fields("filters[perstag]": perstag)
|
22
|
-
|
28
|
+
if fields.any?
|
29
|
+
ActiveCampaignCrm.cache[:contact_fields][perstag] = fields[0]['id']
|
30
|
+
return fields[0]
|
31
|
+
end
|
23
32
|
|
24
33
|
create_contact_field(properties)
|
25
34
|
end
|
26
35
|
|
27
36
|
def find_or_create_field_with_relationship(perstag, properties, rel)
|
28
37
|
fields = contact_fields("filters[perstag]": perstag)
|
29
|
-
|
38
|
+
if fields.any?
|
39
|
+
ActiveCampaignCrm.cache[:contact_fields][perstag] = fields[0]['id']
|
40
|
+
return fields[0]
|
41
|
+
end
|
30
42
|
|
31
43
|
field = create_contact_field(properties)
|
32
44
|
add_relationship_to_field(field['id'], rel)
|
@@ -14,13 +14,22 @@ module ActiveCampaignCrm
|
|
14
14
|
|
15
15
|
def create_tag(fields)
|
16
16
|
response = @connection.post('tags', tag_body(fields))
|
17
|
+
tag_name = response['tag']['tag']
|
18
|
+
ActiveCampaignCrm.cache[:tags][tag_name] = response['tag']['id']
|
17
19
|
response['tag']
|
18
20
|
end
|
19
21
|
|
22
|
+
def cached_tag_id(tag)
|
23
|
+
ActiveCampaignCrm.cache.dig(:tags, tag)
|
24
|
+
end
|
25
|
+
|
20
26
|
def sync_tag(tag, type, description)
|
21
27
|
query = { 'filters[tag]': tag }
|
22
28
|
tags = tags(query)
|
23
|
-
|
29
|
+
if tags.any?
|
30
|
+
ActiveCampaignCrm.cache[:tags][tag] = tags[0]['id']
|
31
|
+
return tags[0]
|
32
|
+
end
|
24
33
|
|
25
34
|
create_tag(tag: tag, tagType: type, description: description)
|
26
35
|
end
|
@@ -1,10 +1,15 @@
|
|
1
1
|
module ActiveCampaignCrm
|
2
2
|
class << self
|
3
3
|
attr_accessor :configuration
|
4
|
+
attr_accessor :cache
|
4
5
|
end
|
5
6
|
|
6
7
|
def self.configure
|
7
8
|
self.configuration ||= Configuration.new
|
9
|
+
self.cache = {
|
10
|
+
"contact_fields": {},
|
11
|
+
"tags": {}
|
12
|
+
}
|
8
13
|
yield(configuration)
|
9
14
|
end
|
10
15
|
|
@@ -48,7 +48,7 @@ module ActiveCampaignCrm
|
|
48
48
|
def handle_response(response)
|
49
49
|
return JSON.parse response.body if response.success?
|
50
50
|
|
51
|
-
errors = JSON.parse(response.body)['errors']
|
51
|
+
errors = JSON.parse(response.body)['errors'] unless response.body.empty?
|
52
52
|
error_messages = errors.map { |error| error['title'] } unless errors.nil?
|
53
53
|
error_message = error_messages.join('-') unless error_messages.nil?
|
54
54
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_campaign_crm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nuno Correia
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-04-
|
11
|
+
date: 2019-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|