active_campaign_wrapper 0.1.0

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.
Files changed (33) hide show
  1. checksums.yaml +7 -0
  2. data/.env.sample +2 -0
  3. data/.gitignore +20 -0
  4. data/.rspec +4 -0
  5. data/.rubocop.yml +6 -0
  6. data/.travis.yml +10 -0
  7. data/CODE_OF_CONDUCT.md +74 -0
  8. data/Gemfile +6 -0
  9. data/LICENSE +21 -0
  10. data/README.md +539 -0
  11. data/Rakefile +21 -0
  12. data/active_campaign_wrapper.gemspec +48 -0
  13. data/bin/console +14 -0
  14. data/bin/setup +8 -0
  15. data/lib/active_campaign_wrapper.rb +21 -0
  16. data/lib/active_campaign_wrapper/api/contact/arguments.rb +18 -0
  17. data/lib/active_campaign_wrapper/api/custom_field/arguments.rb +15 -0
  18. data/lib/active_campaign_wrapper/api/list/arguments.rb +19 -0
  19. data/lib/active_campaign_wrapper/client.rb +73 -0
  20. data/lib/active_campaign_wrapper/configuration.rb +59 -0
  21. data/lib/active_campaign_wrapper/core/contact_automation_gateway.rb +16 -0
  22. data/lib/active_campaign_wrapper/core/contact_gateway.rb +66 -0
  23. data/lib/active_campaign_wrapper/core/contact_score_value_gateway.rb +16 -0
  24. data/lib/active_campaign_wrapper/core/contact_tag_gateway.rb +32 -0
  25. data/lib/active_campaign_wrapper/core/custom_field_gateway.rb +46 -0
  26. data/lib/active_campaign_wrapper/core/custom_field_option_gateway.rb +30 -0
  27. data/lib/active_campaign_wrapper/core/custom_field_value_gateway.rb +44 -0
  28. data/lib/active_campaign_wrapper/core/email_activity_gateway.rb +16 -0
  29. data/lib/active_campaign_wrapper/core/list_gateway.rb +46 -0
  30. data/lib/active_campaign_wrapper/core/tag_gateway.rb +40 -0
  31. data/lib/active_campaign_wrapper/helpers.rb +88 -0
  32. data/lib/active_campaign_wrapper/version.rb +5 -0
  33. metadata +288 -0
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rake'
4
+
5
+ begin
6
+ require 'bundler/setup'
7
+ Bundler::GemHelper.install_tasks
8
+ rescue LoadError
9
+ puts 'although not required, bundler is recommended for running the tests'
10
+ end
11
+
12
+ task default: :spec
13
+
14
+ require 'rspec/core/rake_task'
15
+ RSpec::Core::RakeTask.new(:spec)
16
+
17
+ require 'rubocop/rake_task'
18
+ RuboCop::RakeTask.new do |task|
19
+ task.requires << 'rubocop-performance'
20
+ task.requires << 'rubocop-rspec'
21
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/active_campaign_wrapper/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'active_campaign_wrapper'
7
+ spec.version = ActiveCampaignWrapper::VERSION
8
+ spec.authors = ['Anmol Yousaf']
9
+ spec.email = ['anmolyousaf94@gmail.com']
10
+
11
+ spec.summary = %q{REST API for ActiveCampaign}
12
+ spec.description = %q{ActiveCampaign REST API}
13
+ spec.homepage = 'https://github.com/anmol-yousaf/active_campaign_wrapper'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
16
+
17
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org/'
18
+
19
+ spec.metadata['homepage_uri'] = spec.homepage
20
+ spec.metadata['source_code_uri'] = 'https://github.com/anmol-yousaf/active_campaign_wrapper'
21
+ spec.metadata['changelog_uri'] = 'https://github.com/anmol-yousaf/active_campaign_wrapper'
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ end
28
+ spec.bindir = 'exe'
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ['lib']
31
+
32
+ spec.add_dependency 'activesupport', '>= 5.2.4.3'
33
+ spec.add_dependency 'httparty', '>= 0.14'
34
+
35
+ spec.add_development_dependency 'bundler', '~> 2.1.4'
36
+ spec.add_development_dependency 'codecov', '~> 0.1'
37
+ spec.add_development_dependency 'dotenv', '~> 2.5'
38
+ spec.add_development_dependency 'pry', '~> 0.14.0'
39
+ spec.add_development_dependency 'rake', '~> 13.0'
40
+ spec.add_development_dependency 'rspec', '~> 3.10.0'
41
+ spec.add_development_dependency 'rspec-json_expectations', '~> 1.2'
42
+ spec.add_development_dependency 'rubocop', '~> 1.11.0'
43
+ spec.add_development_dependency 'rubocop-performance', '~> 1.5'
44
+ spec.add_development_dependency 'rubocop-rspec', '~> 1.37'
45
+ spec.add_development_dependency 'simplecov', '~> 0.16'
46
+ spec.add_development_dependency 'vcr', '~> 6.0.0'
47
+ spec.add_development_dependency 'webmock', '~> 3.12.1'
48
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "active_campaign_wrapper"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'httparty'
4
+ require 'active_campaign_wrapper/version'
5
+ require 'active_campaign_wrapper/client'
6
+
7
+ module ActiveCampaignWrapper
8
+ API_VERSION = 3
9
+
10
+ class << self
11
+ attr_accessor :api_token, :endpoint_url
12
+
13
+ def config
14
+ yield self
15
+ end
16
+ end
17
+
18
+ class Error < StandardError; end
19
+
20
+ class AuthorizationError < StandardError; end
21
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveCampaignWrapper
4
+ module Api
5
+ module Contact
6
+ module Arguments
7
+ SNAKE_CASED = {
8
+ bulk_import: %i[
9
+ first_name
10
+ last_name
11
+ customer_acct_name
12
+ detailed_results
13
+ ]
14
+ }.freeze
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveCampaignWrapper
4
+ module Api
5
+ module CustomField
6
+ module Arguments
7
+ SNAKE_CASED = {
8
+ create: %i[
9
+ show_in_list
10
+ ]
11
+ }.freeze
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveCampaignWrapper
4
+ module Api
5
+ module List
6
+ module Arguments
7
+ SNAKE_CASED = {
8
+ create: %i[
9
+ sender_url
10
+ sender_reminder
11
+ send_last_broadcast
12
+ subscription_notify
13
+ unsubscription_notify
14
+ ]
15
+ }.freeze
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_campaign_wrapper/configuration'
4
+
5
+ require 'active_campaign_wrapper/core/tag_gateway'
6
+ require 'active_campaign_wrapper/core/contact_gateway'
7
+ require 'active_campaign_wrapper/core/email_activity_gateway'
8
+ require 'active_campaign_wrapper/core/list_gateway'
9
+ require 'active_campaign_wrapper/core/custom_field_gateway'
10
+ require 'active_campaign_wrapper/core/custom_field_option_gateway'
11
+ require 'active_campaign_wrapper/core/custom_field_value_gateway'
12
+ require 'active_campaign_wrapper/core/contact_tag_gateway'
13
+ require 'active_campaign_wrapper/core/contact_automation_gateway'
14
+ require 'active_campaign_wrapper/core/contact_score_value_gateway'
15
+
16
+ require 'active_campaign_wrapper/api/contact/arguments'
17
+ require 'active_campaign_wrapper/api/list/arguments'
18
+ require 'active_campaign_wrapper/api/custom_field/arguments'
19
+
20
+ module ActiveCampaignWrapper
21
+ class Client
22
+ include Core
23
+
24
+ attr_reader :config
25
+
26
+ def initialize(endpoint_url: nil, api_token: nil)
27
+ @config = Configuration.new(
28
+ endpoint_url: endpoint_url,
29
+ api_token: api_token
30
+ )
31
+ end
32
+
33
+ def tags
34
+ TagGateway.new(self)
35
+ end
36
+
37
+ def contacts
38
+ ContactGateway.new(self)
39
+ end
40
+
41
+ def email_activities
42
+ EmailActivityGateway.new(self)
43
+ end
44
+
45
+ def contact_tags
46
+ ContactTagGateway.new(self)
47
+ end
48
+
49
+ def contact_score_values
50
+ ContactScoreValueGateway.new(self)
51
+ end
52
+
53
+ def contact_automations
54
+ ContactAutomationGateway.new(self)
55
+ end
56
+
57
+ def custom_fields
58
+ CustomFieldGateway.new(self)
59
+ end
60
+
61
+ def custom_field_options
62
+ CustomFieldOptionGateway.new(self)
63
+ end
64
+
65
+ def custom_field_values
66
+ CustomFieldValueGateway.new(self)
67
+ end
68
+
69
+ def lists
70
+ ListGateway.new(self)
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_campaign_wrapper/helpers'
4
+
5
+ module ActiveCampaignWrapper
6
+ class Configuration
7
+ include HTTParty
8
+ include Helpers
9
+
10
+ attr_accessor :endpoint_url, :api_token
11
+
12
+ format :json
13
+
14
+ def initialize(endpoint_url: nil, api_token: nil)
15
+ @endpoint_url = endpoint_url.presence || ActiveCampaignWrapper.endpoint_url
16
+ @api_token = api_token.presence || ActiveCampaignWrapper.api_token
17
+
18
+ self.class.base_uri "#{@endpoint_url}/api/#{ActiveCampaignWrapper::API_VERSION}"
19
+ self.class.default_options.merge! headers: { api_token: @api_token }
20
+ end
21
+
22
+ def post(*args)
23
+ safe_http_call do
24
+ self.class.post(*args)
25
+ end
26
+ end
27
+
28
+ def patch(*args)
29
+ safe_http_call do
30
+ self.class.patch(*args)
31
+ end
32
+ end
33
+
34
+ def put(*args)
35
+ safe_http_call do
36
+ self.class.put(*args)
37
+ end
38
+ end
39
+
40
+ def delete(*args)
41
+ safe_http_call do
42
+ self.class.delete(*args)
43
+ end
44
+ end
45
+
46
+ def get(*args)
47
+ safe_http_call do
48
+ self.class.get(*args)
49
+ end
50
+ end
51
+
52
+ private
53
+
54
+ def safe_http_call
55
+ response = yield
56
+ normalize_response(response)
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveCampaignWrapper
4
+ module Core
5
+ class ContactAutomationGateway
6
+ def initialize(client)
7
+ @client = client
8
+ @config = client.config
9
+ end
10
+
11
+ def all(contact_id, **params)
12
+ @config.get("/contacts/#{contact_id}/contactAutomations", query: params)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveCampaignWrapper
4
+ module Core
5
+ class ContactGateway
6
+ def initialize(client)
7
+ @client = client
8
+ @config = client.config
9
+ end
10
+
11
+ def all(**params)
12
+ @config.get('/contacts', query: params)
13
+ end
14
+
15
+ def create(params)
16
+ params = { contact: params }
17
+ @config.post(
18
+ '/contacts',
19
+ body: ActiveCampaignWrapper::Helpers.normalize_body(params)
20
+ )
21
+ end
22
+
23
+ def sync(params)
24
+ params = { contact: params }
25
+ @config.post(
26
+ '/contact/sync',
27
+ body: ActiveCampaignWrapper::Helpers.normalize_body(params)
28
+ )
29
+ end
30
+
31
+ def update_list_status(params)
32
+ params = { contact_list: params }
33
+ @config.post(
34
+ '/contactLists',
35
+ body: ActiveCampaignWrapper::Helpers.normalize_body(params)
36
+ )
37
+ end
38
+
39
+ def bulk_import(params)
40
+ @config.post(
41
+ '/import/bulk_import',
42
+ body: ActiveCampaignWrapper::Helpers.normalize_body(
43
+ params,
44
+ ActiveCampaignWrapper::Api::Contact::Arguments::SNAKE_CASED[:bulk_import]
45
+ )
46
+ )
47
+ end
48
+
49
+ def delete(contact_id)
50
+ @config.delete("/contacts/#{contact_id}")
51
+ end
52
+
53
+ def update(contact_id, params)
54
+ params = { contact: params }
55
+ @config.put(
56
+ "/contacts/#{contact_id}",
57
+ body: ActiveCampaignWrapper::Helpers.normalize_body(params)
58
+ )
59
+ end
60
+
61
+ def find(contact_id)
62
+ @config.get("/contacts/#{contact_id}")
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveCampaignWrapper
4
+ module Core
5
+ class ContactScoreValueGateway
6
+ def initialize(client)
7
+ @client = client
8
+ @config = client.config
9
+ end
10
+
11
+ def all(contact_id, **params)
12
+ @config.get("/contacts/#{contact_id}/scoreValues", query: params)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveCampaignWrapper
4
+ module Core
5
+ class ContactTagGateway
6
+ def initialize(client)
7
+ @client = client
8
+ @config = client.config
9
+ end
10
+
11
+ def all(contact_id, **params)
12
+ @config.get("/contacts/#{contact_id}/contactTags", query: params)
13
+ end
14
+
15
+ def create(params)
16
+ params = { contact_tag: params }
17
+ @config.post(
18
+ '/contactTags',
19
+ body: ActiveCampaignWrapper::Helpers.normalize_body(params)
20
+ )
21
+ end
22
+
23
+ def delete(contact_tag_id)
24
+ @config.delete("/contactTags/#{contact_tag_id}")
25
+ end
26
+
27
+ def find(contact_tag_id)
28
+ @config.get("/contactTags/#{contact_tag_id}")
29
+ end
30
+ end
31
+ end
32
+ end