active_campaign 0.1.14 → 0.1.15

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
- SHA1:
3
- metadata.gz: f959a6cbb68c5711716a5039eaacce4d89e8858d
4
- data.tar.gz: 5661a144faa672e737d400d37c8b46dccebf9249
2
+ SHA256:
3
+ metadata.gz: 86da02320b2b67aa96ddda701ae0612c6817070e0cfc57678b39c548f3643d19
4
+ data.tar.gz: 117c5fe9baa8bd9b5b34e117800ea73776671c6e9e341cf3d184f98dffac408d
5
5
  SHA512:
6
- metadata.gz: 492bfc8ce519fa91f47a2a86776a0d5611cba71405fa0a6d8a381b9cbbf63ae20be3b750f95a54b7409d0ebd1cf752e1b64a75ca789fa04539009b1a48a9dc17
7
- data.tar.gz: 77e704860971e8ee2fc591fc3288a8144ce03dfbb501657eaa0e90c03d663fd9daba04afd313576f7b65516a5d7c217274119d67cf29d3d951ec091631f2fafc
6
+ metadata.gz: 36f4861c214ac22085eab111f9bb8336fe5a863b67e699d8b5ec4aa45d475d36b82dcd0709d803898be90de30be40f057557158d260a9a8008a69d3e69b31630
7
+ data.tar.gz: 41916f0a0fa99b4b734b5a71fd458d395827c6b8ea67af7bf3af039a3a317c9791cb0beccd05a6701b2fe7f65ac514e216140941e6a87b3ca4397e7ff753dda0
@@ -1,4 +1,26 @@
1
- languages:
2
- Ruby: true
1
+ ---
2
+ engines:
3
+ bundler-audit:
4
+ enabled: false
5
+ duplication:
6
+ enabled: true
7
+ config:
8
+ languages:
9
+ - ruby
10
+ fixme:
11
+ enabled: true
12
+ rubocop:
13
+ enabled: true
14
+ ratings:
15
+ paths:
16
+ - Gemfile.lock
17
+ - "**.css"
18
+ - "**.inc"
19
+ - "**.js"
20
+ - "**.jsx"
21
+ - "**.module"
22
+ - "**.php"
23
+ - "**.py"
24
+ - "**.rb"
3
25
  exclude_paths:
4
- - 'spec/cassettes/**'
26
+ - spec/
@@ -1,25 +1,37 @@
1
1
  AllCops:
2
2
  Include:
3
- - '**/Rakefile'
4
- - '**/lib'
5
- - '**/bin'
6
- - '**/spec'
3
+ - 'Rakefile'
4
+ - 'lib/**/*'
5
+ - 'bin/**/*'
6
+ - 'spec/**/*'
7
7
  Exclude:
8
8
  - 'Gemfile.lock'
9
+ - 'Gemfile'
9
10
  - 'gemfiles/**/*'
11
+ - '**/*.json'
12
+ - '**/*.yml'
13
+ TargetRubyVersion: 2.4
10
14
 
11
15
  Documentation:
12
16
  Enabled: false
13
17
 
14
- ParameterLists:
18
+ Metrics/BlockLength:
19
+ Enabled: true
20
+ Exclude:
21
+ - 'spec/**/*_spec.rb'
22
+
23
+ Metrics/MethodLength:
24
+ CountComments: false # count full line comments?
25
+ Max: 12
26
+
27
+ Metrics/ParameterLists:
15
28
  Enabled: true
16
29
  Max: 5
17
30
  CountKeywordArgs: false
18
31
 
19
- LineLength:
32
+ Metrics/LineLength:
20
33
  Enabled: true
21
- Max: 107
34
+ Max: 120
22
35
 
23
- IfUnlessModifier:
36
+ Style/IfUnlessModifier:
24
37
  Enabled: false
