Skip to content

https://mobileaws.atlassian.net/browse/CLOUD-2712#1

Open
dlopezallcode wants to merge 1 commit intomainfrom
CLOUD-2712
Open

https://mobileaws.atlassian.net/browse/CLOUD-2712#1
dlopezallcode wants to merge 1 commit intomainfrom
CLOUD-2712

Conversation

@dlopezallcode
Copy link
Copy Markdown

Overview

The Ruby SDK has been brought to complete parity with the reference Java SDK. Critical hardcoded URL bugs were fixed, Webhook CRUD was completed, and Contact Service and MD5 caching in MMS were added. The SDK passes 60/60 unit tests.


Implemented Changes

1. Hardcoded URL Fix in Email Service (lib/ccai/email/email_service.rb) 🔴

Before: the service had a hardcoded BASE_URL constant pointing to the test environment, completely ignoring client configuration.

After: uses @client.email_base_url dynamically, which comes from Config with correct test/prod switching. Also fixed:

  • Headers AccountId and ClientId are now passed correctly.
  • Removed ?send=true from endpoint (not required by API).
  • Removed unnecessary Origin header.

Intentional breaking change: Users who were not using use_test_environment: true now send emails to production (correct behavior).


2. Hardcoded Base URL Fix in Client (lib/ccai/client.rb) 🔴

Before: the default of base_url pointed to https://core-test-cloudcontactai.allcode.com/api (test environment).

After: the default now points to https://core.cloudcontactai.com/api (production). Test environment is activated explicitly with use_test_environment: true.

Intentional breaking change: Users who instantiate CCAI.new(client_id:, api_key:) without use_test_environment: true now send to production automatically.


3. Test/Prod Environment Switching (lib/ccai/client.rb, lib/ccai.rb)

Before: no formal mechanism to alternate between environments.

After (Config):

  • use_test_environment: false (default)
  • If true: base_url, email_base_url, files_base_url point to *-test-cloudcontactai.allcode.com domains
  • Resolution by priority: explicit parameter > environment variable > default test/prod
  • Environment variables: CCAI_BASE_URL, CCAI_EMAIL_BASE_URL, CCAI_FILES_BASE_URL
  • Getters: base_url, email_base_url, files_base_url, test_environment?

4. Complete Webhook CRUD (lib/ccai/webhook_service.rb)

Before: the service existed but was incomplete (register, update, list, delete were missing) and verify_signature had an incorrect test.

After:

  • register(config)POST /v1/client/{clientId}/integration (sends array [{...}], returns first element)
  • update(id, config) — POST to same endpoint with id converted to int in payload
  • listGET /v1/client/{clientId}/integration
  • delete(id)DELETE /v1/client/{clientId}/integration/{id}
  • parse_event(json_payload) — decodes JSON locally
  • verify_signature — already existed; test was fixed to use real HMAC instead of fake signature

Documented traps:

  • The API expects [{...}] not {...}.
  • Update uses POST to the same endpoint as register.

5. New Service: Contact (lib/ccai/contact/contact_service.rb)

Before: the SDK had no contact management support.

After:

  • set_do_not_text(do_not_text, contact_id: nil, phone: nil) — SMS opt-out / opt-in

Endpoint: PUT /account/do-not-text

Registered in Client as @contact.


6. MD5 Cache in MMS (lib/ccai/sms/mms_service.rb)

Before: send_with_image() always uploaded the image without checking for duplicates.

After:

  • md5_file(file_path) private — uses Digest::MD5.file(file_path).hexdigest
  • check_file_uploaded(file_key) public — queries GET /clients/{clientId}/storedUrl?fileKey={fileKey}
  • send_with_image() rewritten: computes MD5 → constructs {clientId}/campaign/{md5}.{ext} → checks if exists → if yes, skips upload → sends
  • Bonus fix: get_signed_upload_url() now uses @client.files_base_url instead of hardcoded URL

Compatibility Notes

  • sms, mms do not change in their public interface — backward compatible.
  • The URL default change (test → production) is an intentional and necessary breaking change. Must be communicated in changelog.
  • use_test_environment: true is the parameter to maintain previous behavior if any user needs it.

@dlopezallcode dlopezallcode marked this pull request as ready for review April 16, 2026 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants