active_campaign 0.1.9 → 0.1.10

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: 773816e174638b5fa75102b031ac13ed726e9112
4
- data.tar.gz: 005d17ce9301bcadb204018be4154fb9990916ab
3
+ metadata.gz: f49cb05b48c6d485e7aeef4c124e5ffc4a497065
4
+ data.tar.gz: eb82879f1a6a707ee4ca92a66ef0220b07e60048
5
5
  SHA512:
6
- metadata.gz: 4facfd3b06ece6db14864a65124cb96e8fe73bd670544bdef32ff0f07982de5ce37ef6d78f48a6b37f83e6f8d11d4817d9b729f0e2c3aa6f09fe659a79c5ccde
7
- data.tar.gz: 640e94884732f0f66605c9777b29b1356d16d3178d4d699f7b6b572f2c4ba9a42ebf78a3a02da071cbce0afaae14003960d5bae35cbad8331764f212dc3aa913
6
+ metadata.gz: 920f478ce29086f94efdd3787be205f81b7b4118bf48ca1cd2d23c3470afaa98f7939b7e9cc02a0aace15097c871116ee780bb7e91c47e9cecedb95c52a4d70c
7
+ data.tar.gz: 2177d9dc0f1b73e32edf76cbd96a56d4bb2dc3354be9d3c223338d1a06bec2dfacdb137d77dca1e64a4b217f721af4c217db4bc9ef164f2bda2b5fa871e1e74a
@@ -0,0 +1,4 @@
1
+ languages:
2
+ Ruby: true
3
+ exclude_paths:
4
+ - 'spec/cassettes/**'
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
+ --format Fuubar
1
2
  --color
2
- --order random
3
+ --order random
@@ -0,0 +1,19 @@
1
+ # AllCops:
2
+ # Include:
3
+ # Exclude:
4
+
5
+ Documentation:
6
+ Enabled: false
7
+
8
+ ParameterLists:
9
+ Enabled: true
10
+ Max: 5
11
+ CountKeywordArgs: false
12
+
13
+ LineLength:
14
+ Enabled: true
15
+ Max: 107
16
+
17
+ IfUnlessModifier:
18
+ Enabled: false
19
+ MaxLineLength: 79
@@ -1,14 +1,12 @@
1
- before_script:
2
- - chmod 600 spec/fixtures/.netrc
3
1
  bundler_args: --without development
2
+
4
3
  language: ruby
4
+
5
5
  rvm:
6
- - jruby-18mode
7
6
  - jruby-19mode
8
- - rbx-18mode
9
- - rbx-19mode
10
7
  - rbx-2.1.1
11
- - 1.8.7
12
8
  - 1.9.2
13
9
  - 1.9.3
14
- - 2.0.0
10
+ - 2.0.0
11
+ - 2.1.6
12
+ - 2.2.2
data/Gemfile CHANGED
@@ -1,23 +1,22 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'rake'
4
- gem 'activesupport'
5
3
  gem 'rubysl', '~> 2', platform: :rbx
6
4
 
7
5
  group :development do
8
- gem 'awesome_print', require: 'ap'
9
- gem 'pry'
6
+ gem 'pry', platform: :mri
10
7
  end
11
8
 
12
9
  group :test do
13
- gem 'simplecov', ">= 0.8.0.pre2"
14
- gem "rubinius-coverage", platform: :rbx
15
- gem "codeclimate-test-reporter", require: false
10
+ gem 'simplecov', '>= 0.9.4'
11
+ gem 'rubinius-coverage', platform: :rbx
12
+ gem 'codeclimate-test-reporter', require: false
16
13
  gem 'coveralls', require: false
17
- gem 'rb-fsevent', '~> 0.9'
18
- gem 'rspec', '~> 2.14.0'
19
- gem 'vcr', '~> 2.8.0'
20
- gem 'webmock', '~> 1.15.0'
14
+ gem 'rb-fsevent'
15
+ gem 'rspec', '~> 3.2.0'
16
+ gem 'vcr'
17
+ gem 'webmock'
18
+ gem 'rubocop'
19
+ gem 'fuubar'
21
20
  end
22
21
 
23
22
  gemspec
data/README.md CHANGED
@@ -24,6 +24,21 @@ Or install it yourself as:
24
24
 