25
- MaxLineLength: 79
@@ -0,0 +1,9 @@
1
+ require 'simplecov-json'
2
+
3
+ SimpleCov.formatters = [
4
+ SimpleCov::Formatter::HTMLFormatter,
5
+ SimpleCov::Formatter::JSONFormatter,
6
+ ]
7
+
8
+ SimpleCov.command_name 'RSpec'
9
+ SimpleCov.start
@@ -1,20 +1,40 @@
1
- sudo: false
1
+ env:
2
+ matrix:
3
+ - COV=false
4
+ global:
5
+ - CC_TEST_REPORTER_ID=8ba417e8bf62f355529f4f11b42114f99e073459a7424e79845d64ab95e52b76
6
+ - GIT_COMMITTED_AT=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then git log -1 --pretty=format:%ct; else git log -1 --skip 1 --pretty=format:%ct; fi)
7
+ dist: trusty
8
+ sudo: required
2
9
  language: ruby
3
10
  cache: bundler
11
+
4
12
  before_install:
5
13
  - rvm get head
6
14
  - gem update --system
7
15
  - gem install bundler
8
-
9
- language: ruby
10
-
16
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
17
+ - chmod +x ./cc-test-reporter
18
+ install:
19
+ - bundle install -j8 -r3
20
+ before_script:
21
+ - ./cc-test-reporter before-build
22
+ script:
23
+ - if [[ "${COV}" = "true" ]]; then bundle exec rubocop; fi;
24
+ - bundle exec rspec spec
25
+ after_script:
26
+ - if [[ "${COV}" = "true" ]]; then ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT; fi;
11
27
  rvm:
12
- - jruby-19mode
13
- - rbx-3
14
- - 2.1.8
15
- - 2.2.4
16
- - 2.3.1
28
+ - jruby-9.1.8.0
29
+ env: COV=false
30
+
31
+ matrix:
32
+ fast_finish: true
33
+ include:
34
+ - rvm: 2.5.1
35
+ env: COV=true
17
36
 
