klaviyo / php-klaviyo

PHP wrapper for the Klaviyo API
59 stars 47 forks source link

Data Privacy API Name Needs to be CamelCased to Avoid "Sorry, dataprivacy is not a valid Klaviyo API" #69

Closed GuyPaddock closed 3 years ago

GuyPaddock commented 3 years ago

The docs say that the data privacy API can be used like this:

#Request profile deletion by email
$client->dataprivacy->requestProfileDeletion('someone@mailinator.com');

#Request profile deletion by phone number
$client->dataprivacy->requestProfileDeletion('1-234-567-8910', 'phone_number');

#Request profile deletion by person ID
$client->dataprivacy->requestProfileDeletion('abc123', 'person_id');

However, this leads to inconsistent behavior on different systems depending upon whether PHP is running on a case-sensitive filesystem. If the filesystem is case sensitive, using the above examples will yield this error:

Klaviyo\Exception\KlaviyoException: Sorry, dataprivacy is not a valid Klaviyo API. in Klaviyo\Klaviyo->__get() (line 72 of /code/vendor/klaviyo/php-sdk/src/Klaviyo.php).

The following seems more reliable:

#Request profile deletion by email
$client->dataPrivacy->requestProfileDeletion('someone@mailinator.com');

#Request profile deletion by phone number
$client->dataPrivacy->requestProfileDeletion('1-234-567-8910', 'phone_number');

#Request profile deletion by person ID
$client->dataPrivacy->requestProfileDeletion('abc123', 'person_id');

It looks like this has to do with the way that the pseudo-fields are transformed into class names using ucwords, which only affects the first letter of the class name; meanwhile, the name of the actual API class is DataPrivacy so the name going in needs to be lower-camel for the file to be found by the auto-loader.

njparadis commented 3 years ago

Fixed by #70