active_campaign 0.1.13 → 0.1.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +9 -3
  3. data/.travis.yml +15 -7
  4. data/Gemfile +3 -2
  5. data/README.md +1 -1
  6. data/active_campaign.gemspec +0 -2
  7. data/lib/active_campaign.rb +16 -8
  8. data/lib/active_campaign/client.rb +11 -15
  9. data/lib/active_campaign/client/campaigns.rb +7 -7
  10. data/lib/active_campaign/client/contacts.rb +9 -11
  11. data/lib/active_campaign/client/deals.rb +7 -7
  12. data/lib/active_campaign/client/forms.rb +5 -5
  13. data/lib/active_campaign/client/groups.rb +7 -7
  14. data/lib/active_campaign/client/lists.rb +12 -10
  15. data/lib/active_campaign/client/messages.rb +7 -7
  16. data/lib/active_campaign/client/tracks.rb +8 -12
  17. data/lib/active_campaign/client/users.rb +6 -11
  18. data/lib/active_campaign/configuration.rb +44 -24
  19. data/lib/active_campaign/core_ext.rb +53 -0
  20. data/lib/active_campaign/version.rb +1 -1
  21. data/spec/cassettes/ActiveCampaign_Client_Contacts/_contact_add/when_successful/returns_1_for_result_code.yml +96 -0
  22. data/spec/cassettes/ActiveCampaign_Client_Contacts/_contact_sync/when_successful/returns_1_for_result_code.yml +96 -0
  23. data/spec/cassettes/ActiveCampaign_Client_Contacts/_contact_view/can_find_contact_by_id.yml +150 -0
  24. data/spec/cassettes/ActiveCampaign_Client_Lists/_list_add/add_a_list.yml +48 -0
  25. data/spec/cassettes/ActiveCampaign_Client_Lists/_list_list/can_find_a_list_of_lists.yml +106 -0
  26. data/spec/cassettes/ActiveCampaign_Client_Lists/_list_view/can_find_lists_by_id.yml +102 -0
  27. data/spec/lib/active_campaign/client/contacts_spec.rb +15 -5
  28. data/spec/lib/active_campaign/client/lists_spec.rb +26 -18
  29. data/spec/lib/active_campaign/client_spec.rb +0 -1
  30. data/spec/lib/active_campaign_spec.rb +2 -2
  31. data/spec/spec_helper.rb +12 -14
  32. data/spec/support/coverage.rb +6 -2
  33. data/spec/support/vcr.rb +7 -5
  34. metadata +15 -40
  35. data/circle.yml +0 -15
  36. data/spec/cassettes/ActiveCampaign_Client_Contacts/_contact_sync/when_successful/returns_1_for_result_code.json +0 -1
  37. data/spec/cassettes/ActiveCampaign_Client_Contacts/_contact_view/can_find_contact_by_id.json +0 -1
  38. data/spec/cassettes/ActiveCampaign_Client_Lists/_list_list/can_find_a_list_of_lists.json +0 -1
  39. data/spec/cassettes/ActiveCampaign_Client_Lists/_list_view/can_find_lists_by_id.json +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 59b2ebc1c3ce763d95f2a26ad53c2a54ffd5dda3
4
- data.tar.gz: 988cceabefff6ebfedec608efb5cd78ab30a798e
3
+ metadata.gz: f959a6cbb68c5711716a5039eaacce4d89e8858d
4
+ data.tar.gz: 5661a144faa672e737d400d37c8b46dccebf9249
5
5
  SHA512:
6
- metadata.gz: 7f6ce075309cef38218ecf1c0537a2a5fbf4d10275d794f65accfe3ed295b0dcf03dd29107fe2ebf27bb4b42562dfee6b8b742d7e83095f7811d7a97c1bd6a31
7
- data.tar.gz: 2efbfed1749f1b37da4599c8a94d88deeeb2c84a76b7294ed67c904123111270c596162a717d324bc103d36617050ed92c742d83ceed125576f45a4fd2d63a2e
6
+ metadata.gz: 492bfc8ce519fa91f47a2a86776a0d5611cba71405fa0a6d8a381b9cbbf63ae20be3b750f95a54b7409d0ebd1cf752e1b64a75ca789fa04539009b1a48a9dc17
7
+ data.tar.gz: 77e704860971e8ee2fc591fc3288a8144ce03dfbb501657eaa0e90c03d663fd9daba04afd313576f7b65516a5d7c217274119d67cf29d3d951ec091631f2fafc
@@ -1,6 +1,12 @@
1
- # AllCops:
2
- # Include:
3
- # Exclude:
1
+ AllCops:
2
+ Include:
3
+ - '**/Rakefile'
4
+ - '**/lib'
5
+ - '**/bin'
6
+ - '**/spec'
7
+ Exclude:
8
+ - 'Gemfile.lock'
9
+ - 'gemfiles/**/*'
4
10
 
