Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions .github/workflows/lint.yml

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has been broken forever

This file was deleted.

16 changes: 5 additions & 11 deletions .github/workflows/rspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,17 @@ name: RSpec
on: [push, pull_request]
jobs:
tests:
env:
COV: true

runs-on: ubuntu-latest

strategy:
fail-fast: true
fail-fast: false
matrix:
# ruby: [2.5, 2.6, 2.7, jruby, truffleruby]
ruby: [2.5, 2.6, 2.7]
ruby: ['3.3', '3.4']

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
- run: gem install bundler
- run: bundle install --jobs=$(nproc) --retry=$(nproc)
- run: bin/rspec

bundler-cache: true
- run: bundle exec rspec
3 changes: 1 addition & 2 deletions active_campaign.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ['lib']

spec.add_dependency 'activesupport', '>= 4.0', '< 8.0'
spec.add_dependency 'faraday', '>= 1.0', '< 3.0'
spec.add_dependency 'faraday', '>= 1.2', '< 3.0'
spec.add_dependency 'oj', '>= 3.0', '< 4.0'
end
1 change: 1 addition & 0 deletions lib/active_campaign.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'faraday'
require 'oj'

require 'active_campaign/version'
require 'active_campaign/errors'
Expand Down
2 changes: 1 addition & 1 deletion lib/active_campaign/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def endpoints(*endpoints)
def endpoint(endpoint)
require "active_campaign/api/#{endpoint}"

class_eval { include API.const_get(endpoint.to_s.camelize) }
class_eval { include API.const_get(TransformHash.camelize(endpoint.to_s)) }
rescue LoadError, NameError
raise DependencyMissing, endpoint
end
Expand Down
2 changes: 0 additions & 2 deletions lib/active_campaign/faraday/middleware/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ module Middleware
# @author Mikael Henriksson <mikael@mhenrixon.com>
#
class Request < ::Faraday::Middleware
dependency 'oj'

include TransformHash

def initialize(app, headers)
Expand Down
4 changes: 1 addition & 3 deletions lib/active_campaign/faraday/middleware/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ module Middleware
#
# @author Mikael Henriksson <mikael@mhenrixon.com>
#
class Response < ::Faraday::Response::Middleware
dependency 'oj'

class Response < ::Faraday::Middleware
include TransformHash

# Override this to modify the environment after the response has finished.
Expand Down
37 changes: 34 additions & 3 deletions lib/active_campaign/transform_hash.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require 'active_support/core_ext/string'

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are blocked from upgrading because the gem uses a couple of methods to format strings. It's really a huge overkill


module ActiveCampaign
#
# Utility module for manipulating hashes, arrays and values
Expand Down Expand Up @@ -35,7 +33,7 @@ def transform_keys(hash, *new_case)
# @return [Symbol] the transformed key
#
def transform_key(key, *new_case)
key.to_s.public_send(*new_case).to_sym
inflect(key.to_s, *new_case).to_sym
end

#
Expand Down Expand Up @@ -68,5 +66,38 @@ def transform_array(collection, *new_case)
end
end
end

#
# Changes the case of a string
#
# @param [String] string the string to change
# @param [Symbol] style `:underscore` or `:camelcase`
# @param [Symbol] first_letter `:upper` or `:lower`, only used by `:camelcase`
#
# @return [String]
#
Comment on lines +70 to +78

@jguecaimburu jguecaimburu Aug 27, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is all we need to avoid that dependency.

This gem has been abandoned for +2 years, at some point it might be a lot easier to simply refactor it into a client we own with a lot fewer moving parts. Leaving that for future adventures.

def inflect(string, style, first_letter = :upper)
case style
when :underscore then underscore(string)
when :camelcase then camelize(string, first_letter)
else raise ArgumentError, "unknown case #{style.inspect}"
end
end

# The rules below are the ActiveSupport ones without acronyms or namespace (::) handling. They live here
# so an application's inflection config can't change the keys sent to the API.
def underscore(string)
return string unless /[A-Z-]/.match?(string)

string
.gsub(/([A-Z])(?=[A-Z][a-z])|([a-z\d])(?=[A-Z])/) { "#{Regexp.last_match(1) || Regexp.last_match(2)}_" }
.tr('-', '_')
.downcase
end

def camelize(string, first_letter = :upper)
head = first_letter == :lower ? string.sub(/\A\w/, &:downcase) : string.sub(/\A[a-z\d]*/, &:capitalize)
head.gsub(/_([a-z\d]*)/i) { Regexp.last_match(1).capitalize }
end
end
end
4 changes: 0 additions & 4 deletions spec/lib/active_campaign/api/deal_stages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@

include_context 'with deal_stage params'

after do
client.delete_deal_stage(response.dig(:deal, :id))
end

# rubocop:disable RSpec/ExampleLength
it 'returns a deal_stage hash' do
expect(response).to include_json(
Expand Down
3 changes: 1 addition & 2 deletions spec/lib/active_campaign/api/fields_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@
end

it 'makes the custom field irretrievable' do
show_response = client.show_field(field_id)
expect(show_response).not_to include_json(field: expected_field_response)
expect { client.show_field(field_id) }.to raise_error(ActiveCampaign::ResourceNotFound)
end
end

Expand Down
4 changes: 0 additions & 4 deletions spec/lib/active_campaign/api/pipelines_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@

include_context 'with pipeline params'

after do
client.delete_pipeline(response.dig(:pipeline, :id))
end

it 'returns a pipeline hash' do
expect(response).to include_json(
deal_group: {
Expand Down
3 changes: 1 addition & 2 deletions spec/lib/active_campaign/api/tags_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@
end

it 'makes the tag irretrievable' do
show_response = client.show_tag(tag_id)
expect(show_response).not_to include_json(tag: expected_tag_response)
expect { client.show_tag(tag_id) }.to raise_error(ActiveCampaign::ResourceNotFound)
end
end
end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

require 'active_campaign'

require_relative 'support/cleanup'
require_relative 'support/shared_contexts'
require_relative 'support/webmock'
require_relative 'support/vcr'
Expand Down
15 changes: 15 additions & 0 deletions spec/support/cleanup.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

# The client raises ResourceNotFound on 404, and cleanup hooks often delete a
# resource the example itself already deleted.
Comment on lines +3 to +4

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We made this change on the fork long time ago and never fixed specs

module Cleanup
def cleanup
yield
rescue ActiveCampaign::ResourceNotFound
nil
end
end

RSpec.configure do |config|
config.include Cleanup
end
4 changes: 2 additions & 2 deletions spec/support/shared_contexts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
end

after do
client.delete_account(account_id) if account_id
cleanup { client.delete_account(account_id) } if account_id
end
end

Expand Down Expand Up @@ -80,6 +80,6 @@
end

after do
client.delete_account_contact(account_contact_id) if account_contact_id
cleanup { client.delete_account_contact(account_contact_id) } if account_contact_id
end
end
2 changes: 1 addition & 1 deletion spec/support/shared_contexts/with_contact_tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
let(:contact_tag_id) { contact_tag[:id] }

after do
client.delete_contact_tag(contact_tag_id) if contact_tag_id
cleanup { client.delete_contact_tag(contact_tag_id) } if contact_tag_id
end
end
4 changes: 2 additions & 2 deletions spec/support/shared_contexts/with_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
let(:field_id) { field[:id] }

after do
client.delete_field(field_id) if field_id
cleanup { client.delete_field(field_id) } if field_id
end
end

Expand Down Expand Up @@ -162,6 +162,6 @@
let(:rel_id) { field_rel[:id] }

after do
client.delete_field_rel(rel_id) if rel_id
cleanup { client.delete_field_rel(rel_id) } if rel_id
end
end
2 changes: 1 addition & 1 deletion spec/support/shared_contexts/with_field_value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
let(:field_value_id) { field_value[:id] }

after do
client.delete_field_value(field_value_id) if field_value_id
cleanup { client.delete_field_value(field_value_id) } if field_value_id
end
end
2 changes: 1 addition & 1 deletion spec/support/shared_contexts/with_tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
let(:tag_id) { tag[:id] }

after do
client.delete_tag(tag_id) if tag_id
cleanup { client.delete_tag(tag_id) } if tag_id
end
end
Loading