active_campaign 0.1.10 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f49cb05b48c6d485e7aeef4c124e5ffc4a497065
4
- data.tar.gz: eb82879f1a6a707ee4ca92a66ef0220b07e60048
3
+ metadata.gz: 59b2ebc1c3ce763d95f2a26ad53c2a54ffd5dda3
4
+ data.tar.gz: 988cceabefff6ebfedec608efb5cd78ab30a798e
5
5
  SHA512:
6
- metadata.gz: 920f478ce29086f94efdd3787be205f81b7b4118bf48ca1cd2d23c3470afaa98f7939b7e9cc02a0aace15097c871116ee780bb7e91c47e9cecedb95c52a4d70c
7
- data.tar.gz: 2177d9dc0f1b73e32edf76cbd96a56d4bb2dc3354be9d3c223338d1a06bec2dfacdb137d77dca1e64a4b217f721af4c217db4bc9ef164f2bda2b5fa871e1e74a
6
+ metadata.gz: 7f6ce075309cef38218ecf1c0537a2a5fbf4d10275d794f65accfe3ed295b0dcf03dd29107fe2ebf27bb4b42562dfee6b8b742d7e83095f7811d7a97c1bd6a31
7
+ data.tar.gz: 2efbfed1749f1b37da4599c8a94d88deeeb2c84a76b7294ed67c904123111270c596162a717d324bc103d36617050ed92c742d83ceed125576f45a4fd2d63a2e
@@ -1 +1 @@
1
- repo_token: 9QHPyeb961SRsyxDttIHmzVNhXvP1RJKr
1
+ repo_token: x7iG9NiJ5Q9TkQMy6m8QFXpmmrV42uPvj
@@ -0,0 +1,15 @@
1
+ # 0.1.12
2
+ - Allow ActiveCampaign::Client.new to accept a Hash
3
+
4
+ # 0.1.11
5
+ - Adds Deals
6
+ - Adds Forms
7
+ - Adds Groups
8
+ - Adds Users
9
+ - Adds Tracks
10
+ - Adds Campaigns
11
+
12
+ # 0.1.10
13
+ - Added tagging of lists and contacts
14
+ - Internally: Upgraded gems and RSpec syntax
15
+ - Internally: Added rubocop
data/Gemfile CHANGED
@@ -1,12 +1,10 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ gem 'rake'
3
4
  gem 'rubysl', '~> 2', platform: :rbx
4
5
 
5
- group :development do
6
- gem 'pry', platform: :mri
7
- end
8
-
9
6
  group :test do
7
+ gem 'pry'
10
8
  gem 'simplecov', '>= 0.9.4'
11
9
  gem 'rubinius-coverage', platform: :rbx
