active_campaign_crm 0.1.2 → 0.1.3

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: a34369e13cac516cb243044eff64b46cf236bd193907e3e1356b963ad41a006b
4
- data.tar.gz: c849b6ef493645702333fe97d723dddd31bd4038d6d9c77e8e8c6addfa8eb92a
3
+ metadata.gz: 47f200b7283f94c48f1480fcb49042a340242d6621fa5109df1e29f4135dfe2f
4
+ data.tar.gz: 2e101a3c5dffff3bd12dbc41df7b973942836661837aef3fe09219d7a69801c3
5
5
  SHA512:
6
- metadata.gz: 141f0e6e7f250f106b34e2c41712cd8c738cb96db4da4902ddb0cb11047bec1f9fa0ef08e16799a808db6a62fe08935880813ab1944cbef650f0e5193db43943
7
- data.tar.gz: b0cc2d626b0888a0dffb4874a1e5d4caeadb71ee1b828fe98a4c60efcf85dca932685187a4fb68293c049e10e0f59b83c84098ce12685a93f92a0dd1df79bfb9
6
+ metadata.gz: 4d4fc77022772a99cef0e96064dae022ab901d9c255cd9ed5aa13476ffcfa864e2d33cff954a240cb8882942d5abbd25910909145e00a424b39539c947c45fae
7
+ data.tar.gz: 5a17dc649db72c3b8a834cf1950542f3cd876e1a65098efa48468c8554d923e255f4cdbbead6b6968f17b86911a975292a040ca3880415aa873f533c4bdd9347
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_campaign_crm (0.1.2)
4
+ active_campaign_crm (0.1.3)
5
5
  faraday (~> 0.15)
6
6
 
7
7
  GEM
@@ -2,8 +2,8 @@ require 'active_campaign_crm/version'
2
2
  require 'active_campaign_crm/client'
3
3
  require 'active_campaign_crm/configuration'
4
4
 
5
+ # ActiveCampaignCrm Interface
5
6
  module ActiveCampaignCrm
6
-
7
7
  def self.client
8
8
  ActiveCampaignCrm::Client.new(options)
9
9
  end
@@ -2,7 +2,7 @@ module ActiveCampaignCrm
2
2
  class Client
3
3
  require 'active_campaign_crm/connection'
4
4
 
5
- Dir[File.expand_path('../client/*.rb', __FILE__)].each{ |f| require f }
5
+ Dir[File.expand_path('../client/*.rb', __FILE__)].each { |f| require f }
6
6
 
7
7
  def initialize
8
8
  @connection = ActiveCampaignCrm::Connection.new
@@ -1,5 +1,6 @@
1
1
  module ActiveCampaignCrm
2
2
  class Client
3
+ #Contact Fields Interface
3
4
  module ContactFields
4
5
  def contact_fields(params = {})
5
6
  response = @connection.get('fields', params)
@@ -16,6 +17,22 @@ module ActiveCampaignCrm
16
17
  response['field']
17
18
  end
18
19
 
20
+ def find_or_create_contact_field(perstag, properties)
21
+ fields = contact_fields("filters[perstag]": perstag)
22
+ return fields[0] if fields.any?
23
+
24
+ create_contact_field(properties)
25
+ end
26
+
27
+ def find_or_create_field_with_relationship(perstag, properties, rel)
28
+ fields = contact_fields("filters[perstag]": perstag)
29
+ return fields[0] if fields.any?
30
+
31
+ field = create_contact_field(properties)
32
+ add_relationship_to_field(field['id'], rel)
33
+ field
34
+ end
35
+
19
36
  def add_relationship_to_field(field, rel)
20
37
  response = @connection.post('fieldRels', custom_rel_body(field, rel))
21
38
  response['fieldRel']
@@ -1,5 +1,6 @@
1
1
  module ActiveCampaignCrm
2
2
  class Client
3
+ # Organization Interface
3
4
  module Organization
4
5
  def organizations(params = {})
5
6
  response = @connection.get('organizations', params)
@@ -16,8 +17,16 @@ module ActiveCampaignCrm
16
17
  response['organization']
17
18
  end
18
19
 
20
+ def find_or_create_organization(name)
21
+ organizations = organizations("filters[name]": name)
22
+ return organization[0] if organizations.any?
23
+
24
+ create_organization(name: name)
25
+ end
26
+
19
27
  def update_organization(id, fields)
20
- response = @connection.put("organizations/#{id}", organization_body(fields))
28
+ response = @connection.put("organizations/#{id}",
29
+ organization_body(fields))
21
30
  response['organization']
22
31
  end
23
32
 
@@ -1,5 +1,6 @@
1
1
  module ActiveCampaignCrm
2
2
  class Client
3
+ # Tag Interface
3
4
  module Tags
4
5
  def tags(params = {})
5
6
  response = @connection.get('tags', params)
@@ -16,8 +17,17 @@ module ActiveCampaignCrm
16
17
  response['tag']
17
18
  end
18
19
 
20
+ def sync_tag(tag, type, description)
21
+ query = { 'filters[tag]': tag }
22
+ tags = tags(query)
23
+ return tags[0] if tags.any?
24
+
25
+ create_tag(tag: tag, tagType: type, description: description)
26
+ end
27
+
19
28
  def add_tag_to_contact(contact, tag)
20
- response = @connection.post('contactTags', contact_link_tag_body(contact, tag))
29
+ response = @connection.post('contactTags',
30
+ contact_link_tag_body(contact, tag))
21
31
  response['contactTag']
22
32
  end
23
33
 
@@ -1,11 +1,10 @@
1
1
  module ActiveCampaignCrm
2
+ # Handles all connections with active campaign
2
3
  class Connection
3
4
  require 'faraday'
4
5
  require 'json'
5
6
  require 'active_campaign_crm/error'
6
7
  def initialize
7
- # TODO: raise exception if account_url is not defined
8
- # TODO: raise exception if api_key is not defined
9
8
  @connection = Faraday.new(
10
9
  url: "#{ActiveCampaignCrm.configuration.account_url}/api/3"
11
10
  )
@@ -1,3 +1,3 @@
1
1
  module ActiveCampaignCrm
2
- VERSION = "0.1.2"
2
+ VERSION = '0.1.3'.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.2
4
+ version: 0.1.3
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-07 00:00:00.000000000 Z
11
+ date: 2019-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday