active-campaign-simple 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -24
- 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 +10 -0
- data/lib/active-campaign-simple/request.rb +14 -5
- data/lib/active-campaign-simple/version.rb +2 -2
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be042a9f260af0ab936c9f9e176b775d3883ecf6961dcdddd03c00a1b9930ac3
|
4
|
+
data.tar.gz: 67b23cdbe1ce295350c4e8287b1bfd89d87bdb91a58812f46bc4abedece0fc7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96882a3456a7d0e1a2d7b9cd30b80a6539121b99eead4cca788d9effdab21b05b27c18d8789ef59e87df4e71f60a9bc20afffca790edd093335d830e301be003
|
7
|
+
data.tar.gz: 91f85433ba0183095a36ad378bc6b76d26b0ff8575ce8c453ecbc7f0de07eb6f3b1a9e45c6b0858ff4f8f1fffdaac6389ee00501ab7a8977f5a4703c654ec87a
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@ Simple Ruby REST wrapper for the Active Campaign API
|
|
3
3
|
|
4
4
|
|
5
5
|
## <a name="info">Info</a>
|
6
|
-
This is a very simple wrapper around the REST ActiveCampaign API. You will still need to provide the path and the payload for each request. Eventually I will grow this out to be more convenient. Right now this just provides some conveniences and an easy way to configure the API and not much more... hence the name active-campaign-simple :)
|
6
|
+
This is a very simple wrapper around the REST ActiveCampaign API. You will still need to provide the path and the payload for each request. Eventually I will grow this out to be more convenient, if needed. Right now, this just provides some conveniences and an easy way to configure the API and not much more... hence the name active-campaign-simple :)
|
7
7
|
|
8
8
|
Use the public API as a guide for paths (urls) and payload info: https://developers.activecampaign.com/
|
9
9
|
|
@@ -31,46 +31,45 @@ end
|
|
31
31
|
ActiveCampaign.get('/contacts')
|
32
32
|
|
33
33
|
# Get a contact
|
34
|
-
ActiveCampaign.get('/contacts' + id)
|
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
|
-
ActiveCampaign.delete('/contacts' + id)
|
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 ActiveCampaignAPIError(error)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -1,10 +1,12 @@
|
|
1
1
|
require 'rest-client'
|
2
|
+
require 'active-campaign-simple/exception_handler'
|
3
|
+
require 'active-campaign-simple/event'
|
2
4
|
|
3
5
|
module ActiveCampaign
|
4
6
|
module Request
|
5
7
|
# Perform an GET request
|
6
|
-
def get(path)
|
7
|
-
request(:get, path)
|
8
|
+
def get(path, query: {})
|
9
|
+
request(:get, path, {}, query)
|
8
10
|
end
|
9
11
|
|
10
12
|
# Perform an HTTP POST request
|
@@ -27,15 +29,21 @@ module ActiveCampaign
|
|
27
29
|
request(:delete, path)
|
28
30
|
end
|
29
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
|
+
|
30
37
|
private
|
31
38
|
|
32
39
|
# Perform request
|
33
|
-
def request(method, path, payload={})
|
40
|
+
def request(method, path, payload={}, query={})
|
34
41
|
path = "/#{path}" unless path.start_with?('/')
|
42
|
+
path += "?#{URI::encode_www_form(query)}" unless query.empty?
|
35
43
|
header = {
|
36
44
|
'Api-Token': api_key,
|
37
45
|
content_type: :json,
|
38
|
-
accept: :json
|
46
|
+
accept: :json
|
39
47
|
}
|
40
48
|
opts = {
|
41
49
|
method: method,
|
@@ -45,9 +53,10 @@ module ActiveCampaign
|
|
45
53
|
opts.merge!( { payload: payload.to_json }) unless payload.empty?
|
46
54
|
resp = RestClient::Request.execute(opts)
|
47
55
|
rescue RestClient::ExceptionWithResponse => err
|
48
|
-
|
56
|
+
ActiveCampaign::ExceptionHandler.new(err)
|
49
57
|
else
|
50
58
|
return JSON.parse(resp.body) if resp.body # Some calls respond w nothing
|
51
59
|
end
|
60
|
+
|
52
61
|
end
|
53
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.0
|
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-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -53,6 +53,9 @@ files:
|
|
53
53
|
- lib/active-campaign-simple.rb
|
54
54
|
- lib/active-campaign-simple/client.rb
|
55
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
|
56
59
|
- lib/active-campaign-simple/logger.rb
|
57
60
|
- lib/active-campaign-simple/request.rb
|
58
61
|
- lib/active-campaign-simple/version.rb
|
@@ -75,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
78
|
- !ruby/object:Gem::Version
|
76
79
|
version: 3.0.0
|
77
80
|
requirements: []
|
78
|
-
rubygems_version: 3.2.
|
81
|
+
rubygems_version: 3.2.22
|
79
82
|
signing_key:
|
80
83
|
specification_version: 4
|
81
84
|
summary: Simple Ruby REST wrapper for the ActiveCampaign API
|