active-campaign-simple 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e985487ca78df3e1c59d3ab2797a88b166c84a05f4624e22584827619ff531c6
4
+ data.tar.gz: 6bd4487f7ec7b4056c721d01f2d7e74bb069ffc53fc130915bd9cd9db9c3deb3
5
+ SHA512:
6
+ metadata.gz: 7816983565ec399b90bb211f551ac7a5d3ca43519dc00c98b6958fc93e184fd22d3b7cfdcc9eedcc3757bed63fbc1000183079c8f18b0577ee5a1d4302bd8f7b
7
+ data.tar.gz: d916285c529751f1636e3225958f4f09cb162f4ebd6ae0b0ef5471b0a3899137776a8da748682b82097357e808bf1e4e1ae04be07a6b758f3dd84b672769a2f7
data/.gitignore ADDED
@@ -0,0 +1,56 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ # Ignore Byebug command history file.
17
+ .byebug_history
18
+
19
+ ## Specific to RubyMotion:
20
+ .dat*
21
+ .repl_history
22
+ build/
23
+ *.bridgesupport
24
+ build-iPhoneOS/
25
+ build-iPhoneSimulator/
26
+
27
+ ## Specific to RubyMotion (use of CocoaPods):
28
+ #
29
+ # We recommend against adding the Pods directory to your .gitignore. However
30
+ # you should judge for yourself, the pros and cons are mentioned at:
31
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
32
+ #
33
+ # vendor/Pods/
34
+
35
+ ## Documentation cache and generated files:
36
+ /.yardoc/
37
+ /_yardoc/
38
+ /doc/
39
+ /rdoc/
40
+
41
+ ## Environment normalization:
42
+ /.bundle/
43
+ /vendor/bundle
44
+ /lib/bundler/man/
45
+
46
+ # for a library or gem, you might want to ignore these files since the code is
47
+ # intended to run in multiple environments; otherwise, check them in:
48
+ # Gemfile.lock
49
+ # .ruby-version
50
+ # .ruby-gemset
51
+
52
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
53
+ .rvmrc
54
+
55
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
56
+ # .rubocop-https?--*
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 nateleavitt
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # active-campaign-simple
2
+ Simple Ruby REST wrapper for the Active Campaign API
3
+
4
+
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 :)
7
+
8
+ Use the public API as a guide for paths (urls) and payload info: https://developers.activecampaign.com/
9
+
10
+ ## <a name="installation">Installation</a>
11
+ `gem install active-campaign-simple`
12
+
13
+ ## <a name="setup">Config</a>
14
+ 1. add `gem 'active-campaign-simple'` to your `Gemfile`
15
+ 2. Get your API URL and Key from within your application (Settings > Developer)
16
+ 3. Then create an initializer in `config\initializers` called active_campaign.rb and the following
17
+
18
+ ```ruby
19
+ # Added to your config\initializers file
20
+ ActiveCampaign.configure do |config|
21
+ config.api_url = 'YOUR_API_URL'
22
+ config.api_key = 'YOUR_API_KEY'
23
+ config.api_logger = Logger.new("#{Rails.root}/log/active_campaign_api.log") # optional logger file
24
+ end
25
+ ```
26
+
27
+ ## <a name="examples">Examples</a>
28
+
29
+ ```ruby
30
+ # Get a list of contacts
31
+ ActiveCampaign.get('/contacts')
32
+
33
+ # Get a contact
34
+ ActiveCampaign.get('/contacts' + id)
35
+
36
+ # Create a new contact
37
+ # https://developers.activecampaign.com/reference#create-a-contact-new
38
+ payload = {
39
+ contact: {
40
+ email: 'nate@test.com',
41
+ firstName: 'Nate',
42
+ lastName: 'Test',
43
+ phone: '1231231234'
44
+ },
45
+ fieldValues: {
46
+ {
47
+ field: '1',
48
+ value: 'The Value for First Field'
49
+ },
50
+ {
51
+ field: '6',
52
+ value: '2008-01-20'
53
+ }
54
+ }
55
+ }
56
+ ActiveCampaign.post('/contacts', payload: payload)
57
+
58
+ # Update a contact
59
+ payload = {
60
+ contact: {
61
+ email: 'nate@test.com',
62
+ },
63
+ fieldValues: {
64
+ {
65
+ field: '1',
66
+ value: 'The Value for First Field'
67
+ },
68
+ }
69
+ }
70
+ ActiveCampaign.post('/contacts' + id, payload: payload)
71
+
72
+ # Delete a contact
73
+ ActiveCampaign.delete('/contacts' + id)
74
+ ```
75
+
76
+ ## <a name="contributing">Contributing</a>
77
+ In the spirit of [free software](http://www.fsf.org/licensing/essays/free-sw.html), **everyone** is encouraged to help improve this project.
78
+
79
+ See [MIT LICENSE](https://github.com/nateleavitt/active-campaign-simple/blob/master/LICENSE.md) for details.
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+ require File.expand_path('../lib/active-campaign-simple/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = 'active-campaign-simple'
6
+ gem.summary = %q{Simple Ruby REST wrapper for the ActiveCampaign API}
7
+ gem.description = 'Simple Ruby REST wrapper for the ActiveCampaign'
8
+ gem.authors = ["Nathan Leavitt"]
9
+ gem.email = ['nateleavitt@gmail.com']
10
+ gem.license = 'MIT'
11
+ # gem.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.homepage = 'https://github.com/nateleavitt/active-campaign-simple'
14
+ gem.require_paths = ['lib']
15
+ gem.required_rubygems_version = Gem::Requirement.new('>= 3.0.0')
16
+
17
+ gem.add_development_dependency 'rake', '~> 13.0'
18
+ gem.add_dependency 'rest-client', '~> 2.1'
19
+
20
+ gem.version = ActiveCampaign::VERSION.dup
21
+ end
@@ -0,0 +1,21 @@
1
+ require 'active-campaign-simple/config'
2
+ require 'active-campaign-simple/request'
3
+
4
+ module ActiveCampaign
5
+
6
+ class Client
7
+ include Request
8
+
9
+ # attr_accessor :retry_count
10
+ attr_accessor *Config::VALID_OPTION_KEYS
11
+
12
+ def initialize(options={})
13
+ options = ActiveCampaign.options.merge(options)
14
+ Config::VALID_OPTION_KEYS.each do |key|
15
+ send("#{key}=", options[key])
16
+ end
17
+ end
18
+
19
+ end
20
+
21
+ end
@@ -0,0 +1,38 @@
1
+ require 'active-campaign-simple/version'
2
+
3
+ module ActiveCampaign
4
+
5
+ module Config
6
+ # The list of available options
7
+ VALID_OPTION_KEYS = [
8
+ :api_url,
9
+ :api_key,
10
+ :api_logger,
11
+ :user_agent # allows you to change the User-Agent of the request headers
12
+ ].freeze
13
+
14
+ # @private
15
+ attr_accessor *VALID_OPTION_KEYS
16
+
17
+ # Convenience method to allow configuration options to be set in a block
18
+ def configure
19
+ yield self
20
+ end
21
+
22
+ # Create a hash of options and their values
23
+ def options
24
+ options = {}
25
+ VALID_OPTION_KEYS.each{|k| options[k] = send(k)}
26
+ options
27
+ end
28
+
29
+ def user_agent
30
+ @user_agent ||= "active-campaign-simple-#{VERSION} (RubyGem)"
31
+ end
32
+
33
+ def api_logger
34
+ @api_logger || ActiveCampaign::Logger.new
35
+ end
36
+ end
37
+
38
+ end
@@ -0,0 +1,14 @@
1
+ module ActiveCampaign
2
+ class Logger
3
+
4
+ def info(msg); $stdout.puts msg end
5
+
6
+ def warn(msg); $stdout.puts msg end
7
+
8
+ def error(msg); $stdout.puts msg end
9
+
10
+ def debug(msg); $stdout.puts msg end
11
+
12
+ def fatal(msg); $stdout.puts msg end
13
+ end
14
+ end
@@ -0,0 +1,53 @@
1
+ require 'rest-client'
2
+
3
+ module ActiveCampaign
4
+ module Request
5
+ # Perform an GET request
6
+ def get(path)
7
+ request(:get, path)
8
+ end
9
+
10
+ # Perform an HTTP POST request
11
+ def post(path, payload: {})
12
+ request(:post, path, payload)
13
+ end
14
+
15
+ # Perform an HTTP PUT request
16
+ def put(path, payload: {})
17
+ request(:put, path, payload)
18
+ end
19
+
20
+ # Perform an HTTP PATCH request
21
+ def patch(path, payload: {})
22
+ request(:patch, path, payload)
23
+ end
24
+
25
+ # Perform an HTTP DELETE request
26
+ def delete(path)
27
+ request(:delete, path)
28
+ end
29
+
30
+ private
31
+
32
+ # Perform request
33
+ def request(method, path, payload={})
34
+ path = "/#{path}" unless path.start_with?('/')
35
+ header = {
36
+ 'Api-Token': api_key,
37
+ content_type: :json,
38
+ accept: :json,
39
+ }
40
+ opts = {
41
+ method: method,
42
+ url: api_url + '/api/3' + path,
43
+ headers: header
44
+ }
45
+ opts.merge!( { payload: payload.to_json }) unless payload.empty?
46
+ resp = RestClient::Request.execute(opts)
47
+ rescue RestClient::ExceptionWithResponse => err
48
+ # log error?
49
+ else
50
+ return JSON.parse(resp.body) if resp.body # Some calls respond w nothing
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,4 @@
1
+ module ActiveCampaign
2
+ # The version of the gem
3
+ VERSION = '0.1.0'.freeze unless defined?(::ActiveCampaign::VERSION)
4
+ end
@@ -0,0 +1,25 @@
1
+ require 'active-campaign-simple/client'
2
+ require 'active-campaign-simple/config'
3
+ require 'active-campaign-simple/logger'
4
+
5
+ module ActiveCampaign
6
+ extend Config
7
+ class << self
8
+ # Alias for ActiveCampaign::Client.new
9
+ #
10
+ # @return [ActiveCampaign::Client]
11
+ def new(options={})
12
+ ActiveCampaign::Client.new(options)
13
+ end
14
+
15
+ # Delegate to ActiveCampaign::Client
16
+ def method_missing(method, *args, **kwargs)
17
+ return super unless new.respond_to?(method)
18
+ new.send(method, *args, **kwargs)
19
+ end
20
+
21
+ def respond_to?(method, include_private = false)
22
+ new.respond_to?(method, include_private) || super(method, include_private)
23
+ end
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active-campaign-simple
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nathan Leavitt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-09-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '13.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '13.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.1'
41
+ description: Simple Ruby REST wrapper for the ActiveCampaign
42
+ email:
43
+ - nateleavitt@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE
51
+ - README.md
52
+ - active-campaign-simple.gemspec
53
+ - lib/active-campaign-simple.rb
54
+ - lib/active-campaign-simple/client.rb
55
+ - lib/active-campaign-simple/config.rb
56
+ - lib/active-campaign-simple/logger.rb
57
+ - lib/active-campaign-simple/request.rb
58
+ - lib/active-campaign-simple/version.rb
59
+ homepage: https://github.com/nateleavitt/active-campaign-simple
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 3.0.0
77
+ requirements: []
78
+ rubygems_version: 3.2.15
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Simple Ruby REST wrapper for the ActiveCampaign API
82
+ test_files: []