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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 33fe31e13b43b1d8512a2154745065bdfa14edbb9b4aff283e0dfa25ceb12726
4
- data.tar.gz: b8c40ff6d3f370fb9d31b8451a3d5f107dd354d26f9747bb5a6cba3e3d4e6165
3
+ metadata.gz: fc71868e69c1e667eae14b5d488bc04577a0e2c8d2536b1afe309fcf8026239a
4
+ data.tar.gz: ae89c15ca8ae6f10886f0683ac8e3d90a48b177c32505a5a44ec29d7ac409a1f
5
5
  SHA512:
6
- metadata.gz: a2f62e3033c4aaf18a2b4dd9205a52fc1f6c9cc4c423e33508b9d89058e37099f10dfad39a6b45e0b47299133b810cf3059fc216093f79b88021ae47027dc4af
7
- data.tar.gz: 95d5b4ba6f9237d9ff5e1d1fcdd0108b6e941d6b7ff71743739a31ca36bae14778e0309fc0f9fdc6cfcb2d5a9074787a06e830f47bd616688f5304b11ffa371e
6
+ metadata.gz: c4de6163a5a43118d1040357c76d8ebb010f27ff38b80d94f38bf8c2332a6c447ba10abd9407f1bf99c0d5be7bcebf563066741bcbb88ed59275dd762f45a98a
7
+ data.tar.gz: 9194fa0346cf3b0b37397dca183b808372c50192c09b427f1f00ce3cd3273eacc991cbd52ba76763f057e97e0d187f2416ca27948a51cd6d70f8a777601d6bfd
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_campaign_crm (0.1.4)
4
+ active_campaign_crm (0.2.0)
5
5
  faraday (~> 0.15)
6
6
 
7
7
  GEM
@@ -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
- return fields[0] if fields.any?
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
- return fields[0] if fields.any?
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
- return tags[0] if tags.any?
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
 
@@ -1,3 +1,3 @@
1
1
  module ActiveCampaignCrm
2
- VERSION = '0.1.4'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
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.1.4
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-08 00:00:00.000000000 Z
11
+ date: 2019-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday