Skip to content
Open
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
26 changes: 26 additions & 0 deletions lib/active_campaign/api/contact_lists.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

module ActiveCampaign
module API
#
# Interface to contact list endpoints
#
# @author Daniel Moreira <danieldenis01@gmail.com>
#
module ContactLists
#
# Subscribe a contact to a list or unsubscribe a contact from a list
#
# @param [Hash] params add a contact to a list with this data
# @param params [String] :contact ID of the contact you're adding the tag to
# @param params [String] :list ID of the list to subscribe the contact to
# @param params [String] :status Set to "1" to subscribe or "2" to unsubscribe.
#
# @return [Hash] a hash with the information of the newly created contact list
#
def update_contact_list(params)
post('contactLists', contact_list: params)
end
end
end
end
5 changes: 1 addition & 4 deletions lib/active_campaign/api/contacts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,7 @@ def sync_contact(params)
#
# @return [Hash]
#
def show_contacts(filters: {}, orders: {}, **params)
params[:filters] = filters if filters.any?
params[:orders] = orders if orders.any?

def show_contacts(**params)
get('contacts', params)
end

Expand Down
1 change: 1 addition & 0 deletions lib/active_campaign/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Client
endpoint :accounts
endpoint :addresses
endpoint :contacts
endpoint :contact_lists
endpoint :contact_tags
endpoint :deals
endpoint :deal_custom_field_meta
Expand Down

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions spec/lib/active_campaign/api/contact_lists_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ActiveCampaign::API::ContactLists, :vcr do
let(:client) { ActiveCampaign.client }

describe '#update_contact_list', :with_existing_contact, :with_existing_list, :with_contact_list_params do
subject(:response) { client.update_contact_list(contact_list_params) }

# after do
# client.update_contact_list(contact_list_params.merge(status: '2'))
# end

it 'returns a contact list hash' do
expect(response).to include_json(contact_list: expected_contact_list_response)
end
end
end
1 change: 1 addition & 0 deletions spec/support/shared_contexts.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require_relative 'shared_contexts/with_address'
require_relative 'shared_contexts/with_contact_list'
require_relative 'shared_contexts/with_contact_tag'
require_relative 'shared_contexts/with_deal'
require_relative 'shared_contexts/with_deal_custom_field_meta'
Expand Down
19 changes: 19 additions & 0 deletions spec/support/shared_contexts/with_contact_list.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

RSpec.shared_context 'with contact list params', with_contact_list_params: true do
include_context 'with existing contact'
include_context 'with existing list'

let!(:contact_id) { contact[:id] }
let!(:list_id) { list[:id] }
let(:contact_list_params) do
{
contact: contact_id,
list: list_id
}
end

let(:expected_contact_list_response) do
contact_list_params
end
end
2 changes: 1 addition & 1 deletion spec/support/shared_contexts/with_existing_contact.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

RSpec.shared_context 'with existing contact' do
RSpec.shared_context 'with existing contact', :with_existing_contact do
let(:contact) do
response = client.create_contact(contact_params)
response.fetch(:contact) { raise 'HELL (contact creation failed)' }
Expand Down
1 change: 1 addition & 0 deletions spec/support/shared_contexts/with_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
response = client.create_list(list_params)
response.fetch(:list) { raise "HELL (list creation failed) #{response}" }
end

let(:list_id) { list[:id] }

after do
Expand Down