5
11
  Documentation:
6
12
  Enabled: false
@@ -1,12 +1,20 @@
1
- bundler_args: --without development
1
+ sudo: false
2
+ language: ruby
3
+ cache: bundler
4
+ before_install:
5
+ - rvm get head
6
+ - gem update --system
7
+ - gem install bundler
2
8
 
3
9
  language: ruby
4
10
 
5
11
  rvm:
6
12
  - jruby-19mode
7
- - rbx-2.1.1
8
- - 1.9.2
9
- - 1.9.3
10
- - 2.0.0
11
- - 2.1.6
12
- - 2.2.2
13
+ - rbx-3
14
+ - 2.1.8
15
+ - 2.2.4
16
+ - 2.3.1
17
+
18
+ addons:
19
+ code_climate:
20
+ repo_token: e199bdc9d2cf5ceaa7e46425f118470e43880940098f815a4c972a923102b12b
data/Gemfile CHANGED
@@ -5,12 +5,13 @@ gem 'rubysl', '~> 2', platform: :rbx
5
5
 
6
6
  group :test do
7
7
  gem 'pry'
8
- gem 'simplecov', '>= 0.9.4'
8
+ gem 'simplecov'
9
+ gem 'simplecov-json'
9
10
  gem 'rubinius-coverage', platform: :rbx
10
11
  gem 'codeclimate-test-reporter', require: false
11
12
  gem 'coveralls', require: false
12
13
  gem 'rb-fsevent'
13
- gem 'rspec', '~> 3.2.0'
14
+ gem 'rspec', '>= 3.2'
14
15
  gem 'vcr'
15
16
  gem 'webmock'
16
17
  gem 'rubocop'
data/README.md CHANGED
@@ -33,7 +33,7 @@ client = ::ActiveCampaign::Client.new(
33
33
  # or configure globally for all clients
34
34
  ::ActiveCampaign.configure do |config|
35
35
  config.api_endpoint = 'YOUR-ENDPOINT', # e.g. 'https://yourendpoint.api-us1.com'
36
- config.api_key = 'YOUR-API-KEY') # e.g. 'a4e60a1ba200595d5cc37ede5732545184165e'
36
+ config.api_key = 'YOUR-API-KEY' # e.g. 'a4e60a1ba200595d5cc37ede5732545184165e'
37
37
  end
38
38
 
39
39
  ```
@@ -19,7 +19,5 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ['lib']
20
20
 
21
21
  spec.add_dependency 'httpi'
22
- spec.add_dependency 'hashie'
23
- spec.add_dependency 'activesupport'
24
22
  spec.add_dependency 'multi_json'
25
23
  end
@@ -1,21 +1,17 @@
1
- require 'active_support'
2
- require 'active_support/core_ext'
3
- require 'active_support/core_ext/module/delegation'
4
1
  require 'active_campaign/version'
5
2
  require 'active_campaign/client'
6
3
  require 'active_campaign/configuration'
4
+ require 'active_campaign/core_ext'
7
5
 
8
6
  module ActiveCampaign
9
- extend Configuration
10
-
11
7
  module_function
12
8
 
13
9
  # API client based on configured options {Configurable}
14
10
  #
15
11
  # @return [ActiveCampaign::Client] API wrapper
16
12
  def client
17
- unless defined?(@client) && @client.same_options?(configuration)
18
- @client = ActiveCampaign::Client.new(configuration)
13
+ unless defined?(@client) && @client.same_options?(config)
14
+ @client = ActiveCampaign::Client.new(config)
19
15
  end
20
16
 
21
17
  @client
@@ -24,13 +20,25 @@ module ActiveCampaign
24
20
  # @private
25
21
  def respond_to_missing?(method_name, include_private = false)
26
22
  client.respond_to?(method_name, include_private)
27
- end if RUBY_VERSION >= '1.9'
23
+ end
28
24
 
29
25
  # @private
30
26
  def respond_to?(method_name, include_private = false)
31
27
  client.respond_to?(method_name, include_private) || super
32
28
  end if RUBY_VERSION < '1.9'
33
29
 
30
+ def config
31
+ @config ||= Configuration.new
32
+ end
33
+
34
+ def configure
35
+ yield config if block_given?
36
+ end
37
+
38
+ def reset!
39
+ @config = Configuration.new
40
+ end
41
+
34
42
  private
35
43
 
36
44
  def method_missing(method_name, *args, &block)
@@ -1,6 +1,4 @@
1
1
  require 'httpi'
2
- require 'hashie'
3
-
4
2
  require 'active_campaign/method_creator'
5
3
 
6
4
  require 'active_campaign/client/campaigns'
@@ -17,6 +15,7 @@ module ActiveCampaign
17
15
  class Client
18
16
  include Comparable
19
17
  extend ActiveCampaign::MethodCreator
18
+ extend Forwardable
20
19
 
21
20
  include ActiveCampaign::Client::Campaigns
22
21
  include ActiveCampaign::Client::Contacts
@@ -28,14 +27,11 @@ module ActiveCampaign
28
27
  include ActiveCampaign::Client::Tracks
29
28
  include ActiveCampaign::Client::Users
30
29
 
31
- delegate :api_key, :api_output, :api_endpoint, :user_agent, :log, :log_level,
32
- :logger, :mash, :debug, to: :config
33
-
34
- attr_accessor :config
30
+ def_delegators :@config, :api_key, :api_output, :api_endpoint,
31
+ :user_agent, :log, :log_level, :logger, :mash, :debug
35
32
 
36
- def initialize(configuration = nil)
37
- self.config = configuration.is_a?(OpenStruct) ? configuration : OpenStruct.new(configuration)
38
- self.config ||= ActiveCampaign.configuration
33
+ def initialize(options = {})
34
+ @config ||= ActiveCampaign.config.merge(options)
39
35
  end
40
36
 
41
37
  # Compares client options to a Hash of requested options
@@ -43,7 +39,7 @@ module ActiveCampaign
43
39
  # @param opts [Hash] Options to compare with current client options
44
40
  # @return [Boolean]
45
41
  def same_options?(other_config)
46
- config.to_h.sort == other_config.to_h.sort
42
+ @config.to_h.sort == other_config.to_h.sort
47
43
  end
48
44
 
49
45
  # Make a HTTP GET request
@@ -56,12 +52,12 @@ module ActiveCampaign
56
52
  end
57
53
 
58
54
  def hash
59
- [config, Client].hash
55
+ [@config, Client].hash
60
56
  end
61
57
 
62
58
  def <=>(other)
63
59
  other.is_a?(ActiveCampaign::Client) &&
64
- config.to_h.sort <=> other.config.to_h.sort
60
+ @config.to_h.sort <=> other.config.to_h.sort
65
61
  end
66
62
 
67
63
  # Make a HTTP POST request
@@ -79,6 +75,7 @@ module ActiveCampaign
79
75
  req = create_request method, api_method, data
80
76
  response = HTTPI.send(method, req)
81
77
  response = JSON.parse(response.body)
78
+
82
79
  normalize(response)
83
80
  end
84
81
 
@@ -119,12 +116,11 @@ module ActiveCampaign
119
116
  def normalize(response)
120
117
  keys, values = keys_values(response)
121
118
  if keys.all? { |key| numeric?(key) }
122
- response[:results] = values
119
+ response['results'] = values
123
120
  keys.each { |key| response.delete(key) }
124
121
  end
125
122
 
126
- return Hashie::Mash.new response if mash
127
- ActiveSupport::HashWithIndifferentAccess.new(response)
123
+ response
128
124
  end
129
125
 
130
126
  def numeric?(string)
@@ -1,21 +1,21 @@
1
1
  module ActiveCampaign
2
2
  class Client
3
3
  module Campaigns
4
- GET_METHODS = %w(
4
+ GET_METHODS ||= %w(
5
5
  create delete_list delete list paginator report_bounce_list
6
6
  report_bounce_totals report_forward_list report_forward_totals
7
7
  report_link_list report_link_totals report_open_list report_open_totals
8
8
  report_totals report_unopen_list report_unsubscription_list
9
9
  report_unsubscription_totals send status
10
- ).freeze unless defined?(GET_METHODS)
11
- POST_METHODS = %w(create).freeze unless defined?(POST_METHODS)
12
-
13
- extend ActiveSupport::Concern
10
+ ).freeze
11
+ POST_METHODS ||= %w(create).freeze
14
12
 
15
13
  # TODO: Create proper methods with parameter validation and possible
16
14
  # naming fixes since this is one the worst APIs I have ever worked with.
17
- included do
18
- define_api_calls(:campaign, GET_METHODS, POST_METHODS)
15
+ def self.included(base)
16
+ base.class_exec do
17
+ define_api_calls(:campaign, GET_METHODS, POST_METHODS)
18
+ end
19
19
  end
20
20
  end
21
21
  end
@@ -1,25 +1,23 @@
1
- require 'active_support'
2
-
3
1
  module ActiveCampaign
4
2
  class Client
5
3
  module Contacts
6
- GET_METHODS = %w(
4
+ GET_METHODS ||= %w(
7
5
  automation_list delete_list delete list paginator view view_email
8
6
  view_hash note_delete
9
- ).freeze unless defined?(GET_METHODS)
7
+ ).freeze
10
8
 
11
- POST_METHODS = %w(
9
+ POST_METHODS ||= %w(
12
10
  add edit sync tag_add tag_remove
13
11
  note_edit note_add
14
- ).freeze unless defined?(POST_METHODS)
15
-
16
- extend ActiveSupport::Concern
12
+ ).freeze
17
13
 
18
14
  # TODO: Create proper methods with parameter validation and possible naming
19
15
  # fixes since this is one the worst APIs I have ever worked with.
20
- included do
21
- %w(contact subscriber).each do |name|
22
- define_api_calls(name, GET_METHODS, POST_METHODS)
16
+ def self.included(base)
17
+ base.class_exec do
18
+ %w(contact subscriber).each do |name|
19
+ define_api_calls(name, GET_METHODS, POST_METHODS)
20
+ end
23
21
  end
24
22
  end
25
23
  end
@@ -1,20 +1,20 @@
1
1
  module ActiveCampaign
2
2
  class Client
3
3
  module Deals
4
- GET_METHODS = %w(get list pipeline_list stage_list).freeze unless defined?(GET_METHODS)
4
+ GET_METHODS ||= %w(get list pipeline_list stage_list).freeze
5
5
 
6
- POST_METHODS = %w(
6
+ POST_METHODS ||= %w(
7
7
  add delete edit note_add note_edit pipeline_add pipeline_delete
8
8
  pipeline_edit stage_add stage_delete stage_edit task_add task_edit
9
9
  tasktype_add tasktype_delete tasktype_edit
10
- ).freeze unless defined?(POST_METHODS)
11
-
12
- extend ActiveSupport::Concern
10
+ ).freeze
13
11
 
14
12
  # TODO: Create proper methods with parameter validation and possible
15
13
  # naming fixes since this is one the worst APIs I have ever worked with.
16
- included do
17
- define_api_calls(:deal, GET_METHODS, POST_METHODS)
14
+ def self.included(base)
15
+ base.class_exec do
16
+ define_api_calls(:deal, GET_METHODS, POST_METHODS)
17
+ end
18
18
  end
19
19
  end
20
20
  end
@@ -1,14 +1,14 @@
1
1
  module ActiveCampaign
2
2
  class Client
3
3
  module Forms
4
- GET_METHODS = %w(getforms html).freeze unless defined?(GET_METHODS)
5
-
6
- extend ActiveSupport::Concern
4
+ GET_METHODS ||= %w(getforms html).freeze
7
5
 
8
6
  # TODO: Create proper methods with parameter validation and possible
9
7
  # naming fixes since this is one the worst APIs I have ever worked with.
10
- included do
11
- define_api_calls(:form, GET_METHODS)
8
+ def self.included(base)
9
+ base.class_exec do
10
+ define_api_calls(:form, GET_METHODS)
11
+ end
12
12
  end
13
13
  end
14
14
  end
@@ -1,18 +1,18 @@
1
1
  module ActiveCampaign
2
2
  class Client
3
3
  module Groups
4
- GET_METHODS = %w(
4
+ GET_METHODS ||= %w(
5
5
  delete delete_list list view
6
- ).freeze unless defined?(GET_METHODS)
6
+ ).freeze
7
7
 
8
- POST_METHODS = %w(add edit) unless defined?(POST_METHODS)
9
-
10
- extend ActiveSupport::Concern
8
+ POST_METHODS ||= %w(add edit).freeze
11
9
 
12
10
  # TODO: Create proper methods with parameter validation and possible
13
11
  # naming fixes since this is one the worst APIs I have ever worked with.
14
- included do
15
- define_api_calls(:group, GET_METHODS, POST_METHODS)
12
+ def self.included(base)
13
+ base.class_exec do
14
+ define_api_calls(:group, GET_METHODS, POST_METHODS)
15
+ end
16
16
  end
17
17
  end
18
18
  end
@@ -1,17 +1,19 @@
1
1
  module ActiveCampaign
2
2
  class Client
3
3
  module Lists
4
- GET_METHODS = %w(
5
- delete_list delete field_add field_delete
6
- field_edit field_view list paginator view
7
- ).freeze unless defined?(GET_METHODS)
8
- POST_METHODS = %w(add edit).freeze unless defined?(POST_METHODS)
9
- DELETE_METHODS = [].freeze unless defined?(DELETE_METHODS)
4
+ GET_METHODS ||= %w(
5
+ delete_list delete field_delete
6
+ field_view list paginator view
7
+ ).freeze
8
+ POST_METHODS ||= %w(
9
+ add edit field_add field_edit
10
+ ).freeze
11
+ DELETE_METHODS ||= [].freeze
10
12
 
11
- extend ActiveSupport::Concern
12
-
13
- included do
14
- define_api_calls(:list, GET_METHODS, POST_METHODS, DELETE_METHODS)
13
+ def self.included(base)
14
+ base.class_exec do
15
+ define_api_calls(:list, GET_METHODS, POST_METHODS, DELETE_METHODS)
16
+ end
15
17
  end
16
18
  end
17
19
  end
@@ -1,20 +1,20 @@
1
1
  module ActiveCampaign
2
2
  class Client
3
3
  module Messages
4
- GET_METHODS = %w(
4
+ GET_METHODS ||= %w(
5
5
  delete_list delete list template_add template_delete_list
6
6
  template_delete template_edit template_export template_import
7
7
  template_list template_view view
8
- ).freeze unless defined?(GET_METHODS)
8
+ ).freeze
9
9
 
10
- POST_METHODS = %w(add edit).freeze unless defined?(POST_METHODS)
11
-
12
- extend ActiveSupport::Concern
10
+ POST_METHODS ||= %w(add edit).freeze
13
11
 
14
12
  # TODO: Create proper methods with parameter validation and possible
15
13
  # naming fixes since this is one the worst APIs I have ever worked with.
16
- included do
17
- define_api_calls(:message, GET_METHODS, POST_METHODS)
14
+ def self.included(base)
15
+ base.class_exec do
16
+ define_api_calls(:message, GET_METHODS, POST_METHODS)
17
+ end
18
18
  end
19
19
  end
20
20
  end
@@ -1,21 +1,17 @@
1
1
  module ActiveCampaign
2
2
  class Client
3
3
  module Tracks
4
- GET_METHODS = %w(event_list site_list).freeze unless defined?(GET_METHODS)
5
- PUT_METHODS = %w(site_whitelist_add).freeze unless defined?(PUT_METHODS)
6
- POST_METHODS = %w(
7
- event_status_edit site_status_edit event_add
8
- ).freeze unless defined?(POST_METHODS)
9
- DELETE_METHODS = %w(
10
- event_delete site_whitelist_delete
11
- ).freeze unless defined?(DELETE_METHODS)
12
-
13
- extend ActiveSupport::Concern
4
+ GET_METHODS ||= %w(event_list site_list).freeze
5
+ PUT_METHODS ||= %w(site_whitelist_add).freeze
6
+ POST_METHODS ||= %w(event_status_edit site_status_edit event_add).freeze
7
+ DELETE_METHODS ||= %w(event_delete site_whitelist_delete).freeze
14
8
 
15
9
  # TODO: Create proper methods with parameter validation and possible
16
10
  # naming fixes since this is one the worst APIs I have ever worked with.
17
- included do
18
- define_api_calls(:track, GET_METHODS, POST_METHODS, DELETE_METHODS, PUT_METHODS)
11
+ def self.included(base)
12
+ base.class_exec do
13
+ define_api_calls(:track, GET_METHODS, POST_METHODS, DELETE_METHODS, PUT_METHODS)
14
+ end
19
15
  end
20
16
  end
21
17
  end