18
- addons:
19
- code_climate:
20
- repo_token: e199bdc9d2cf5ceaa7e46425f118470e43880940098f815a4c972a923102b12b
37
+ notifications:
38
+ email:
39
+ recipients:
40
+ - mikael@zoolutions.se
@@ -1,7 +1,17 @@
1
- # 0.1.12
1
+ ## 0.1.14
2
+
3
+ - #10 bugs fixes
4
+ - the http method of list_field_add and list_field_edit should be POST
5
+ - Fix method_missing for ActiveCampaign module (#27)
6
+ - Add Tags client prototype (#17)
7
+ - Add automation_contact_remove post method (#25)
8
+
9
+ ## 0.1.13
10
+
2
11
  - Allow ActiveCampaign::Client.new to accept a Hash
3
12
 
4
- # 0.1.11
13
+ ## 0.1.11
14
+
5
15
  - Adds Deals
6
16
  - Adds Forms
7
17
  - Adds Groups
@@ -9,7 +19,8 @@
9
19
  - Adds Tracks
10
20
  - Adds Campaigns
11
21
 
12
- # 0.1.10
22
+ ## 0.1.10
23
+
13
24
  - Added tagging of lists and contacts
14
25
  - Internally: Upgraded gems and RSpec syntax
15
26
  - Internally: Added rubocop
data/Gemfile CHANGED
@@ -1,21 +1,4 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'rake'
4
- gem 'rubysl', '~> 2', platform: :rbx
5
-
6
- group :test do
7
- gem 'pry'
8
- gem 'simplecov'
9
- gem 'simplecov-json'
10
- gem 'rubinius-coverage', platform: :rbx
11
- gem 'codeclimate-test-reporter', require: false
12
- gem 'coveralls', require: false
13
- gem 'rb-fsevent'
14
- gem 'rspec', '>= 3.2'
15
- gem 'vcr'
16
- gem 'webmock'
17
- gem 'rubocop'
18
- gem 'fuubar'
19
- end
1
+ # frozen_string_literal: true
20
2
 
3
+ source 'https://rubygems.org'
21
4
  gemspec
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/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)
1
+ [![Build Status](https://travis-ci.org/mhenrixon/active_campaign.svg?branch=master)](https://travis-ci.org/mhenrixon/active_campaign)[![Code Climate](https://codeclimate.com/github/mhenrixon/active_campaign/badges/gpa.svg)](https://codeclimate.com/github/mhenrixon/active_campaign)[![Test Coverage](https://codeclimate.com/github/mhenrixon/active_campaign/badges/coverage.svg)](https://codeclimate.com/github/mhenrixon/active_campaign/coverage)
2
2
  # Active::Campaign::Ruby
3
3
 
4
4
  A simple wrapper for the ActiveCampaign API. Since their API seems to be
@@ -27,12 +27,12 @@ Read their [API documentation](http://www.activecampaign.com/api/overview.php)fo
27
27
  ```ruby
28
28
  # To setup the client
29
29
  client = ::ActiveCampaign::Client.new(
30
- api_endpoint: 'YOUR-ENDPOINT', # e.g. 'https://yourendpoint.api-us1.com'
30
+ api_endpoint: 'YOUR-ENDPOINT', # e.g. 'https://yourendpoint.api-us1.com/admin/api.php'
31
31
  api_key: 'YOUR-API-KEY') # e.g. 'a4e60a1ba200595d5cc37ede5732545184165e'
32
32
 
33
33
  # or configure globally for all clients
34
34
  ::ActiveCampaign.configure do |config|
35
- config.api_endpoint = 'YOUR-ENDPOINT', # e.g. 'https://yourendpoint.api-us1.com'
35
+ config.api_endpoint = 'YOUR-ENDPOINT', # e.g. 'https://yourendpoint.api-us1.com/admin/api.php'
36
36
  config.api_key = 'YOUR-API-KEY' # e.g. 'a4e60a1ba200595d5cc37ede5732545184165e'
37
37
  end
38
38
 
@@ -111,6 +111,16 @@ All responses are wrapped under `results` so
111
111
  }
112
112
  ```
113
113
 
114
+ For using tags_list action do the following
115
+
116
+ ```ruby
117
+ ActiveCampaign.get('tags_list')
118
+ ```
119
+ The response of method is an array of tags
120
+
121
+ ```ruby
122
+ [{"id":1,"name":"test_tag","count":1}]
123
+ ```
114
124
 
115
125
  ## Contributing
116
126
 
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
  require 'rubocop/rake_task'
@@ -5,10 +7,10 @@ require 'rubocop/rake_task'
5
7
  desc 'Run RuboCop on the lib directory'
6
8
  RuboCop::RakeTask.new(:style) do |task|
7
9
  task.formatters = ['fuubar']
8
- task.options = %w(--display-cop-names)
10
+ task.options = %w[--display-cop-names]
9
11
  task.fail_on_error = true
10
12
  end
11
13
 
12
14
  RSpec::Core::RakeTask.new(:spec)
13
15
 
14
- task default: [:style, :spec]
16
+ task default: %i[style spec]
@@ -1,4 +1,6 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
3
+
2
4
  lib = File.expand_path('../lib', __FILE__)
3
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
6
  require 'active_campaign/version'
@@ -10,7 +12,7 @@ Gem::Specification.new do |spec|
10
12
  spec.email = ['mikael@zoolutions.se']
11
13
  spec.description = 'A simple ruby wrapper for the ActiveCampaign API'
12
14
  spec.summary = 'See http://www.activecampaign.com/api/overview.php for more information'
13
- spec.homepage = ''
15
+ spec.homepage = 'https://github.com/mhenrixon/active_campaign'
14
16
  spec.license = 'MIT'
15
17
 
16
18
  spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
@@ -18,6 +20,17 @@ Gem::Specification.new do |spec|
18
20
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
21
  spec.require_paths = ['lib']
20
22
 
21
- spec.add_dependency 'httpi'
22
- spec.add_dependency 'multi_json'
23
+ spec.add_dependency 'httpi', '>= 1.0', '< 3.0'
24
+ spec.add_dependency 'multi_json', '>= 1.0', '< 2'
25
+ spec.add_development_dependency 'codeclimate-test-reporter', '~> 1.0'
26
+ spec.add_development_dependency 'fuubar', '~> 2.0'
27
+ spec.add_development_dependency 'gem-release', '~> 1.0'
28
+ spec.add_development_dependency 'pry', '~> 0.10'
29
+ spec.add_development_dependency 'rake', '~> 12.0'
30
+ spec.add_development_dependency 'rspec', '~> 3.5'
31
+ spec.add_development_dependency 'rubocop', '~> 0.48'
32
+ spec.add_development_dependency 'webmock', '~> 3.0'
33
+ spec.add_development_dependency 'simplecov', '~> 0.13'
34
+ spec.add_development_dependency 'simplecov-json', '~> 0.2'
35
+ spec.add_development_dependency 'vcr', '~> 3.0'
23
36
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_campaign/version'
2
4
  require 'active_campaign/client'
3
5
  require 'active_campaign/configuration'
@@ -10,11 +12,7 @@ module ActiveCampaign
10
12
  #
11
13
  # @return [ActiveCampaign::Client] API wrapper
12
14
  def client
13
- unless defined?(@client) && @client.same_options?(config)
14
- @client = ActiveCampaign::Client.new(config)
15
- end
16
-
17
- @client
15
+ ActiveCampaign::Client.new
18
16
  end
19
17
 
20
18
  # @private
@@ -22,11 +20,6 @@ module ActiveCampaign
22
20
  client.respond_to?(method_name, include_private)
23
21
  end
24
22
 
25
- # @private
26
- def respond_to?(method_name, include_private = false)
27
- client.respond_to?(method_name, include_private) || super
28
- end if RUBY_VERSION < '1.9'
29
-
30
23
  def config
31
24
  @config ||= Configuration.new
32
25
  end
@@ -39,10 +32,15 @@ module ActiveCampaign
39
32
  @config = Configuration.new
40
33
  end
41
34
 
42
- private
43
-
44
- def method_missing(method_name, *args, &block)
45
- return super unless client.respond_to?(method_name)
46
- client.send(method_name, *args, &block)
35
+ class << self
36
+ # rubocop:disable Style/MissingRespondToMissing
37
+ def method_missing(method_name, *args, &block)
38
+ if client.respond_to?(method_name)
39
+ client.send(method_name, *args, &block)
40
+ else
41
+ super
42
+ end
43
+ end
44
+ # rubocop:enable Style/MissingRespondToMissing
47
45
  end
48
46
  end
@@ -1,5 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'httpi'
2
- require 'active_campaign/method_creator'
3
4
 
4
5
  require 'active_campaign/client/campaigns'
5
6
  require 'active_campaign/client/contacts'
@@ -13,8 +14,6 @@ require 'active_campaign/client/users'
13
14
 
14
15
  module ActiveCampaign
15
16
  class Client
16
- include Comparable
17
- extend ActiveCampaign::MethodCreator
18
17
  extend Forwardable
19
18
 
20
19
  include ActiveCampaign::Client::Campaigns
@@ -27,19 +26,12 @@ module ActiveCampaign
27
26
  include ActiveCampaign::Client::Tracks
28
27
  include ActiveCampaign::Client::Users
29
28
 
30
- def_delegators :@config, :api_key, :api_output, :api_endpoint,
31
- :user_agent, :log, :log_level, :logger, :mash, :debug
29
+ attr_reader :config
30
+ def_delegators :config, :api_key, :api_output, :api_endpoint,
31
+ :user_agent, :log, :log_level, :logger, :debug
32
32
 
33
33
  def initialize(options = {})
34
- @config ||= ActiveCampaign.config.merge(options)
35
- end
36
-
37
- # Compares client options to a Hash of requested options
38
- #
39
- # @param opts [Hash] Options to compare with current client options
40
- # @return [Boolean]
41
- def same_options?(other_config)
42
- @config.to_h.sort == other_config.to_h.sort
34
+ @config = ActiveCampaign.config.dup.merge(options)
43
35
  end
44
36
 
45
37
  # Make a HTTP GET request
@@ -51,15 +43,6 @@ module ActiveCampaign
51
43
  request :get, api_method, options
52
44
  end
53
45
 
54
- def hash
55
- [@config, Client].hash
56
- end
57
-
58
- def <=>(other)
59
- other.is_a?(ActiveCampaign::Client) &&
60
- @config.to_h.sort <=> other.config.to_h.sort
61
- end
62
-
63
46
  # Make a HTTP POST request
64
47
  #
65
48
  # @param url [String] The path, relative to {#api_endpoint}
@@ -69,6 +52,17 @@ module ActiveCampaign
69
52
  request :post, api_method, options
70
53
  end
71
54
 
55
+ def hash
56
+ [config.hash, Client].hash
57
+ end
58
+
59
+ def ==(other)
60
+ other.is_a?(ActiveCampaign::Client) &&
61
+ hash == other.hash
62
+ end
63
+
64
+ alias eql? ==
65
+
72
66
  private
73
67
 
74
68
  def request(method, api_method, data)
@@ -79,10 +73,17 @@ module ActiveCampaign
79
73
  normalize(response)
80
74
  end
81
75
 
76
+ def request_headers
77
+ {
78
+ 'User-Agent' => user_agent,
79
+ 'Content-Type' => 'application/x-www-form-urlencoded'
80
+ }
81
+ end
82
+
82
83
  def create_request(method, api_method, options = {})
83
84
  req = HTTPI::Request.new(
84
85
  url: File.join(api_endpoint),
85
- headers: { 'User-Agent' => user_agent },
86
+ headers: request_headers,
86
87
  query: query(method, api_method, options),
87
88
  body: body(method, api_method, options)
88
89
  )
@@ -92,20 +93,20 @@ module ActiveCampaign
92
93
  end
93
94
 
94
95
  def query(method, api_method, options = {})
95
- q = options.delete(:query) { Hash.new }
96
+ q = options.delete(:query) { {} }
96
97
  q.merge!(api_key: api_key,
97
98
  api_action: api_method.to_s,
98
99
  api_output: api_output)
99
100
 
100
- q.merge!(options) if method == :get
101
+ return q unless method == :get
101
102
 
102
- q
103
+ q.merge(options)
103
104
  end
104
105
 
105
106
  def body(method, _api_method, options = {})
106
107
  return nil unless method == :post
107
108
 
108
- fields = options.delete(:fields) { Hash.new }
109
+ fields = options.delete(:fields) { {} }
109
110
  options[:field] = fields.inject({}) do |hash, (k, v)|
110
111
  hash.merge("%#{k}%,0" => v)
111
112
  end
@@ -114,6 +115,8 @@ module ActiveCampaign
114
115
  end
115
116
 
116
117
  def normalize(response)
118
+ return response if response.is_a? Array
119
+
117
120
  keys, values = keys_values(response)
118
121
  if keys.all? { |key| numeric?(key) }
119
122
  response['results'] = values
@@ -133,7 +136,7 @@ module ActiveCampaign
133
136
  end
134
137
 
135
138
  def results(response)
136
- response.reject { |k, _v| %w(result_code result_message result_output).include?(k) }
139
+ response.reject { |k, _v| %w[result_code result_message result_output].include?(k) }
137
140
  end
138
141
  end
139
142
  end