active-campaign-simple 0.2.0 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/lib/active-campaign-simple/event.rb +3 -1
- 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 +7 -6
- data/lib/active-campaign-simple/version.rb +1 -1
- metadata +4 -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: 63e03471fe9ddfffd39e4e000488fcb351e644fb0543eb60c18d1c2ee6efdbe5
|
4
|
+
data.tar.gz: 05f9b1bf283dc9a352c019df3996a839388492befbe99213227f52a36f70364f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6fb592b802a0891f3236cfacc0688ee6165f5f2d14d76009b5bd02ada8eff7eaef8cbbdec9eb9e6cbc048878a198d16a2851df2dbb8abf3d009568fa228e8ed2
|
7
|
+
data.tar.gz: 6df24341d90774d7761ea1791c518abad99a19b0baa91cf041ab75bf6d4e839772678241dc74e619cbff15038179dbbbb940332c133212c7903e1ceeb71e0df3
|
data/README.md
CHANGED
@@ -60,6 +60,9 @@ ActiveCampaign.put('/contacts/' + id, payload: {
|
|
60
60
|
# Delete a contact
|
61
61
|
ActiveCampaign.delete('/contacts/' + id)
|
62
62
|
|
63
|
+
# Search for a contact
|
64
|
+
ActiveCampaign.get('/contacts', query: { email: 'test@test.com' })
|
65
|
+
|
63
66
|
# Event Tracking
|
64
67
|
# See: https://developers.activecampaign.com/reference#track-event
|
65
68
|
# NOTE - The tracking API is different from all other calls as it changes the arguments a little to simplify.
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'active-campaign-simple/exception_handler'
|
2
|
+
|
1
3
|
module ActiveCampaign
|
2
4
|
class Event
|
3
5
|
|
@@ -16,7 +18,7 @@ module ActiveCampaign
|
|
16
18
|
|
17
19
|
resp = RestClient.post("https://trackcmp.net/event", form)
|
18
20
|
rescue RestClient::ExceptionWithResponse => err
|
19
|
-
|
21
|
+
ActiveCampaign::ExceptionHandler.new(err)
|
20
22
|
else
|
21
23
|
return resp.body if resp.body # Some calls respond w nothing
|
22
24
|
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.new(error)
|
14
|
+
else
|
15
|
+
raise ActiveCampaign::APIError.new(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 APIError < ActiveCampaignAPIError; end
|
11
|
+
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'rest-client'
|
2
|
-
require 'active-campaign-simple/
|
2
|
+
require 'active-campaign-simple/exception_handler'
|
3
3
|
require 'active-campaign-simple/event'
|
4
4
|
|
5
5
|
module ActiveCampaign
|
6
6
|
module Request
|
7
7
|
# Perform an GET request
|
8
|
-
def get(path)
|
9
|
-
request(:get, path)
|
8
|
+
def get(path, query: {})
|
9
|
+
request(:get, path, {}, query)
|
10
10
|
end
|
11
11
|
|
12
12
|
# Perform an HTTP POST request
|
@@ -37,12 +37,13 @@ module ActiveCampaign
|
|
37
37
|
private
|
38
38
|
|
39
39
|
# Perform request
|
40
|
-
def request(method, path, payload={})
|
40
|
+
def request(method, path, payload={}, query={})
|
41
41
|
path = "/#{path}" unless path.start_with?('/')
|
42
|
+
path += "?#{URI::encode_www_form(query)}" unless query.empty?
|
42
43
|
header = {
|
43
44
|
'Api-Token': api_key,
|
44
45
|
content_type: :json,
|
45
|
-
accept: :json
|
46
|
+
accept: :json
|
46
47
|
}
|
47
48
|
opts = {
|
48
49
|
method: method,
|
@@ -52,7 +53,7 @@ module ActiveCampaign
|
|
52
53
|
opts.merge!( { payload: payload.to_json }) unless payload.empty?
|
53
54
|
resp = RestClient::Request.execute(opts)
|
54
55
|
rescue RestClient::ExceptionWithResponse => err
|
55
|
-
|
56
|
+
ActiveCampaign::ExceptionHandler.new(err)
|
56
57
|
else
|
57
58
|
return JSON.parse(resp.body) if resp.body # Some calls respond w nothing
|
58
59
|
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.2
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Leavitt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -51,10 +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
|
57
56
|
- lib/active-campaign-simple/event.rb
|
57
|
+
- lib/active-campaign-simple/exception_handler.rb
|
58
|
+
- lib/active-campaign-simple/exceptions.rb
|
58
59
|
- lib/active-campaign-simple/logger.rb
|
59
60
|
- lib/active-campaign-simple/request.rb
|
60
61
|
- lib/active-campaign-simple/version.rb
|