12
10
  gem 'codeclimate-test-reporter', require: false
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Circle CI](https://circleci.com/gh/RushPlay/active_campaign.png?circle-token=908def2d4311fcbe28d2caabccaa703e2835cf37)](https://circleci.com/gh/RushPlay/active_campaign/tree/master)[![Coverage Status](https://coveralls.io/repos/RushPlay/active_campaign/badge.png?branch=master)](https://coveralls.io/r/RushPlay/active_campaign?branch=master) [![Code Climate](https://codeclimate.com/repos/525d012ec7f3a335f101a3d6/badges/74d14b105bf9f769f10f/gpa.png)](https://codeclimate.com/repos/525d012ec7f3a335f101a3d6/feed)
1
+ [![Circle CI](https://circleci.com/gh/RushPlay/active_campaign.png?circle-token=908def2d4311fcbe28d2caabccaa703e2835cf37)](https://circleci.com/gh/RushPlay/active_campaign/tree/master)[![Coverage Status](https://coveralls.io/repos/mhenrixon/active_campaign/badge.svg)](https://coveralls.io/r/mhenrixon/active_campaign) [![Code Climate](https://codeclimate.com/repos/525d012ec7f3a335f101a3d6/badges/74d14b105bf9f769f10f/gpa.png)](https://codeclimate.com/repos/525d012ec7f3a335f101a3d6/feed)
2
2
  # Active::Campaign::Ruby
3
3
 
4
4
  A simple wrapper for the ActiveCampaign API. Since their API seems to be
@@ -46,7 +46,8 @@ ActiveCampaign.list_list ids: 'all'
46
46
 
47
47
  ```ruby
48
48
  # To sync a contact (create if doesn't exist or update if matching email)
49
- # you have to resort to some really ugly hacks. Due to the form serialization # type of API (read not a object oriented REST API) you need to translate
49
+ # you have to resort to some really ugly hacks. Due to the form serialization
50
+ # type of API (read not a object oriented REST API) you need to translate
50
51
  # something pretty into something horrific when it comes to the parameters.
51
52
  ActiveCampaign.contact_sync({
52
53
  "id" => user.active_campaign_contact_id,
data/circle.yml CHANGED
@@ -6,7 +6,6 @@ dependencies:
6
6
  bundler:
7
7
  without: [production, staging, benchmarking]
8
8
  cache_directories:
9
- - vendor/bundle_java
10
9
  - vendor/bundle
11
10
  override:
12
11
  - rvm-exec 2.2.2 bundle install
@@ -1,6 +1,7 @@
1
1
  require 'active_support'
2
2
  require 'active_support/core_ext'
3
3
  require 'active_support/core_ext/module/delegation'
4
+ require 'active_campaign/version'
4
5
  require 'active_campaign/client'
5
6
  require 'active_campaign/configuration'
6
7
 
@@ -1,16 +1,32 @@
1
1
  require 'httpi'
2
2
  require 'hashie'
3
3
 
4
+ require 'active_campaign/method_creator'
5
+
6
+ require 'active_campaign/client/campaigns'
4
7
  require 'active_campaign/client/contacts'
8
+ require 'active_campaign/client/deals'
9
+ require 'active_campaign/client/forms'
10
+ require 'active_campaign/client/groups'
5
11
  require 'active_campaign/client/lists'
6
- require 'active_campaign/client/campaigns'
12
+ require 'active_campaign/client/messages'
13
+ require 'active_campaign/client/tracks'
14
+ require 'active_campaign/client/users'
7
15
 
8
16
  module ActiveCampaign
9
17
  class Client
10
18
  include Comparable
19
+ extend ActiveCampaign::MethodCreator
20
+
21
+ include ActiveCampaign::Client::Campaigns
11
22
  include ActiveCampaign::Client::Contacts
23
+ include ActiveCampaign::Client::Deals
24
+ include ActiveCampaign::Client::Forms
25
+ include ActiveCampaign::Client::Groups
12
26
  include ActiveCampaign::Client::Lists
13
- include ActiveCampaign::Client::Campaigns
27
+ include ActiveCampaign::Client::Messages
28
+ include ActiveCampaign::Client::Tracks
29
+ include ActiveCampaign::Client::Users
14
30
 
15
31
  delegate :api_key, :api_output, :api_endpoint, :user_agent, :log, :log_level,
16
32
  :logger, :mash, :debug, to: :config
@@ -18,7 +34,7 @@ module ActiveCampaign
18
34
  attr_accessor :config
19
35
 
20
36
  def initialize(configuration = nil)
21
- self.config = configuration
37
+ self.config = configuration.is_a?(OpenStruct) ? configuration : OpenStruct.new(configuration)
22
38
  self.config ||= ActiveCampaign.configuration
23
39
  end
24
40
 
@@ -1,29 +1,21 @@
1
1
  module ActiveCampaign
2
2
  class Client
3
3
  module Campaigns
4
- CONTACT_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
- )
11
- CONTACT_POST_METHODS = %w(create)
10
+ ).freeze unless defined?(GET_METHODS)
11
+ POST_METHODS = %w(create).freeze unless defined?(POST_METHODS)
12
12
 
13
13
  extend ActiveSupport::Concern
14
14
 
15
15
  # TODO: Create proper methods with parameter validation and possible
16
16
  # naming fixes since this is one the worst APIs I have ever worked with.
17
17
  included do
18
- CONTACT_METHODS.each do |method|
19
- define_method "campaign_#{method}" do |options|
20
- if CONTACT_POST_METHODS.include?(method)
21
- post __method__, options
22
- else
23
- get __method__, options
24
- end
25
- end
26
- end
18
+ define_api_calls(:campaign, GET_METHODS, POST_METHODS)
27
19
  end
28
20
  end
29
21
  end
@@ -3,11 +3,15 @@ require 'active_support'
3
3
  module ActiveCampaign
4
4
  class Client
5
5
  module Contacts
6
- CONTACT_METHODS = %w(
7
- add automation_list delete_list delete edit list paginator
8
- sync view view_email view_hash tag_add tag_remove
9
- )
10
- CONTACT_POST_METHODS = %w(add edit sync tag_add tag_remove)
6
+ GET_METHODS = %w(
7
+ automation_list delete_list delete list paginator view view_email
8
+ view_hash note_delete
9
+ ).freeze unless defined?(GET_METHODS)
10
+
11
+ POST_METHODS = %w(
12
+ add edit sync tag_add tag_remove
13
+ note_edit note_add
14
+ ).freeze unless defined?(POST_METHODS)
11
15
 
12
16
  extend ActiveSupport::Concern
13
17
 
@@ -15,15 +19,7 @@ module ActiveCampaign
15
19
  # fixes since this is one the worst APIs I have ever worked with.
16
20
  included do
17
21
  %w(contact subscriber).each do |name|
18
- CONTACT_METHODS.each do |method|
19
- define_method "#{name}_#{method}" do |options|
20
- if CONTACT_POST_METHODS.include?(method)
21
- post __method__, options
22
- else
23
- get __method__, options
24
- end
25
- end
26
- end
22
+ define_api_calls(name, GET_METHODS, POST_METHODS)
27
23
  end
28
24
  end
29
25
  end
@@ -0,0 +1,21 @@
1
+ module ActiveCampaign
2
+ class Client
3
+ module Deals
4
+ GET_METHODS = %w(get list pipeline_list stage_list).freeze unless defined?(GET_METHODS)
5
+
6
+ POST_METHODS = %w(
7
+ add delete edit note_add note_edit pipeline_add pipeline_delete
8
+ pipeline_edit stage_add stage_delete stage_edit task_add task_edit
9
+ tasktype_add tasktype_delete tasktype_edit
10
+ ).freeze unless defined?(POST_METHODS)
11
+
12
+ extend ActiveSupport::Concern
13
+
14
+ # TODO: Create proper methods with parameter validation and possible
15
+ # 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)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ module ActiveCampaign
2
+ class Client
3
+ module Forms
4
+ GET_METHODS = %w(getforms html).freeze unless defined?(GET_METHODS)
5
+
6
+ extend ActiveSupport::Concern
7
+
8
+ # TODO: Create proper methods with parameter validation and possible
9
+ # naming fixes since this is one the worst APIs I have ever worked with.
10
+ included do
11
+ define_api_calls(:form, GET_METHODS)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ module ActiveCampaign
2
+ class Client
3
+ module Groups
4
+ GET_METHODS = %w(
5
+ delete delete_list list view
6
+ ).freeze unless defined?(GET_METHODS)
7
+
8
+ POST_METHODS = %w(add edit) unless defined?(POST_METHODS)
9
+
10
+ extend ActiveSupport::Concern
11
+
12
+ # TODO: Create proper methods with parameter validation and possible
13
+ # 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)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,24 +1,17 @@
1
1
  module ActiveCampaign
2
2
  class Client
3
3
  module Lists
4
- LIST_API_METHODS = %w(
5
- add delete_list delete edit field_add field_delete
4
+ GET_METHODS = %w(
5
+ delete_list delete field_add field_delete
6
6
  field_edit field_view list paginator view
7
- )
8
- LIST_POST_METHODS = %w(add edit)
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)
9
10
 
10
11
  extend ActiveSupport::Concern
11
12
 
12
13
  included do
13
- LIST_API_METHODS.each do |method|
14
- define_method "list_#{method}" do |options|
15
- if LIST_POST_METHODS.include?(method)
16
- post __method__, options
17
- else
18
- get __method__, options
19
- end
20
- end
21
- end
14
+ define_api_calls(:list, GET_METHODS, POST_METHODS, DELETE_METHODS)
22
15
  end
23
16
  end
24
17
  end
@@ -1,27 +1,20 @@
1
1
  module ActiveCampaign
2
2
  class Client
3
3
  module Messages
4
- CONTACT_METHODS = %w(
5
- add delete_list delete edit list template_add template_delete_list
4
+ GET_METHODS = %w(
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
- )
9
- CONTACT_POST_METHODS = %w(add edit)
8
+ ).freeze unless defined?(GET_METHODS)
9
+
10
+ POST_METHODS = %w(add edit).freeze unless defined?(POST_METHODS)
10
11
 
11
12
  extend ActiveSupport::Concern
12
13
 
13
14
  # TODO: Create proper methods with parameter validation and possible
14
15
  # naming fixes since this is one the worst APIs I have ever worked with.
15
16
  included do
16
- CONTACT_METHODS.each do |method|
17
- define_method "contact_#{method}" do |options|
18
- if CONTACT_POST_METHODS.include?(method)
19
- post __method__, options
20
- else
21
- get __method__, options
22
- end
23
- end
24
- end
17
+ define_api_calls(:message, GET_METHODS, POST_METHODS)
25
18
  end
26
19
  end
27
20
  end
@@ -0,0 +1,22 @@
1
+ module ActiveCampaign
2
+ class Client
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
14
+
15
+ # TODO: Create proper methods with parameter validation and possible
16
+ # 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)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ require 'active_support'
2
+
3
+ module ActiveCampaign
4
+ class Client
5
+ module Users
6
+ GET_METHODS = %w(
7
+ delete delete_list list me view view_email view_username
8
+ ).freeze unless defined?(GET_METHODS)
9
+
10
+ POST_METHODS = %w(add edit).freeze unless defined?(POST_METHODS)
11
+
12
+ extend ActiveSupport::Concern
13
+
14
+ # TODO: Create proper methods with parameter validation and possible naming
15
+ # fixes since this is one the worst APIs I have ever worked with.
16
+ included do
17
+ define_api_calls(:user, GET_METHODS, POST_METHODS)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,32 @@
1
+ module ActiveCampaign
2
+ module MethodCreator
3
+ def define_api_calls(resource, gets = [], posts = [], deletes = [], puts = [])
4
+ gets.each { |method| define_get_method(resource, method) }
5
+ posts.each { |method| define_post_method(resource, method) }
6
+ deletes.each { |method| define_delete_method(resource, method) }
7
+ puts.each { |method| define_put_method(resource, method) }
8
+ end
9
+
10
+ def define_get_method(resource, call)
11
+ define_api_method(:get, resource, call)
12
+ end
13
+
14
+ def define_post_method(resource, call)
15
+ define_api_method(:post, resource, call)
16
+ end
17
+
18
+ def define_delete_method(resource, call)
19
+ define_api_method(:delete, resource, call)
20
+ end
21
+
22
+ def define_put_method(resource, call)
23
+ define_api_method(:put, resource, call)
24
+ end
25
+
26
+ def define_api_method(method, resource, call)
27
+ define_method "#{resource}_#{call}" do |options = {}|
28
+ send(method, __method__, options)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,3 +1,3 @@
1
1
  module ActiveCampaign
2
- VERSION = '0.1.10'
2
+ VERSION = '0.1.13'
3
3
  end
@@ -2,5 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  module ActiveCampaign
4
4
  describe Client do
5
+
5
6
  end
6
7
  end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveCampaign do
4
+ # rubocop:disable LineLength
5
+ API_CALLS = %w(
6
+ campaign_create campaign_delete campaign_delete_list campaign_list campaign_paginator campaign_report_bounce_list campaign_report_bounce_totals campaign_report_forward_list campaign_report_forward_totals campaign_report_link_list campaign_report_link_totals campaign_report_open_list campaign_report_open_totals campaign_report_totals campaign_report_unopen_list campaign_report_unsubscription_list campaign_report_unsubscription_totals campaign_send campaign_status
7
+ contact_add contact_automation_list contact_delete contact_delete_list contact_edit contact_list contact_note_add contact_note_delete contact_note_edit contact_paginator contact_sync contact_tag_add contact_tag_remove contact_view contact_view_email contact_view_hash
8
+ deal_add deal_delete deal_edit deal_get deal_list deal_note_add deal_note_edit deal_pipeline_add deal_pipeline_delete deal_pipeline_edit deal_pipeline_list deal_stage_add deal_stage_delete deal_stage_edit deal_stage_list deal_task_add deal_task_edit deal_tasktype_add deal_tasktype_delete deal_tasktype_edit
9
+ form_getforms form_html
10
+ group_add group_delete group_delete_list group_edit group_list group_view
11
+ list_add list_delete list_delete_list list_edit list_field_add list_field_delete list_field_edit list_field_view list_list list_paginator list_view
12
+ message_add message_delete message_delete_list message_edit message_list message_template_add message_template_delete message_template_delete_list message_template_edit message_template_export message_template_import message_template_list message_template_view message_view
13
+ user_add user_delete user_delete_list user_edit user_list user_me user_view user_view_email user_view_username
14
+ track_event_delete track_event_list track_event_status_edit track_site_list track_site_status_edit track_site_whitelist_add track_site_whitelist_delete track_event_add
15
+ ).freeze unless defined?(API_CALLS)
16
+ # rubocop:enable LineLength
17
+
18
+ before do
19
+ ActiveCampaign.reset!
20
+ end
21
+
22
+ after do
23
+ ActiveCampaign.reset!
24
+ end
25
+
26
+ describe 'api_calls' do
27
+ API_CALLS.each do |call|
28
+ specify { expect(ActiveCampaign).to respond_to(call) }
29
+ end
30
+ end
31
+
32
+ describe '.client' do
33
+ it 'creates an ActiveCampaign::Client' do
34
+ expect(ActiveCampaign.client).to be_kind_of ActiveCampaign::Client
35
+ end
36
+
37
+ it 'caches the client when the same options are passed' do
38
+ expect(ActiveCampaign.client).to eq ActiveCampaign.client
39
+ end
40
+
41
+ it 'returns a fresh client when options are not the same' do
42
+ client = ActiveCampaign.client
43
+ ActiveCampaign.config.api_key = 'somekey'
44
+ client_two = ActiveCampaign.client
45
+ client_three = ActiveCampaign.client
46
+ expect(client_three).to eql client_two
47
+ expect(client).to_not eql client_two
48
+ end
49
+ end
50
+
51
+ describe '.configure' do
52
+ ActiveCampaign.config.to_h.keys.each do |key|
53
+ it "sets the #{key.to_s.gsub('_', ' ')}" do
54
+ ActiveCampaign.configure do |config|
55
+ config.send("#{key}=", key)
56
+ end
57
+ expect(ActiveCampaign.configuration[key]).to eq key
58
+ end
59
+ end
60
+ end
61
+ end
@@ -28,19 +28,14 @@ end
28
28
 
29
29
  def initialize_new_client
30
30
  before do
31
- initialize_active_campaign
32
- @client = ActiveCampaign::Client.new
33
- end
34
- end
35
-
36
- def initialize_active_campaign
37
- ActiveCampaign.configure do |config|
38
- config.api_endpoint = test_api_endpoint
39
- config.api_key = test_api_key
40
- config.api_output = 'json'
41
- config.debug = false
42
- config.log_level = :fatal
43
- config.log = false
44
- config.mash = true
31
+ @client = ActiveCampaign::Client.new(
32
+ api_endpoint: test_api_endpoint,
33
+ api_key: test_api_key,
34
+ api_output: 'json',
35
+ debug: false,
36
+ log_level: :fatal,
37
+ log: false,
38
+ mash: true
39
+ )
45
40
  end
46
41
  end
@@ -1,5 +1,7 @@
1
1
  require 'simplecov'
2
2
  require 'coveralls'
3
+ Coveralls.wear!
4
+
3
5
  require 'codeclimate-test-reporter'
4
6
  formatters = [SimpleCov::Formatter::HTMLFormatter, Coveralls::SimpleCov::Formatter]
5
7
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_campaign
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikael Henriksson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-13 00:00:00.000000000 Z
11
+ date: 2015-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpi
@@ -80,6 +80,7 @@ files:
80
80
  - ".rubocop.yml"
81
81
  - ".ruby-version"
82
82
  - ".travis.yml"
83
+ - Changelog.md
83
84
  - Gemfile
84
85
  - LICENSE.txt
85
86
  - README.md
@@ -90,22 +91,27 @@ files:
90
91
  - lib/active_campaign/client.rb
91
92
  - lib/active_campaign/client/campaigns.rb
92
93
  - lib/active_campaign/client/contacts.rb
94
+ - lib/active_campaign/client/deals.rb
95
+ - lib/active_campaign/client/forms.rb
96
+ - lib/active_campaign/client/groups.rb
93
97
  - lib/active_campaign/client/lists.rb
94
98
  - lib/active_campaign/client/messages.rb
99
+ - lib/active_campaign/client/tracks.rb
100
+ - lib/active_campaign/client/users.rb
95
101
  - lib/active_campaign/configuration.rb
96
- - lib/active_campaign/error.rb
102
+ - lib/active_campaign/method_creator.rb
97
103
  - lib/active_campaign/version.rb
98
- - spec/active_campaign_spec.rb
99
104
  - spec/cassettes/ActiveCampaign_Client_Contacts/_contact_sync/when_successful/returns_1_for_result_code.json
100
105
  - spec/cassettes/ActiveCampaign_Client_Contacts/_contact_view/can_find_contact_by_id.json
101
106
  - spec/cassettes/ActiveCampaign_Client_Lists/_list_list/can_find_a_list_of_lists.json
102
107
  - spec/cassettes/ActiveCampaign_Client_Lists/_list_view/can_find_lists_by_id.json
103
- - spec/client/contacts_spec.rb
104
- - spec/client/lists_spec.rb
105
- - spec/client_spec.rb
106
108
  - spec/fixtures/contact_sync.json
107
109
  - spec/fixtures/contact_view.json
108
110
  - spec/fixtures/list_view.json
111
+ - spec/lib/active_campaign/client/contacts_spec.rb
112
+ - spec/lib/active_campaign/client/lists_spec.rb
113
+ - spec/lib/active_campaign/client_spec.rb
114
+ - spec/lib/active_campaign_spec.rb
109
115
  - spec/spec_helper.rb
110
116
  - spec/support/coverage.rb
111
117
  - spec/support/vcr.rb
@@ -130,22 +136,22 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
136
  version: '0'
131
137
  requirements: []
132
138
  rubyforge_project:
133
- rubygems_version: 2.4.6
139
+ rubygems_version: 2.4.8
134
140
  signing_key:
135
141
  specification_version: 4
136
142
  summary: See http://www.activecampaign.com/api/overview.php for more information
137
143
  test_files:
138
- - spec/active_campaign_spec.rb
139
144
  - spec/cassettes/ActiveCampaign_Client_Contacts/_contact_sync/when_successful/returns_1_for_result_code.json
140
145
  - spec/cassettes/ActiveCampaign_Client_Contacts/_contact_view/can_find_contact_by_id.json
141
146
  - spec/cassettes/ActiveCampaign_Client_Lists/_list_list/can_find_a_list_of_lists.json
142
147
  - spec/cassettes/ActiveCampaign_Client_Lists/_list_view/can_find_lists_by_id.json
143
- - spec/client/contacts_spec.rb
144
- - spec/client/lists_spec.rb
145
- - spec/client_spec.rb
146
148
  - spec/fixtures/contact_sync.json
147
149
  - spec/fixtures/contact_view.json
148
150
  - spec/fixtures/list_view.json
151
+ - spec/lib/active_campaign/client/contacts_spec.rb
152
+ - spec/lib/active_campaign/client/lists_spec.rb
153
+ - spec/lib/active_campaign/client_spec.rb
154
+ - spec/lib/active_campaign_spec.rb
149
155
  - spec/spec_helper.rb
150
156
  - spec/support/coverage.rb
151
157
  - spec/support/vcr.rb
@@ -1,146 +0,0 @@
1
- module ActiveCampaign
2
- # Custom error class for rescuing from all GitHub errors
3
- class Error < StandardError
4
- ERRORS = {
5
- 400 => ActiveCampaign::BadRequest,
6
- 401 => ActiveCampaign::Unauthorized,
7
- 403 => (lambda do |body|
8
- if body =~ /rate limit exceeded/i
9
- ActiveCampaign::TooManyRequests
10
- elsif body =~ /login attempts exceeded/i
11
- ActiveCampaign::TooManyLoginAttempts
12
- else
13
- ActiveCampaign::Forbidden
14
- end
15
- end),
16
- 404 => ActiveCampaign::NotFound,
17
- 406 => ActiveCampaign::NotAcceptable,
18
- 422 => ActiveCampaign::UnprocessableEntity,
19
- 500 => ActiveCampaign::InternalServerError,
20
- 501 => ActiveCampaign::NotImplemented,
21
- 502 => ActiveCampaign::BadGateway,
22
- 503 => ActiveCampaign::ServiceUnavailable
23
- }
24
-
25
- # Returns the appropriate ActiveCampaign::Error sublcass based
26
- # on status and response message
27
- #
28
- # @param [Hash]
29
- # @returns [ActiveCampaign::Error]
30
- # rubocop:disable MethodLength
31
- def self.from_response(response)
32
- status = response[:status].to_i
33
- body = response[:body].to_s
34
- klass = error_class(status)
35
- klass.new(response, body)
36
- end
37
- # rubocop:disable MethodLength
38
-
39
- def self.error_class(status, body)
40
- klass = ERRORS[status]
41
- return klass[body] if status == 403
42
- klass
43
- end
44
-
45
- def initialize(response = nil)
46
- @response = response
47
- super(build_error_message)
48
- end
49
-
50
- private
51
-
52
- def data
53
- @data ||= parse_body
54
- end
55
-
56
- def parse_body
57
- body = @response[:body]
58
-
59
- if body.present? && body.is_a?(String)
60
- return Sawyer::Agent.serializer.decode(body) if json?
61
- end
62
-
63
- body
64
- end
65
-
66
- def json?
67
- @response[:response_headers] && @response[:response_headers][:content_type] =~ /json/
68
- end
69
-
70
- def response_message
71
- case data
72
- when Hash
73
- data[:message]
74
- when String
75
- data
76
- end
77
- end
78
-
79
- def response_error
80
- "Error: #{data[:error]}" if data.is_a?(Hash) && data[:error]
81
- end
82
-
83
- def response_error_summary
84
- return nil unless data.is_a?(Hash) && !Array(data[:errors]).empty?
85
-
86
- summary = "\nError summary:\n"
87
- summary << data[:errors].map do |hash|
88
- hash.map { |k, v| " #{k}: #{v}" }
89
- end.join("\n")
90
-
91
- summary
92
- end
93
-
94
- # rubocop:disable AbcSize
95
- def build_error_message
96
- return nil if @response.nil?
97
-
98
- message = "#{@response[:method].to_s.upcase} "
99
- message << "#{@response[:url]}: "
100
- message << "#{@response[:status]} - "
101
- message << "#{response_message}" unless response_message.nil?
102
- message << "#{response_error}" unless response_error.nil?
103
- message << "#{response_error_summary}" unless response_error_summary.nil?
104
- message
105
- end
106
- # rubocop:enable AbcSize
107
- end
108
-
109
- # Raised when ActiveCampaign returns a 400 HTTP status code
110
- class BadRequest < Error; end
111
-
112
- # Raised when ActiveCampaign returns a 401 HTTP status code
113
- class Unauthorized < Error; end
114
-
115
- # Raised when ActiveCampaign returns a 403 HTTP status code
116
- class Forbidden < Error; end
117
-
118
- # Raised when ActiveCampaign returns a 403 HTTP status code
119
- # and body matches 'rate limit exceeded'
120
- class TooManyRequests < Forbidden; end
121
-
122
- # Raised when ActiveCampaign returns a 403 HTTP status code
123
- # and body matches 'login attempts exceeded'
124
- class TooManyLoginAttempts < Forbidden; end
125
-
126
- # Raised when ActiveCampaign returns a 404 HTTP status code
127
- class NotFound < Error; end
128
-
129
- # Raised when ActiveCampaign returns a 406 HTTP status code
130
- class NotAcceptable < Error; end
131
-
132
- # Raised when ActiveCampaign returns a 422 HTTP status code
133
- class UnprocessableEntity < Error; end
134
-
135
- # Raised when ActiveCampaign returns a 500 HTTP status code
136
- class InternalServerError < Error; end
137
-
138
- # Raised when ActiveCampaign returns a 501 HTTP status code
139
- class NotImplemented < Error; end
140
-
141
- # Raised when ActiveCampaign returns a 502 HTTP status code
142
- class BadGateway < Error; end
143
-
144
- # Raised when ActiveCampaign returns a 503 HTTP status code
145
- class ServiceUnavailable < Error; end
146
- end
@@ -1,41 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ActiveCampaign do
4
- before do
5
- ActiveCampaign.reset!
6
- end
7
-
8
- after do
9
- ActiveCampaign.reset!
10
- end
11
-
12
- describe '.client' do
13
- it 'creates an ActiveCampaign::Client' do
14
- expect(ActiveCampaign.client).to be_kind_of ActiveCampaign::Client
15
- end
16
-
17
- it 'caches the client when the same options are passed' do
18
- expect(ActiveCampaign.client).to eq ActiveCampaign.client
19
- end
20
-
21
- it 'returns a fresh client when options are not the same' do
22
- client = ActiveCampaign.client
23
- ActiveCampaign.config.api_key = 'somekey'
24
- client_two = ActiveCampaign.client
25
- client_three = ActiveCampaign.client
26
- expect(client_three).to eql client_two
27
- expect(client).to_not eql client_two
28
- end
29
- end
30
-
31
- describe '.configure' do
32
- ActiveCampaign.config.to_h.keys.each do |key|
33
- it "sets the #{key.to_s.gsub('_', ' ')}" do
34
- ActiveCampaign.configure do |config|
35
- config.send("#{key}=", key)
36
- end
37
- expect(ActiveCampaign.configuration[key]).to eq key
38
- end
39
- end
40
- end
41
- end