active-campaign-simple 0.1.1 → 0.3.1
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/README.md +20 -21
- data/lib/active-campaign-simple/event.rb +25 -0
- data/lib/active-campaign-simple/exception_handler.rb +20 -0
- data/lib/active-campaign-simple/exceptions.rb +11 -0
- data/lib/active-campaign-simple/request.rb +14 -7
- data/lib/active-campaign-simple/version.rb +1 -1
- metadata +5 -3
- data/lib/active-campaign-simple/api_error.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f14ce1acb34a9a870103f2046ea7c49f1f443f3a32d3b1b5277227fabd700ee
|
4
|
+
data.tar.gz: 75887c51dd6588bc2ecfc3c474b81830960b6e520a0912958459830f71890525
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a1d9339f80b99a526f2298946db806c6d4733922d44783255f1e1326ac9f54c292b7e5354a2f12b3a2251806be8995092f1d9f27c90868fa8df9d64ec125597
|
7
|
+
data.tar.gz: 73740f17ae33f57b391f2f8c554217bf09bd7136029e8b6fa6584acaadd5926ac8c32b466dedc810b9d7fd8a79f281a743b7d00a56c3fc92de77c438d2f05bdf
|
data/README.md
CHANGED
@@ -33,44 +33,43 @@ ActiveCampaign.get('/contacts')
|
|
33
33
|
# Get a contact
|
34
34
|
ActiveCampaign.get('/contacts/' + id)
|
35
35
|
|
36
|
-
# Create a new contact
|
36
|
+
# Create (post) a new contact
|
37
37
|
# https://developers.activecampaign.com/reference#create-a-contact-new
|
38
|
-
payload
|
38
|
+
ActiveCampaign.post('/contacts', payload: {
|
39
39
|
contact: {
|
40
40
|
email: 'nate@test.com',
|
41
41
|
firstName: 'Nate',
|
42
42
|
lastName: 'Test',
|
43
43
|
phone: '1231231234'
|
44
44
|
},
|
45
|
-
fieldValues:
|
45
|
+
fieldValues: [
|
46
46
|
{
|
47
47
|
field: '1',
|
48
48
|
value: 'The Value for First Field'
|
49
|
-
},
|
50
|
-
{
|
51
|
-
field: '6',
|
52
|
-
value: '2008-01-20'
|
53
49
|
}
|
54
|
-
|
55
|
-
}
|
56
|
-
ActiveCampaign.post('/contacts', payload: payload)
|
50
|
+
]
|
51
|
+
})
|
57
52
|
|
58
|
-
# Update a contact
|
59
|
-
payload
|
53
|
+
# Update (put) a contact
|
54
|
+
ActiveCampaign.put('/contacts/' + id, payload: {
|
60
55
|
contact: {
|
61
|
-
email: 'nate@test.com'
|
62
|
-
},
|
63
|
-
fieldValues: {
|
64
|
-
{
|
65
|
-
field: '1',
|
66
|
-
value: 'The Value for First Field'
|
67
|
-
},
|
56
|
+
email: 'nate@test.com'
|
68
57
|
}
|
69
|
-
}
|
70
|
-
ActiveCampaign.post('/contacts/' + id, payload: payload)
|
58
|
+
})
|
71
59
|
|
72
60
|
# Delete a contact
|
73
61
|
ActiveCampaign.delete('/contacts/' + id)
|
62
|
+
|
63
|
+
# Search for a contact
|
64
|
+
ActiveCampaign.get('/contacts', query: { email: 'test@test.com' })
|
65
|
+
|
66
|
+
# Event Tracking
|
67
|
+
# See: https://developers.activecampaign.com/reference#track-event
|
68
|
+
# NOTE - The tracking API is different from all other calls as it changes the arguments a little to simplify.
|
69
|
+
ActiveCampaign.track_event('event-key', 'actid', 'event-name', 'email')
|
70
|
+
|
71
|
+
# or with optional eventdata
|
72
|
+
ActiveCampaign.track_event('event-key', 'actid', 'event-name', 'email', 'eventdata')
|
74
73
|
```
|
75
74
|
|
76
75
|
## <a name="contributing">Contributing</a>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module ActiveCampaign
|
2
|
+
class Event
|
3
|
+
|
4
|
+
class << self
|
5
|
+
# Post event
|
6
|
+
def post_event(key, actid, event, email, eventdata=nil)
|
7
|
+
# header = { content_type: 'application/x-www-form-urlencoded' }
|
8
|
+
form = {
|
9
|
+
key: key,
|
10
|
+
actid: actid,
|
11
|
+
event: event,
|
12
|
+
# visit: URI.encode_www_form_component{ email: email },
|
13
|
+
visit: { email: email }
|
14
|
+
}
|
15
|
+
form.merge!({ eventdata: eventdata }) if eventdata
|
16
|
+
|
17
|
+
resp = RestClient.post("https://trackcmp.net/event", form)
|
18
|
+
rescue RestClient::ExceptionWithResponse => err
|
19
|
+
raise APIError, err
|
20
|
+
else
|
21
|
+
return resp.body if resp.body # Some calls respond w nothing
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'active-campaign-simple/exceptions'
|
2
|
+
|
3
|
+
module ActiveCampaign
|
4
|
+
class ExceptionHandler
|
5
|
+
|
6
|
+
ERRORS = {
|
7
|
+
'404 Not Found' => ActiveCampaign::NotFoundError
|
8
|
+
}
|
9
|
+
|
10
|
+
def initialize(error)
|
11
|
+
error_class = ERRORS[error.message]
|
12
|
+
if error_class
|
13
|
+
raise error_class, error
|
14
|
+
else
|
15
|
+
raise ActiveCampaign::StandardError(error)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class ActiveCampaignAPIError < StandardError
|
2
|
+
def initialize(error)
|
3
|
+
ActiveCampaign.api_logger.error "ERROR: #{error}"
|
4
|
+
super(error)
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
module ActiveCampaign
|
9
|
+
class NotFoundError < ActiveCampaignAPIError; end
|
10
|
+
class StandardError < ActiveCampaignAPIError; end
|
11
|
+
end
|
@@ -1,11 +1,12 @@
|
|
1
1
|
require 'rest-client'
|
2
|
-
require 'active-campaign-simple/
|
2
|
+
require 'active-campaign-simple/exception_handler'
|
3
|
+
require 'active-campaign-simple/event'
|
3
4
|
|
4
5
|
module ActiveCampaign
|
5
6
|
module Request
|
6
7
|
# Perform an GET request
|
7
|
-
def get(path)
|
8
|
-
request(:get, path)
|
8
|
+
def get(path, query: {})
|
9
|
+
request(:get, path, {}, query)
|
9
10
|
end
|
10
11
|
|
11
12
|
# Perform an HTTP POST request
|
@@ -28,15 +29,21 @@ module ActiveCampaign
|
|
28
29
|
request(:delete, path)
|
29
30
|
end
|
30
31
|
|
32
|
+
# used for tracking events
|
33
|
+
def track_event(key, actid, event, email, eventdata=nil)
|
34
|
+
Event.post_event(key, actid, event, email, eventdata)
|
35
|
+
end
|
36
|
+
|
31
37
|
private
|
32
38
|
|
33
39
|
# Perform request
|
34
|
-
def request(method, path, payload={})
|
40
|
+
def request(method, path, payload={}, query={})
|
35
41
|
path = "/#{path}" unless path.start_with?('/')
|
42
|
+
path += "?#{URI::encode_www_form(query)}" unless query.empty?
|
36
43
|
header = {
|
37
44
|
'Api-Token': api_key,
|
38
45
|
content_type: :json,
|
39
|
-
accept: :json
|
46
|
+
accept: :json
|
40
47
|
}
|
41
48
|
opts = {
|
42
49
|
method: method,
|
@@ -46,10 +53,10 @@ module ActiveCampaign
|
|
46
53
|
opts.merge!( { payload: payload.to_json }) unless payload.empty?
|
47
54
|
resp = RestClient::Request.execute(opts)
|
48
55
|
rescue RestClient::ExceptionWithResponse => err
|
49
|
-
|
50
|
-
raise APIError, err
|
56
|
+
ActiveCampaign::ExceptionHandler.new(err)
|
51
57
|
else
|
52
58
|
return JSON.parse(resp.body) if resp.body # Some calls respond w nothing
|
53
59
|
end
|
60
|
+
|
54
61
|
end
|
55
62
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active-campaign-simple
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Leavitt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-09-
|
11
|
+
date: 2021-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -51,9 +51,11 @@ files:
|
|
51
51
|
- README.md
|
52
52
|
- active-campaign-simple.gemspec
|
53
53
|
- lib/active-campaign-simple.rb
|
54
|
-
- lib/active-campaign-simple/api_error.rb
|
55
54
|
- lib/active-campaign-simple/client.rb
|
56
55
|
- lib/active-campaign-simple/config.rb
|
56
|
+
- lib/active-campaign-simple/event.rb
|
57
|
+
- lib/active-campaign-simple/exception_handler.rb
|
58
|
+
- lib/active-campaign-simple/exceptions.rb
|
57
59
|
- lib/active-campaign-simple/logger.rb
|
58
60
|
- lib/active-campaign-simple/request.rb
|
59
61
|
- lib/active-campaign-simple/version.rb
|