active_campaign 0.1.14 → 0.1.15
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.
- checksums.yaml +5 -5
- data/.codeclimate.yml +25 -3
- data/.rubocop.yml +21 -9
- data/.simplecov +9 -0
- data/.travis.yml +32 -12
- data/Changelog.md +14 -3
- data/Gemfile +2 -19
- data/README.md +13 -3
- data/Rakefile +4 -2
- data/active_campaign.gemspec +16 -3
- data/lib/active_campaign.rb +13 -15
- data/lib/active_campaign/client.rb +32 -29
- data/lib/active_campaign/client/campaigns.rb +86 -15
- data/lib/active_campaign/client/contacts.rb +90 -18
- data/lib/active_campaign/client/deals.rb +80 -14
- data/lib/active_campaign/client/forms.rb +7 -7
- data/lib/active_campaign/client/groups.rb +22 -10
- data/lib/active_campaign/client/lists.rb +52 -13
- data/lib/active_campaign/client/messages.rb +62 -14
- data/lib/active_campaign/client/tracks.rb +48 -11
- data/lib/active_campaign/client/users.rb +44 -9
- data/lib/active_campaign/configuration.rb +38 -13
- data/lib/active_campaign/core_ext.rb +8 -3
- data/lib/active_campaign/version.rb +3 -1
- data/spec/lib/active_campaign/client/contacts_spec.rb +2 -1
- data/spec/lib/active_campaign/client/lists_spec.rb +2 -1
- data/spec/lib/active_campaign/client_spec.rb +8 -0
- data/spec/lib/active_campaign_spec.rb +15 -20
- data/spec/spec_helper.rb +6 -5
- data/spec/support/vcr.rb +2 -0
- data/spec/support/webmock.rb +2 -0
- metadata +175 -13
- data/.coveralls.yml +0 -1
- data/lib/active_campaign/method_creator.rb +0 -32
- data/spec/support/coverage.rb +0 -18
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 | 
            -
             | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 2 | 
            +
            SHA256:
         | 
| 3 | 
            +
              metadata.gz: 86da02320b2b67aa96ddda701ae0612c6817070e0cfc57678b39c548f3643d19
         | 
| 4 | 
            +
              data.tar.gz: 117c5fe9baa8bd9b5b34e117800ea73776671c6e9e341cf3d184f98dffac408d
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 36f4861c214ac22085eab111f9bb8336fe5a863b67e699d8b5ec4aa45d475d36b82dcd0709d803898be90de30be40f057557158d260a9a8008a69d3e69b31630
         | 
| 7 | 
            +
              data.tar.gz: 41916f0a0fa99b4b734b5a71fd458d395827c6b8ea67af7bf3af039a3a317c9791cb0beccd05a6701b2fe7f65ac514e216140941e6a87b3ca4397e7ff753dda0
         | 
    
        data/.codeclimate.yml
    CHANGED
    
    | @@ -1,4 +1,26 @@ | |
| 1 | 
            -
             | 
| 2 | 
            -
             | 
| 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 | 
            -
              -  | 
| 26 | 
            +
              - spec/
         | 
    
        data/.rubocop.yml
    CHANGED
    
    | @@ -1,25 +1,37 @@ | |
| 1 1 | 
             
            AllCops:
         | 
| 2 2 | 
             
              Include:
         | 
| 3 | 
            -
                - ' | 
| 4 | 
            -
                - ' | 
| 5 | 
            -
                - ' | 
| 6 | 
            -
                - ' | 
| 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 | 
            -
             | 
| 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:  | 
| 34 | 
            +
              Max: 120
         | 
| 22 35 |  | 
| 23 | 
            -
            IfUnlessModifier:
         | 
| 36 | 
            +
            Style/IfUnlessModifier:
         | 
| 24 37 | 
             
              Enabled: false
         | 
| 25 | 
            -
              MaxLineLength: 79
         | 
    
        data/.simplecov
    ADDED
    
    
    
        data/.travis.yml
    CHANGED
    
    | @@ -1,20 +1,40 @@ | |
| 1 | 
            -
             | 
| 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 | 
            -
             | 
| 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- | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
               | 
| 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 | 
            -
             | 
| 19 | 
            -
               | 
| 20 | 
            -
                 | 
| 37 | 
            +
            notifications:
         | 
| 38 | 
            +
              email:
         | 
| 39 | 
            +
                recipients:
         | 
| 40 | 
            +
                  - mikael@zoolutions.se
         | 
    
        data/Changelog.md
    CHANGED
    
    | @@ -1,7 +1,17 @@ | |
| 1 | 
            -
             | 
| 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 | 
            -
             | 
| 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 | 
            -
             | 
| 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 | 
            -
             | 
| 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 | 
            -
            [](https://travis-ci.org/mhenrixon/active_campaign)[](https://codeclimate.com/github/mhenrixon/active_campaign)[](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 | 
| 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: [ | 
| 16 | 
            +
            task default: %i[style spec]
         | 
    
        data/active_campaign.gemspec
    CHANGED
    
    | @@ -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
         | 
    
        data/lib/active_campaign.rb
    CHANGED
    
    | @@ -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 | 
            -
                 | 
| 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 | 
            -
               | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 46 | 
            -
             | 
| 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 | 
            -
                 | 
| 31 | 
            -
             | 
| 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  | 
| 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:  | 
| 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) {  | 
| 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 | 
| 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) {  | 
| 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 | 
| 139 | 
            +
                  response.reject { |k, _v| %w[result_code result_message result_output].include?(k) }
         | 
| 137 140 | 
             
                end
         | 
| 138 141 | 
             
              end
         | 
| 139 142 | 
             
            end
         |