From 9aaec2c1873b9ea4eabfedeafed9a768e3eb9b28 Mon Sep 17 00:00:00 2001 From: jpgbarbosa Date: Thu, 29 Apr 2021 18:08:36 +0100 Subject: [PATCH 1/2] Fix rubocop offenses --- .rubocop.yml | 25 +++++++++++++++++++ active_campaign.gemspec | 2 ++ lib/active_campaign/api.rb | 2 +- lib/active_campaign/client.rb | 4 --- lib/active_campaign/configuration.rb | 2 +- .../faraday/middleware/request.rb | 2 +- .../faraday/middleware/response.rb | 2 +- spec/support/shared_contexts/with_list.rb | 1 + 8 files changed, 32 insertions(+), 8 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index bca7e0f..a65ba84 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -7,3 +7,28 @@ AllCops: Exclude: - 'gemfiles/**/*' - '**/*.json' + - bin/**/* + +RSpec/MultipleMemoizedHelpers: + Enabled: false + +Lint/MissingSuper: + Exclude: + - 'lib/active_campaign.rb' + - 'lib/active_campaign/*' + +Naming/VariableNumber: + Exclude: + - 'spec/**/*' + +Layout/ExtraSpacing: + Exclude: + - 'spec/support/shared_contexts/*' + +Lint/EmptyBlock: + Exclude: + - 'spec/support/shared_contexts/*' + +RSpec/AlignLeftLetBrace: + Exclude: + - 'spec/support/shared_contexts/*' diff --git a/active_campaign.gemspec b/active_campaign.gemspec index 700cda6..af94da6 100644 --- a/active_campaign.gemspec +++ b/active_campaign.gemspec @@ -24,6 +24,8 @@ Gem::Specification.new do |spec| 'public gem pushes.' end + spec.required_ruby_version = '>= 2.5.0' + spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR) # spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) diff --git a/lib/active_campaign/api.rb b/lib/active_campaign/api.rb index 724c484..df7c3bb 100644 --- a/lib/active_campaign/api.rb +++ b/lib/active_campaign/api.rb @@ -52,7 +52,7 @@ def endpoint(endpoint) # @return [Logger] any object that responds to :debug, :info, :warn, :error and :fatal # def logger - @logger ||= ActiveCampaign.logger + @logger ||= ActiveCampaign.logger # rubocop:disable ThreadSafety/InstanceVariableInClassMethod - should be a fixme end end end diff --git a/lib/active_campaign/client.rb b/lib/active_campaign/client.rb index 85a53da..7523999 100644 --- a/lib/active_campaign/client.rb +++ b/lib/active_campaign/client.rb @@ -100,8 +100,6 @@ def safe_http_call # rubocop:disable Metrics/AbcSize, Metrics/MethodLength raise ProxyAuthError, e rescue ::Faraday::ConflictError => e raise ConflictError, e - rescue ::Faraday::UnauthorizedError => e - raise UnauthorizedError, e rescue ::Faraday::UnprocessableEntityError => e raise UnprocessableEntityError, e rescue ::Faraday::ServerError => e @@ -110,8 +108,6 @@ def safe_http_call # rubocop:disable Metrics/AbcSize, Metrics/MethodLength raise TimeoutError, e rescue ::Faraday::NilStatusError => e raise NilStatusError, e - rescue ::Faraday::ConnectionFailed => e - raise ConnectionFailed, e rescue ::Faraday::SSLError => e raise SSLError, e end diff --git a/lib/active_campaign/configuration.rb b/lib/active_campaign/configuration.rb index 9b447ff..45303cf 100644 --- a/lib/active_campaign/configuration.rb +++ b/lib/active_campaign/configuration.rb @@ -55,7 +55,7 @@ def initialize self.api_timeout = 5 self.api_token = API_TOKEN self.debug = false - self.logger = Logger.new(STDOUT) + self.logger = Logger.new($stdout) @request_middleware = {} @response_middleware = {} end diff --git a/lib/active_campaign/faraday/middleware/request.rb b/lib/active_campaign/faraday/middleware/request.rb index dec1dee..556775f 100644 --- a/lib/active_campaign/faraday/middleware/request.rb +++ b/lib/active_campaign/faraday/middleware/request.rb @@ -45,7 +45,7 @@ def normalize_body(env) end def logger - @logger ||= Logger.new(STDOUT) + @logger ||= Logger.new($stdout) end end end diff --git a/lib/active_campaign/faraday/middleware/response.rb b/lib/active_campaign/faraday/middleware/response.rb index bcd38f6..ba7359c 100644 --- a/lib/active_campaign/faraday/middleware/response.rb +++ b/lib/active_campaign/faraday/middleware/response.rb @@ -4,7 +4,7 @@ require 'faraday/logging/formatter' module ActiveCampaign - LOGGER = ::Logger.new(STDOUT) + LOGGER = ::Logger.new($stdout) module Faraday module Middleware # diff --git a/spec/support/shared_contexts/with_list.rb b/spec/support/shared_contexts/with_list.rb index 95e1101..4aee59a 100644 --- a/spec/support/shared_contexts/with_list.rb +++ b/spec/support/shared_contexts/with_list.rb @@ -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 From 1f71c11a12c6ecf11e969ba5dfce93d5797bd0cd Mon Sep 17 00:00:00 2001 From: jpgbarbosa Date: Thu, 29 Apr 2021 18:08:48 +0100 Subject: [PATCH 2/2] contact_list feature --- lib/active_campaign/api/contact_lists.rb | 26 ++ lib/active_campaign/client.rb | 1 + .../returns_a_contact_list_hash.yml | 411 ++++++++++++++++++ .../active_campaign/api/contact_lists_spec.rb | 19 + spec/support/shared_contexts.rb | 1 + .../shared_contexts/with_contact_list.rb | 19 + .../shared_contexts/with_existing_contact.rb | 2 +- 7 files changed, 478 insertions(+), 1 deletion(-) create mode 100644 lib/active_campaign/api/contact_lists.rb create mode 100644 spec/cassettes/ActiveCampaign_API_ContactLists/_update_contact_list/returns_a_contact_list_hash.yml create mode 100644 spec/lib/active_campaign/api/contact_lists_spec.rb create mode 100644 spec/support/shared_contexts/with_contact_list.rb diff --git a/lib/active_campaign/api/contact_lists.rb b/lib/active_campaign/api/contact_lists.rb new file mode 100644 index 0000000..159e157 --- /dev/null +++ b/lib/active_campaign/api/contact_lists.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +module ActiveCampaign + module API + # + # Interface to contact list endpoints + # + # @author Daniel Moreira + # + 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 diff --git a/lib/active_campaign/client.rb b/lib/active_campaign/client.rb index 7523999..f4e7eab 100644 --- a/lib/active_campaign/client.rb +++ b/lib/active_campaign/client.rb @@ -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 diff --git a/spec/cassettes/ActiveCampaign_API_ContactLists/_update_contact_list/returns_a_contact_list_hash.yml b/spec/cassettes/ActiveCampaign_API_ContactLists/_update_contact_list/returns_a_contact_list_hash.yml new file mode 100644 index 0000000..77724c3 --- /dev/null +++ b/spec/cassettes/ActiveCampaign_API_ContactLists/_update_contact_list/returns_a_contact_list_hash.yml @@ -0,0 +1,411 @@ +--- +http_interactions: +- request: + method: post + uri: "/contacts" + body: + encoding: UTF-8 + string: '{"contact":{"email":"mikael@mhenrixon.com","firstName":"Mikael","lastName":"Henriksson","phone":"+491735728523"}}' + headers: + User-Agent: + - ActiveCampaign Ruby Client (v3.0.0) + Accept: + - application/json + Content-Type: + - application/json + Api-Token: + - "" + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 201 + message: Created + headers: + Date: + - Wed, 10 Mar 2021 19:29:42 GMT + Content-Type: + - application/json + Content-Length: + - '1766' + Connection: + - keep-alive + Set-Cookie: + - PHPSESSID=aa78414290d8ff9e3b4186d040703fd7; path=/; HttpOnly + - __cfduid=da8478bc95beb10080463549e05ab785e1615404582; expires=Fri, 09-Apr-21 + 19:29:42 GMT; path=/; domain=.api-us1.com; HttpOnly; SameSite=Lax + - em_acp_globalauth_cookie=7c9ae051-fa0b-4c49-a883-3dc3dc8a6a46; path=/; domain=.inveniobr.api-us1.com; + secure; httponly + - em_acp_globalauth_cookie=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; + path=/; domain=.inveniobr.api-us1.com + - em_acp_globalauth_cookie=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; + path=/; domain=.inveniobr.api-us1.com + - em_acp_globalauth_cookie=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; + path=/; domain=.inveniobr.api-us1.com + Access-Control-Allow-Headers: + - Content-Type, origin, x-requested-with + Access-Control-Allow-Methods: + - POST, GET + Access-Control-Allow-Origin: + - "*" + Cache-Control: + - no-store, no-cache, must-revalidate + Expires: + - Thu, 19 Nov 1981 08:52:00 GMT + Pragma: + - no-cache + X-Content-Type-Options: + - nosniff + X-Envoy-Upstream-Service-Time: + - '238' + X-Request-Id: + - 03db6c57-812f-4113-961f-49afdd44f47c + Cf-Cache-Status: + - DYNAMIC + Cf-Request-Id: + - '08bf36dcd60000f3cfe7b22000000001' + Expect-Ct: + - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" + Server: + - cloudflare + Cf-Ray: + - 62def40e2ae8f3cf-GRU + body: + encoding: UTF-8 + string: '{"contact":{"email":"mikael@mhenrixon.com","phone":"+491735728523","firstName":"Mikael","lastName":"Henriksson","email_empty":false,"cdate":"2021-03-10T13:29:42-06:00","udate":"2021-03-10T13:29:42-06:00","orgid":"","orgname":"","accountContacts":[],"links":{"bounceLogs":"https:\/\/inveniobr.api-us1.com\/api\/3\/contacts\/5\/bounceLogs","contactAutomations":"https:\/\/inveniobr.api-us1.com\/api\/3\/contacts\/5\/contactAutomations?limit=1000&orders%5Blastdate%5D=DESC","contactData":"https:\/\/inveniobr.api-us1.com\/api\/3\/contacts\/5\/contactData","contactGoals":"https:\/\/inveniobr.api-us1.com\/api\/3\/contacts\/5\/contactGoals","contactLists":"https:\/\/inveniobr.api-us1.com\/api\/3\/contacts\/5\/contactLists","contactLogs":"https:\/\/inveniobr.api-us1.com\/api\/3\/contacts\/5\/contactLogs","contactTags":"https:\/\/inveniobr.api-us1.com\/api\/3\/contacts\/5\/contactTags","contactDeals":"https:\/\/inveniobr.api-us1.com\/api\/3\/contacts\/5\/contactDeals","deals":"https:\/\/inveniobr.api-us1.com\/api\/3\/contacts\/5\/deals","fieldValues":"https:\/\/inveniobr.api-us1.com\/api\/3\/contacts\/5\/fieldValues","geoIps":"https:\/\/inveniobr.api-us1.com\/api\/3\/contacts\/5\/geoIps","notes":"https:\/\/inveniobr.api-us1.com\/api\/3\/contacts\/5\/notes","organization":"https:\/\/inveniobr.api-us1.com\/api\/3\/contacts\/5\/organization","plusAppend":"https:\/\/inveniobr.api-us1.com\/api\/3\/contacts\/5\/plusAppend","trackingLogs":"https:\/\/inveniobr.api-us1.com\/api\/3\/contacts\/5\/trackingLogs","scoreValues":"https:\/\/inveniobr.api-us1.com\/api\/3\/contacts\/5\/scoreValues","automationEntryCounts":"https:\/\/inveniobr.api-us1.com\/api\/3\/contacts\/5\/automationEntryCounts"},"hash":"45ad71261e9d4f250da7cae121ce059c","id":"5","organization":""}}' + recorded_at: Wed, 10 Mar 2021 19:29:42 GMT +- request: + method: post + uri: "/lists" + body: + encoding: UTF-8 + string: '{"list":{"name":"Awesome List","stringid":"awesome-list","sender_url":"https://mhenrixon.com","sender_reminder":"This + is why we are sending you this"}}' + headers: + User-Agent: + - ActiveCampaign Ruby Client (v3.0.0) + Accept: + - application/json + Content-Type: + - application/json + Api-Token: + - "" + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 201 + message: Created + headers: + Date: + - Wed, 10 Mar 2021 19:29:43 GMT + Content-Type: + - application/json + Content-Length: + - '479' + Connection: + - keep-alive + Set-Cookie: + - PHPSESSID=695cbcd669f8640e6a9f47ba360d320f; path=/; HttpOnly + - __cfduid=d22117441c96b1ec0d530831a3e37a9931615404582; expires=Fri, 09-Apr-21 + 19:29:42 GMT; path=/; domain=.api-us1.com; HttpOnly; SameSite=Lax + - em_acp_globalauth_cookie=1d9b50d4-0a97-4e18-ac58-af1094d2ad67; path=/; domain=.inveniobr.api-us1.com; + secure; httponly + - em_acp_globalauth_cookie=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; + path=/; domain=.inveniobr.api-us1.com + - em_acp_globalauth_cookie=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; + path=/; domain=.inveniobr.api-us1.com + - em_acp_globalauth_cookie=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; + path=/; domain=.inveniobr.api-us1.com + Cache-Control: + - no-store, no-cache, must-revalidate + Expires: + - Thu, 19 Nov 1981 08:52:00 GMT + Pragma: + - no-cache + X-Envoy-Upstream-Service-Time: + - '692' + X-Request-Id: + - '0488a3f6-7820-4ffc-b1d1-5b62dcba710e' + Cf-Cache-Status: + - DYNAMIC + Cf-Request-Id: + - '08bf36dec400004b2f5a343000000001' + Expect-Ct: + - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" + Server: + - cloudflare + Cf-Ray: + - 62def41139204b2f-GRU + body: + encoding: UTF-8 + string: '{"list":{"name":"Awesome List","stringid":"awesome-list","sender_url":"https:\/\/mhenrixon.com","sender_reminder":"This + is why we are sending you this","cdate":"2021-03-10T13:29:42-06:00","udate":"2021-03-10T13:29:42-06:00","links":{"contactGoalLists":"https:\/\/inveniobr.api-us1.com\/api\/3\/lists\/4\/contactGoalLists","user":"https:\/\/inveniobr.api-us1.com\/api\/3\/lists\/4\/user","addressLists":"https:\/\/inveniobr.api-us1.com\/api\/3\/lists\/4\/addressLists"},"id":"4"}}' + recorded_at: Wed, 10 Mar 2021 19:29:43 GMT +- request: + method: post + uri: "/contactLists" + body: + encoding: UTF-8 + string: '{"contactList":{"contact":"5","list":"4"}}' + headers: + User-Agent: + - ActiveCampaign Ruby Client (v3.0.0) + Accept: + - application/json + Content-Type: + - application/json + Api-Token: + - "" + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 201 + message: Created + headers: + Date: + - Wed, 10 Mar 2021 19:29:43 GMT + Content-Type: + - application/json + Content-Length: + - '3137' + Connection: + - keep-alive + Set-Cookie: + - PHPSESSID=f2a67f6fafb2fcc32b752fe756ca3e42; path=/; HttpOnly + - __cfduid=d44445f69b57ff182120d3b6988ae374a1615404583; expires=Fri, 09-Apr-21 + 19:29:43 GMT; path=/; domain=.api-us1.com; HttpOnly; SameSite=Lax + - em_acp_globalauth_cookie=4f39b0ec-b246-43f6-8dc8-fa41b0d4c4ea; path=/; domain=.inveniobr.api-us1.com; + secure; httponly + - em_acp_globalauth_cookie=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; + path=/; domain=.inveniobr.api-us1.com + - em_acp_globalauth_cookie=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; + path=/; domain=.inveniobr.api-us1.com + - em_acp_globalauth_cookie=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; + path=/; domain=.inveniobr.api-us1.com + Cache-Control: + - no-store, no-cache, must-revalidate + Expires: + - Thu, 19 Nov 1981 08:52:00 GMT + Pragma: + - no-cache + X-Envoy-Upstream-Service-Time: + - '125' + X-Request-Id: + - 6cb3e74e-a3f6-444b-a4c7-ff6517dff0eb + Cf-Cache-Status: + - DYNAMIC + Cf-Request-Id: + - '08bf36e25600004b2f5c3fd000000001' + Expect-Ct: + - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" + Server: + - cloudflare + Cf-Ray: + - 62def416fed74b2f-GRU + body: + encoding: UTF-8 + string: '{"contacts":[{"cdate":"2021-03-10T13:29:42-06:00","email":"mikael@mhenrixon.com","phone":"+491735728523","firstName":"Mikael","lastName":"Henriksson","orgid":"0","orgname":"","segmentio_id":"","bounced_hard":"0","bounced_soft":"0","bounced_date":null,"ip":"0","ua":null,"hash":"45ad71261e9d4f250da7cae121ce059c","socialdata_lastcheck":null,"email_local":"","email_domain":"","sentcnt":"0","rating_tstamp":null,"gravatar":"0","deleted":"0","anonymized":"0","adate":null,"udate":"2021-03-10T13:29:42-06:00","edate":null,"deleted_at":null,"created_utc_timestamp":"2021-03-10 + 13:29:42","updated_utc_timestamp":"2021-03-10 13:29:42","created_timestamp":"2021-03-10 + 13:29:42","updated_timestamp":"2021-03-10 13:29:42","created_by":null,"updated_by":null,"email_empty":false,"accountContacts":[],"links":{"bounceLogs":"https:\/\/inveniobr.api-us1.com\/api\/3\/contacts\/5\/bounceLogs","contactAutomations":"https:\/\/inveniobr.api-us1.com\/api\/3\/contacts\/5\/contactAutomations?limit=1000&orders%5Blastdate%5D=DESC","contactData":"https:\/\/inveniobr.api-us1.com\/api\/3\/contacts\/5\/contactData","contactGoals":"https:\/\/inveniobr.api-us1.com\/api\/3\/contacts\/5\/contactGoals","contactLists":"https:\/\/inveniobr.api-us1.com\/api\/3\/contacts\/5\/contactLists","contactLogs":"https:\/\/inveniobr.api-us1.com\/api\/3\/contacts\/5\/contactLogs","contactTags":"https:\/\/inveniobr.api-us1.com\/api\/3\/contacts\/5\/contactTags","contactDeals":"https:\/\/inveniobr.api-us1.com\/api\/3\/contacts\/5\/contactDeals","deals":"https:\/\/inveniobr.api-us1.com\/api\/3\/contacts\/5\/deals","fieldValues":"https:\/\/inveniobr.api-us1.com\/api\/3\/contacts\/5\/fieldValues","geoIps":"https:\/\/inveniobr.api-us1.com\/api\/3\/contacts\/5\/geoIps","notes":"https:\/\/inveniobr.api-us1.com\/api\/3\/contacts\/5\/notes","organization":"https:\/\/inveniobr.api-us1.com\/api\/3\/contacts\/5\/organization","plusAppend":"https:\/\/inveniobr.api-us1.com\/api\/3\/contacts\/5\/plusAppend","trackingLogs":"https:\/\/inveniobr.api-us1.com\/api\/3\/contacts\/5\/trackingLogs","scoreValues":"https:\/\/inveniobr.api-us1.com\/api\/3\/contacts\/5\/scoreValues","automationEntryCounts":"https:\/\/inveniobr.api-us1.com\/api\/3\/contacts\/5\/automationEntryCounts"},"id":"5","organization":null}],"contactList":{"list":"4","contact":"5","sdate":"2021-03-10T13:29:43-06:00","first_name":"Mikael","last_name":"Henriksson","sourceid":3,"unsubreason":"","unsubscribeAutomation":null,"links":{"automation":"https:\/\/inveniobr.api-us1.com\/api\/3\/contactLists\/5\/automation","list":"https:\/\/inveniobr.api-us1.com\/api\/3\/contactLists\/5\/list","contact":"https:\/\/inveniobr.api-us1.com\/api\/3\/contactLists\/5\/contact","form":"https:\/\/inveniobr.api-us1.com\/api\/3\/contactLists\/5\/form","autosyncLog":"https:\/\/inveniobr.api-us1.com\/api\/3\/contactLists\/5\/autosyncLog","campaign":"https:\/\/inveniobr.api-us1.com\/api\/3\/contactLists\/5\/campaign","unsubscribeAutomation":"https:\/\/inveniobr.api-us1.com\/api\/3\/contactLists\/5\/unsubscribeAutomation","message":"https:\/\/inveniobr.api-us1.com\/api\/3\/contactLists\/5\/message"},"status":"","id":"5"}}' + recorded_at: Wed, 10 Mar 2021 19:29:43 GMT +- request: + method: delete + uri: "/lists/4" + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - ActiveCampaign Ruby Client (v3.0.0) + Accept: + - application/json + Content-Type: + - application/json + Api-Token: + - "" + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 200 + message: OK + headers: + Date: + - Wed, 10 Mar 2021 19:29:44 GMT + Content-Type: + - application/json + Content-Length: + - '2' + Connection: + - keep-alive + Set-Cookie: + - PHPSESSID=8af7368c8348baf51043b90d37b077f1; path=/; HttpOnly + - __cfduid=d63b400427a9edc1cd8e7616fae8a2c851615404583; expires=Fri, 09-Apr-21 + 19:29:43 GMT; path=/; domain=.api-us1.com; HttpOnly; SameSite=Lax + - em_acp_globalauth_cookie=0355c0ad-0337-48b4-b2d9-1ffe09ad1425; path=/; domain=.inveniobr.api-us1.com; + secure; httponly + - em_acp_globalauth_cookie=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; + path=/; domain=.inveniobr.api-us1.com + - em_acp_globalauth_cookie=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; + path=/; domain=.inveniobr.api-us1.com + - em_acp_globalauth_cookie=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; + path=/; domain=.inveniobr.api-us1.com + Cache-Control: + - no-store, no-cache, must-revalidate + Expires: + - Thu, 19 Nov 1981 08:52:00 GMT + Pragma: + - no-cache + X-Envoy-Upstream-Service-Time: + - '242' + X-Request-Id: + - 2da8254e-4311-4454-98a3-863674e535ed + Cf-Cache-Status: + - DYNAMIC + Cf-Request-Id: + - '08bf36e3b5000051f2bd3c0000000001' + Expect-Ct: + - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" + Server: + - cloudflare + Cf-Ray: + - 62def4192dba51f2-GRU + body: + encoding: UTF-8 + string: "{}" + recorded_at: Wed, 10 Mar 2021 19:29:44 GMT +- request: + method: delete + uri: "/lists/4" + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - ActiveCampaign Ruby Client (v3.0.0) + Accept: + - application/json + Content-Type: + - application/json + Api-Token: + - "" + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 404 + message: Not Found + headers: + Date: + - Wed, 10 Mar 2021 19:29:44 GMT + Content-Type: + - application/json + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Set-Cookie: + - PHPSESSID=5fe475c0184ef3b5e97ed00ad1098719; path=/; HttpOnly + - __cfduid=d6f516fc75bbe258e66621df6502f43041615404584; expires=Fri, 09-Apr-21 + 19:29:44 GMT; path=/; domain=.api-us1.com; HttpOnly; SameSite=Lax + - em_acp_globalauth_cookie=61379498-50a7-4a6c-8340-80144575fde1; path=/; domain=.inveniobr.api-us1.com; + secure; httponly + - em_acp_globalauth_cookie=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; + path=/; domain=.inveniobr.api-us1.com + - em_acp_globalauth_cookie=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; + path=/; domain=.inveniobr.api-us1.com + - em_acp_globalauth_cookie=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; + path=/; domain=.inveniobr.api-us1.com + Cache-Control: + - no-store, no-cache, must-revalidate + Expires: + - Thu, 19 Nov 1981 08:52:00 GMT + Pragma: + - no-cache + X-Envoy-Upstream-Service-Time: + - '110' + X-Request-Id: + - caf63798-51a2-4a86-9498-9798bc430c79 + Cf-Cache-Status: + - DYNAMIC + Cf-Request-Id: + - '08bf36e58a0000d01ce6859000000001' + Expect-Ct: + - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" + Server: + - cloudflare + Cf-Ray: + - 62def41c1fbdd01c-GRU + body: + encoding: ASCII-8BIT + string: '{"message":"No Result found for _List with id 4"}' + recorded_at: Wed, 10 Mar 2021 19:29:44 GMT +- request: + method: delete + uri: "/contacts/5" + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - ActiveCampaign Ruby Client (v3.0.0) + Accept: + - application/json + Content-Type: + - application/json + Api-Token: + - "" + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 404 + message: Not Found + headers: + Date: + - Wed, 10 Mar 2021 19:29:45 GMT + Content-Type: + - application/json + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Set-Cookie: + - PHPSESSID=078005f44950a3ccf6a8ea8c5a173771; path=/; HttpOnly + - __cfduid=de68f26aafd8532ac3545e358b42683fb1615404585; expires=Fri, 09-Apr-21 + 19:29:45 GMT; path=/; domain=.api-us1.com; HttpOnly; SameSite=Lax + - em_acp_globalauth_cookie=3c1fc9ce-7a25-48be-846c-0c4e72794e2e; path=/; domain=.inveniobr.api-us1.com; + secure; httponly + - em_acp_globalauth_cookie=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; + path=/; domain=.inveniobr.api-us1.com + - em_acp_globalauth_cookie=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; + path=/; domain=.inveniobr.api-us1.com + - em_acp_globalauth_cookie=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; + path=/; domain=.inveniobr.api-us1.com + Cache-Control: + - no-store, no-cache, must-revalidate + Expires: + - Thu, 19 Nov 1981 08:52:00 GMT + Pragma: + - no-cache + X-Envoy-Upstream-Service-Time: + - '148' + X-Request-Id: + - fd0b2576-0fb2-4f4d-aef4-e9b879935dbd + Cf-Cache-Status: + - DYNAMIC + Cf-Request-Id: + - '08bf36e84d0000f6b3ae105000000001' + Expect-Ct: + - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" + Server: + - cloudflare + Cf-Ray: + - 62def4207ce1f6b3-GRU + body: + encoding: ASCII-8BIT + string: '{"message":"No Result found for Subscriber with id 5"}' + recorded_at: Wed, 10 Mar 2021 19:29:45 GMT +recorded_with: VCR 6.0.0 diff --git a/spec/lib/active_campaign/api/contact_lists_spec.rb b/spec/lib/active_campaign/api/contact_lists_spec.rb new file mode 100644 index 0000000..efe20b4 --- /dev/null +++ b/spec/lib/active_campaign/api/contact_lists_spec.rb @@ -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 diff --git a/spec/support/shared_contexts.rb b/spec/support/shared_contexts.rb index 0771376..12952a6 100644 --- a/spec/support/shared_contexts.rb +++ b/spec/support/shared_contexts.rb @@ -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' diff --git a/spec/support/shared_contexts/with_contact_list.rb b/spec/support/shared_contexts/with_contact_list.rb new file mode 100644 index 0000000..9890cb8 --- /dev/null +++ b/spec/support/shared_contexts/with_contact_list.rb @@ -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 diff --git a/spec/support/shared_contexts/with_existing_contact.rb b/spec/support/shared_contexts/with_existing_contact.rb index 54d6638..3b38384 100644 --- a/spec/support/shared_contexts/with_existing_contact.rb +++ b/spec/support/shared_contexts/with_existing_contact.rb @@ -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)' }