25
25
  Read their [API documentation](http://www.activecampaign.com/api/overview.php)for how to use this gem.
26
26
 
27
+ ```ruby
28
+ # To setup the client
29
+ client = ::ActiveCampaign::Client.new(
30
+ api_endpoint: 'YOUR-ENDPOINT', # e.g. 'https://yourendpoint.api-us1.com'
31
+ api_key: 'YOUR-API-KEY') # e.g. 'a4e60a1ba200595d5cc37ede5732545184165e'
32
+
33
+ # or configure globally for all clients
34
+ ::ActiveCampaign.configure do |config|
35
+ config.api_endpoint = 'YOUR-ENDPOINT', # e.g. 'https://yourendpoint.api-us1.com'
36
+ config.api_key = 'YOUR-API-KEY') # e.g. 'a4e60a1ba200595d5cc37ede5732545184165e'
37
+ end
38
+
39
+ ```
40
+
41
+
27
42
  ```ruby
28
43
  # To fetch all lists
29
44
  ActiveCampaign.list_list ids: 'all'
@@ -34,12 +49,12 @@ ActiveCampaign.list_list ids: 'all'
34
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
35
50
  # something pretty into something horrific when it comes to the parameters.
36
51
  ActiveCampaign.contact_sync({
37
- "id" => user.active_campaign_contact_id,
38
- "email" => user.email,
39
- "first_name" => user.first,
40
- "last_name" => user.last,
41
- "p[#{user.active_campaign_list_id}]" => user.active_campaign_list_id,
42
- "status[#{user.active_campaign_list_id}" => user.receive_emails ? 1 : 2
52
+ "id" => user.active_campaign_contact_id,
53
+ "email" => user.email,
54
+ "first_name" => user.first,
55
+ "last_name" => user.last,
56
+ "p[#{user.active_campaign_list_id}]" => user.active_campaign_list_id,
57
+ "status[#{user.active_campaign_list_id}]" => user.receive_emails ? 1 : 2
43
58
  })
44
59
 
45
60
  # Another example of syncing a contact:
data/Rakefile CHANGED
@@ -1 +1,14 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+
5
+ desc 'Run RuboCop on the lib directory'
6
+ RuboCop::RakeTask.new(:style) do |task|
7
+ task.formatters = ['fuubar']
8
+ task.options = %w(--display-cop-names)
9
+ task.fail_on_error = true
10
+ end
11
+
12
+ RSpec::Core::RakeTask.new(:spec)
13
+
14
+ task default: [:style, :spec]
@@ -4,20 +4,22 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'active_campaign/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "active_campaign"
7
+ spec.name = 'active_campaign'
8
8
  spec.version = ActiveCampaign::VERSION
9
- spec.authors = ["Mikael Henriksson"]
10
- spec.email = ["mikael@zoolutions.se"]
11
- spec.description = %q{A simple ruby wrapper for the ActiveCampaign API}
12
- spec.summary = %q{See http://www.activecampaign.com/api/overview.php for more information}
13
- spec.homepage = ""
14
- spec.license = "MIT"
9
+ spec.authors = ['Mikael Henriksson']
10
+ spec.email = ['mikael@zoolutions.se']
11
+ spec.description = 'A simple ruby wrapper for the ActiveCampaign API'
12
+ spec.summary = 'See http://www.activecampaign.com/api/overview.php for more information'
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
15
 
16
- spec.files = `git ls-files`.split($/)
16
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency "httpi"
22
- spec.add_dependency "hashie"
21
+ spec.add_dependency 'httpi'
22
+ spec.add_dependency 'hashie'
23
+ spec.add_dependency 'activesupport'
24
+ spec.add_dependency 'multi_json'
23
25
  end
@@ -0,0 +1,16 @@
1
+ machine:
2
+ ruby:
3
+ version: 2.2.2
4
+
5
+ dependencies:
6
+ bundler:
7
+ without: [production, staging, benchmarking]
8
+ cache_directories:
9
+ - vendor/bundle_java
10
+ - vendor/bundle
11
+ override:
12
+ - rvm-exec 2.2.2 bundle install
13
+
14
+ test:
15
+ override:
16
+ - rvm-exec 2.2.2 bundle exec rspec
@@ -1,41 +1,39 @@
1
- # require 'active_support/core_ext'
1
+ require 'active_support'
2
+ require 'active_support/core_ext'
3
+ require 'active_support/core_ext/module/delegation'
2
4
  require 'active_campaign/client'
3
- require 'active_campaign/default'
5
+ require 'active_campaign/configuration'
4
6
 
5
7
  module ActiveCampaign
8
+ extend Configuration
6
9
 
7
- class << self
10
+ module_function
8
11
 
9
- include ActiveCampaign::Configurable
10
-
11
- # API client based on configured options {Configurable}
12
- #
13
- # @return [ActiveCampaign::Client] API wrapper
14
- def client
15
- unless defined?(@client) && @client.same_options?(options)
16
- @client = ActiveCampaign::Client.new(options)
17
- end
18
-
19
- @client
12
+ # API client based on configured options {Configurable}
13
+ #
14
+ # @return [ActiveCampaign::Client] API wrapper
15
+ def client
16
+ unless defined?(@client) && @client.same_options?(configuration)
17
+ @client = ActiveCampaign::Client.new(configuration)
20
18
  end
21
19
 
22
- # @private
23
- def respond_to_missing?(method_name, include_private=false)
24
- client.respond_to?(method_name, include_private)
25
- end if RUBY_VERSION >= "1.9"
20
+ @client
21
+ end
22
+
23
+ # @private
24
+ def respond_to_missing?(method_name, include_private = false)
25
+ client.respond_to?(method_name, include_private)
26
+ end if RUBY_VERSION >= '1.9'
26
27
 
27
- # @private
28
- def respond_to?(method_name, include_private=false)
29
- client.respond_to?(method_name, include_private) || super
30
- end if RUBY_VERSION < "1.9"
28
+ # @private
29
+ def respond_to?(method_name, include_private = false)
30
+ client.respond_to?(method_name, include_private) || super
31
+ end if RUBY_VERSION < '1.9'
31
32
 
32
33
  private
33
34
 
34
- def method_missing(method_name, *args, &block)
35
- return super unless client.respond_to?(method_name)
36
- client.send(method_name, *args, &block)
37
- end
35
+ def method_missing(method_name, *args, &block)
36
+ return super unless client.respond_to?(method_name)
37
+ client.send(method_name, *args, &block)
38
38
  end
39
-
40
- ActiveCampaign.setup
41
39
  end
@@ -1,33 +1,36 @@
1
- require 'active_campaign/configurable'
1
+ require 'httpi'
2
+ require 'hashie'
3
+
2
4
  require 'active_campaign/client/contacts'
3
5
  require 'active_campaign/client/lists'
4
6
  require 'active_campaign/client/campaigns'
5
- require 'httpi'
6
- require 'hashie'
7
7
 
8
8
  module ActiveCampaign
9
9
  class Client
10
- include ActiveCampaign::Configurable
10
+ include Comparable
11
11
  include ActiveCampaign::Client::Contacts
12
12
  include ActiveCampaign::Client::Lists
13
13
  include ActiveCampaign::Client::Campaigns
14
14
 
15
- def initialize(options = {})
16
- ActiveCampaign::Configurable.keys.each do |key|
17
- instance_variable_set(:"@#{key}", options[key] ||
18
- ActiveCampaign.instance_variable_get(:"@#{key}"))
19
- end
15
+ delegate :api_key, :api_output, :api_endpoint, :user_agent, :log, :log_level,
16
+ :logger, :mash, :debug, to: :config
17
+
18
+ attr_accessor :config
19
+
20
+ def initialize(configuration = nil)
21
+ self.config = configuration
22
+ self.config ||= ActiveCampaign.configuration
20
23
  end
21
24
 
22
25
  # Compares client options to a Hash of requested options
23
26
  #
24
27
  # @param opts [Hash] Options to compare with current client options
25
28
  # @return [Boolean]
26
- def same_options?(opts)
27
- opts.hash == options.hash
29
+ def same_options?(other_config)
30
+ config.to_h.sort == other_config.to_h.sort
28
31
  end
29
32
 
30
- # Make a HTTP GET request
33
+ # Make a HTTP GET request
31
34
  #
32
35
  # @param url [String] The path, relative to {#api_endpoint}
33
36
  # @param options [Hash] Query and header params for request
@@ -36,6 +39,15 @@ module ActiveCampaign
36
39
  request :get, api_method, options
37
40
  end
38
41
 
42
+ def hash
43
+ [config, Client].hash
44
+ end
45
+
46
+ def <=>(other)
47
+ other.is_a?(ActiveCampaign::Client) &&
48
+ config.to_h.sort <=> other.config.to_h.sort
49
+ end
50
+
39
51
  # Make a HTTP POST request
40
52
  #
41
53
  # @param url [String] The path, relative to {#api_endpoint}
@@ -47,81 +59,69 @@ module ActiveCampaign
47
59
 
48
60
  private
49
61
 
50
- def request(method, api_method, data)
51
- req = create_request method, api_method, data
52
-
53
- response = HTTPI.send(method, req)
54
- response = JSON.parse(response.body)
55
- normalize(response)
56
- end
57
-
62
+ def request(method, api_method, data)
63
+ req = create_request method, api_method, data
64
+ response = HTTPI.send(method, req)
65
+ response = JSON.parse(response.body)
66
+ normalize(response)
67
+ end
58
68
 
59
- def create_request(method, api_method, options = {})
60
- request = HTTPI::Request.new url: File.join(api_endpoint, api_path)
69
+ def create_request(method, api_method, options = {})
70
+ req = HTTPI::Request.new(
71
+ url: File.join(api_endpoint),
72
+ headers: { 'User-Agent' => user_agent },
73
+ query: query(method, api_method, options),
74
+ body: body(method, api_method, options)
75
+ )
76
+ req.auth.ssl.verify_mode = :none
77
+ req.auth.ssl.ssl_version = :TLSv1
78
+ req
79
+ end
61
80
 
62
- request.headers = { "User-Agent" => user_agent }
63
- request.auth.ssl.verify_mode = :none
64
- request.query = query(method, api_method, options)
65
- request.body = body(method, api_method, options)
81
+ def query(method, api_method, options = {})
82
+ q = options.delete(:query) { Hash.new }
83
+ q.merge!(api_key: api_key,
84
+ api_action: api_method.to_s,
85
+ api_output: api_output)
66
86
 
67
- request
68
- end
87
+ q.merge!(options) if method == :get
69
88
 
70
- def query(method, api_method, options = {})
71
- q = options.delete(:query) { Hash.new }
72
- q.merge!({
73
- :api_key => api_key,
74
- :api_action => api_method.to_s,
75
- :api_output => api_output
76
- })
89
+ q
90
+ end
77
91
 
78
- if method == :get
79
- q.merge!(options)
80
- end
92
+ def body(method, _api_method, options = {})
93
+ return nil unless method == :post
81
94
 
82
- q
95
+ fields = options.delete(:fields) { Hash.new }
96
+ options[:field] = fields.inject({}) do |hash, (k, v)|
97
+ hash.merge("%#{k}%,0" => v)
83
98
  end
84
99
 
85
- def body(method, api_method, options = {})
86
- return nil unless method == :post
87
-
88
- fields = options.delete(:fields){ Hash.new }
89
- options[:field] = fields.inject({}) do |hash, (k,v)|
90
- hash.merge("%#{k}%,0" => v)
91
- end
100
+ options.to_query
101
+ end
92
102
 
93
- options.to_query
103
+ def normalize(response)
104
+ keys, values = keys_values(response)
105
+ if keys.all? { |key| numeric?(key) }
106
+ response[:results] = values
107
+ keys.each { |key| response.delete(key) }
94
108
  end
95
109
 
96
- def normalize(response)
97
- keys, values = keys_values(response)
98
-
99
- if keys.all?{|key| is_numeric?(key) }
100
- response[:results] = values
101
- keys.each do |key|
102
- response.delete(key)
103
- end
104
- end
105
-
106
- if mash
107
- Hashie::Mash.new response
108
- else
109
- ActiveSupport::HashWithIndifferentAccess.new(response)
110
- end
111
-
112
- end
110
+ return Hashie::Mash.new response if mash
111
+ ActiveSupport::HashWithIndifferentAccess.new(response)
112
+ end
113
113
 
114
- def is_numeric?(string)
115
- string.to_s.match(/\A[+-]?\d+\Z/) == nil ? false : true
116
- end
114
+ def numeric?(string)
115
+ string.to_s.match(/\A[+-]?\d+\Z/).nil? ? false : true
116
+ end
117
117
 
118
- def keys_values(response)
119
- results = results(response)
120
- [results.keys, results.values]
121
- end
118
+ def keys_values(response)
119
+ results = results(response)
120
+ [results.keys, results.values]
121
+ end
122
122
 
123
- def results(response)
124
- response.reject{|k,v| %w(result_code result_message result_output).include?(k) }
125
- end
123
+ def results(response)
124
+ response.reject { |k, _v| %w(result_code result_message result_output).include?(k) }
125
+ end
126
126
  end
127
- end
127
+ end