├── .editorconfig ├── .gitattributes ├── .gitignore ├── .htaccess ├── .scrutinizer.yml ├── .travis.yml ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── composer.json ├── composer.lock ├── phpunit.xml └── src ├── Contract ├── PardotApi.php ├── PardotAuthenticator.php └── QueryObject.php ├── Formatter └── JsonFormatter.php ├── PardotApi.php ├── PardotAuthenticator.php ├── Query ├── AccountsQuery.php ├── CampaignsQuery.php ├── CustomFieldsQuery.php ├── CustomRedirectsQuery.php ├── DynamicContentQuery.php ├── EmailClicksQuery.php ├── EmailQuery.php ├── EmailTemplatesQuery.php ├── FormsQuery.php ├── LifecycleHistoriesQuery.php ├── LifecycleStagesQuery.php ├── ListMembershipsQuery.php ├── ListsQuery.php ├── OpportunitiesQuery.php ├── ProspectAccountsQuery.php ├── ProspectsQuery.php ├── Query.php ├── TagObjectsQuery.php ├── TagsQuery.php ├── UsersQuery.php ├── VisitorActivitiesQuery.php ├── VisitorsQuery.php └── VisitsQuery.php ├── Traits ├── CanCreate.php ├── CanDelete.php ├── CanQuery.php ├── CanRead.php └── CanUpdate.php └── Validator ├── BooleanValidator.php ├── DateValidator.php ├── FixedValuesValidator.php ├── PositiveIntListValidator.php ├── PositiveIntValidator.php ├── SortOrderValidator.php ├── StringValidator.php └── Validator.php /.editorconfig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cyber-Duck/Pardot-API/16770cf9b551a93cd328d1007093f4d0873b24b0/.editorconfig -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cyber-Duck/Pardot-API/16770cf9b551a93cd328d1007093f4d0873b24b0/.gitattributes -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .sass-cache 2 | 3 | /vendor/ -------------------------------------------------------------------------------- /.htaccess: -------------------------------------------------------------------------------- 1 | 2 | Deny from all 3 | -------------------------------------------------------------------------------- /.scrutinizer.yml: -------------------------------------------------------------------------------- 1 | checks: 2 | php: true -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 5.4 5 | - 5.5 6 | - 5.6 7 | - hhvm 8 | 9 | before_script: 10 | - composer self-update 11 | - composer install --prefer-source --no-interaction --dev 12 | 13 | script: phpunit -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cyber-Duck/Pardot-API/16770cf9b551a93cd328d1007093f4d0873b24b0/CHANGELOG.md -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cyber-Duck/Pardot-API/16770cf9b551a93cd328d1007093f4d0873b24b0/CODE_OF_CONDUCT.md -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cyber-Duck/Pardot-API/16770cf9b551a93cd328d1007093f4d0873b24b0/CONTRIBUTING.md -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023 Cyber-Duck Ltd 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Pardot-API 2 | PHP package to interact with the Pardot API 3 | 4 | [![Latest Stable Version](https://poser.pugx.org/cyber-duck/pardot-api/v/stable)](https://packagist.org/packages/cyber-duck/pardot-api) 5 | [![Latest Unstable Version](https://poser.pugx.org/cyber-duck/pardot-api/v/unstable)](https://packagist.org/packages/cyber-duck/pardot-api) 6 | [![Total Downloads](https://poser.pugx.org/cyber-duck/pardot-api/downloads)](https://packagist.org/packages/cyber-duck/pardot-api) 7 | [![License](https://poser.pugx.org/cyber-duck/pardot-api/license)](https://packagist.org/packages/cyber-duck/pardot-api) 8 | 9 | Author: [Andrew Mc Cormack](https://github.com/Andrew-Mc-Cormack) 10 | 11 | ## Pardot API PHP Library 12 | 13 | A library to integrate with the Pardot API through PHP objects 14 | 15 | This library simplifies the process of authentication and querying the Pardot API and provides access to all of the v4 API features. 16 | 17 | Latest Version 2.0.0 supports Salesforce SSO authentication. 18 | 19 | ### Setup 20 | 21 | To initalise the Pardot API object pass your user email, password, client id, client secret and business unit id credentials. 22 | Any subsequent request to fetch data from the API will automatically perform the authentication actions before trying to fetch data. 23 | 24 | ```php 25 | use CyberDuck\PardotApi\PardotApi; 26 | 27 | $pardot = new PardotApi( 28 | 'EMAIL', 29 | 'PASSWORD', 30 | 'CLIENT_ID', 31 | 'CLIENT_SECRET', 32 | 'BUSINESS_UNIT_ID', 33 | ); 34 | ``` 35 | 36 | ## Querying the API 37 | 38 | You can call the query method on an any pardot object passing the object, operator, and data array (optional) 39 | 40 | ```php 41 | $result = $pardot->request('campaign', 'read/id/1'); 42 | 43 | $result = $pardot->request('campaign', 'query', ['created_after' => 'today']); 44 | ``` 45 | 46 | ## Object Methods 47 | 48 | The PardotApi instance has functions which correspond to the object types in Pardot to simplify calls to the API. 49 | When calling one of these functions a query object is returned (->campaigns() returns a CampaignsQuery object). 50 | These returned objects in turn have functions corresponding to different object actions such as query, create, update, insert, delete etc. 51 | The full list of objects available are as follows: 52 | 53 | ### Account methods 54 | 55 | ```php 56 | $pardot->account()->read(); // retrieves current account information 57 | ``` 58 | 59 | ### Campaign methods 60 | 61 | ```php 62 | $pardot->campaign()->query([...]); // queries and returns a filtered list 63 | $pardot->campaign()->create([...]); // creates an object using passed array data 64 | $pardot->campaign()->read(1); // queries an object by ID 65 | $pardot->campaign()->update(1, [...]); // updates an object by ID using passed array data 66 | ``` 67 | 68 | ### Custom Fields methods 69 | 70 | ```php 71 | $pardot->customField()->query([...]); // queries and returns a filtered list 72 | $pardot->customField()->create([...]); // creates an object using passed array data 73 | $pardot->customField()->read(1); // queries an object by ID 74 | $pardot->customField()->update(1, [...]); // updates an object by ID using passed array data 75 | $pardot->customField()->delete(1); // deletes an object by ID 76 | ``` 77 | 78 | ### Custom Redirects methods 79 | 80 | ```php 81 | $pardot->customRedirect()->query([...]); // queries and returns a filtered list 82 | $pardot->customRedirect()->read(1); // queries an object by ID 83 | ``` 84 | 85 | ### Dynamic Content methods 86 | 87 | ```php 88 | $pardot->dynamicContent()->query([...]); // queries and returns a filtered list 89 | $pardot->dynamicContent()->read(1); // queries an object by ID 90 | ``` 91 | 92 | ### Email Clicks methods 93 | 94 | ```php 95 | $pardot->emailClick()->query([...]); // queries and returns a filtered list 96 | ``` 97 | 98 | ### Email methods 99 | 100 | ```php 101 | $pardot->email()->read(1); // queries an object by ID 102 | $pardot->email()->stats(1); // Returns the statistical data for the list email 103 | $pardot->email()->sendToID(1, [...]); // Sends a 1 to 1 email to an ID using an array of email config / data 104 | $pardot->email()->sendToEmail('name@example.com', [...]); // Sends a 1 to 1 email to a email address an array of email config / data 105 | $pardot->email()->send([...]); // send an email to a list of IDs 106 | ``` 107 | 108 | ### Email Templates methods 109 | 110 | ```php 111 | $pardot->emailTemplate()->listOneToOne(); // Returns a list of email templates used in 1 to 1 emails 112 | ``` 113 | 114 | ### Forms methods 115 | 116 | ```php 117 | $pardot->form()->query([...]); // queries and returns a filtered list 118 | $pardot->form()->read(1); // queries an object by ID 119 | ``` 120 | 121 | ### Lifecycle Histories methods 122 | 123 | ```php 124 | $pardot->lifecycleHistory()->query([...]); // queries and returns a filtered list 125 | $pardot->lifecycleHistory()->read(1); // queries an object by ID 126 | ``` 127 | 128 | ### Lifecycle Stages methods 129 | 130 | ```php 131 | $pardot->lifecycleStage()->query([...]); // queries and returns a filtered list 132 | ``` 133 | 134 | ### List Memberships methods 135 | 136 | ```php 137 | // @todo 138 | ``` 139 | 140 | ### Lists methods 141 | 142 | ```php 143 | // @todo 144 | ``` 145 | 146 | ### Opportunities methods 147 | 148 | ```php 149 | // @todo 150 | ``` 151 | 152 | ### Prospect Accounts methods 153 | 154 | ```php 155 | // @todo 156 | ``` 157 | 158 | ### Prospects methods 159 | 160 | ```php 161 | // @todo 162 | ``` 163 | 164 | ### Tag Objects methods 165 | 166 | ```php 167 | $pardot->tagObject()->query([...]); // queries and returns a filtered list 168 | $pardot->tagObject()->read(1); // queries an object by ID 169 | ``` 170 | 171 | ### Tags methods 172 | 173 | ```php 174 | $pardot->tag()->query([...]); // queries and returns a filtered list 175 | $pardot->tag()->read(1); // queries an object by ID 176 | ``` 177 | 178 | ### Users methods 179 | 180 | ```php 181 | $pardot->user()->query([...]); // queries and returns a filtered list 182 | $pardot->user()->read(1); // queries an object by ID 183 | $pardot->user()->readByEmail('name@example.com'); // queries an object by email 184 | ``` 185 | 186 | ### Visitor Activities methods 187 | 188 | ```php 189 | // @todo 190 | ``` 191 | 192 | ### Visitors methods 193 | 194 | ```php 195 | $pardot->visitor()->query([...]); // queries and returns a filtered list 196 | $pardot->visitor()->read(1); // queries an object by ID 197 | $pardot->visitor()->assign(1,2); // Assigns or reassigns the visitor by ID to a prospect ID. 198 | ``` 199 | 200 | ### Visits methods 201 | 202 | ```php 203 | $pardot->visit()->query([...]); // queries and returns a filtered list 204 | $pardot->visit()->read(1); // queries an object by ID 205 | ``` 206 | 207 | ## Debugging 208 | 209 | Error messages can be enabled by turning debugging on. Requests to the Pardot API will fail silently by default so as to prevent 210 | fatal application errors. Extra response checking should be conducted when implementing this library as most methods will return 211 | null when there is an issue with the API query. 212 | 213 | ```php 214 | $pardot->setDebug(true); 215 | ``` 216 | 217 | ## Output Type 218 | 219 | You can change the output type to full, simple, mobile, or bulk. Defaults to full. 220 | 221 | ```php 222 | $pardot->setOuput('full'); 223 | ``` 224 | 225 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cyber-duck/pardot-api", 3 | "description": "PHP package to interact with the Pardot API", 4 | "homepage": "https://github.com/cyber-duck/pardot-api", 5 | "keywords": [ 6 | "php", 7 | "pardot" 8 | ], 9 | "license": "MIT", 10 | "authors": [ 11 | { 12 | "name": "Andrew Mc Cormack", 13 | "email": "andy@cyber-duck.co.uk" 14 | } 15 | ], 16 | "support": { 17 | "issues": "https://github.com/cyber-duck/pardot-api" 18 | }, 19 | "extra": { 20 | "installer-name": "pardot-api" 21 | }, 22 | "require": { 23 | "guzzlehttp/guzzle": "6.3.*" 24 | }, 25 | "autoload": { 26 | "classmap": [ 27 | "src/" 28 | ] 29 | }, 30 | "prefer-stable": true 31 | } 32 | -------------------------------------------------------------------------------- /composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", 5 | "This file is @generated automatically" 6 | ], 7 | "content-hash": "6c3e21c4fb8df260acdcb6c0be58af2b", 8 | "packages": [ 9 | { 10 | "name": "guzzlehttp/guzzle", 11 | "version": "6.3.3", 12 | "source": { 13 | "type": "git", 14 | "url": "https://github.com/guzzle/guzzle.git", 15 | "reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba" 16 | }, 17 | "dist": { 18 | "type": "zip", 19 | "url": "https://api.github.com/repos/guzzle/guzzle/zipball/407b0cb880ace85c9b63c5f9551db498cb2d50ba", 20 | "reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba", 21 | "shasum": "" 22 | }, 23 | "require": { 24 | "guzzlehttp/promises": "^1.0", 25 | "guzzlehttp/psr7": "^1.4", 26 | "php": ">=5.5" 27 | }, 28 | "require-dev": { 29 | "ext-curl": "*", 30 | "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4 || ^7.0", 31 | "psr/log": "^1.0" 32 | }, 33 | "suggest": { 34 | "psr/log": "Required for using the Log middleware" 35 | }, 36 | "type": "library", 37 | "extra": { 38 | "branch-alias": { 39 | "dev-master": "6.3-dev" 40 | } 41 | }, 42 | "autoload": { 43 | "files": [ 44 | "src/functions_include.php" 45 | ], 46 | "psr-4": { 47 | "GuzzleHttp\\": "src/" 48 | } 49 | }, 50 | "notification-url": "https://packagist.org/downloads/", 51 | "license": [ 52 | "MIT" 53 | ], 54 | "authors": [ 55 | { 56 | "name": "Michael Dowling", 57 | "email": "mtdowling@gmail.com", 58 | "homepage": "https://github.com/mtdowling" 59 | } 60 | ], 61 | "description": "Guzzle is a PHP HTTP client library", 62 | "homepage": "http://guzzlephp.org/", 63 | "keywords": [ 64 | "client", 65 | "curl", 66 | "framework", 67 | "http", 68 | "http client", 69 | "rest", 70 | "web service" 71 | ], 72 | "time": "2018-04-22T15:46:56+00:00" 73 | }, 74 | { 75 | "name": "guzzlehttp/promises", 76 | "version": "v1.3.1", 77 | "source": { 78 | "type": "git", 79 | "url": "https://github.com/guzzle/promises.git", 80 | "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646" 81 | }, 82 | "dist": { 83 | "type": "zip", 84 | "url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646", 85 | "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646", 86 | "shasum": "" 87 | }, 88 | "require": { 89 | "php": ">=5.5.0" 90 | }, 91 | "require-dev": { 92 | "phpunit/phpunit": "^4.0" 93 | }, 94 | "type": "library", 95 | "extra": { 96 | "branch-alias": { 97 | "dev-master": "1.4-dev" 98 | } 99 | }, 100 | "autoload": { 101 | "psr-4": { 102 | "GuzzleHttp\\Promise\\": "src/" 103 | }, 104 | "files": [ 105 | "src/functions_include.php" 106 | ] 107 | }, 108 | "notification-url": "https://packagist.org/downloads/", 109 | "license": [ 110 | "MIT" 111 | ], 112 | "authors": [ 113 | { 114 | "name": "Michael Dowling", 115 | "email": "mtdowling@gmail.com", 116 | "homepage": "https://github.com/mtdowling" 117 | } 118 | ], 119 | "description": "Guzzle promises library", 120 | "keywords": [ 121 | "promise" 122 | ], 123 | "time": "2016-12-20T10:07:11+00:00" 124 | }, 125 | { 126 | "name": "guzzlehttp/psr7", 127 | "version": "1.4.2", 128 | "source": { 129 | "type": "git", 130 | "url": "https://github.com/guzzle/psr7.git", 131 | "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c" 132 | }, 133 | "dist": { 134 | "type": "zip", 135 | "url": "https://api.github.com/repos/guzzle/psr7/zipball/f5b8a8512e2b58b0071a7280e39f14f72e05d87c", 136 | "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c", 137 | "shasum": "" 138 | }, 139 | "require": { 140 | "php": ">=5.4.0", 141 | "psr/http-message": "~1.0" 142 | }, 143 | "provide": { 144 | "psr/http-message-implementation": "1.0" 145 | }, 146 | "require-dev": { 147 | "phpunit/phpunit": "~4.0" 148 | }, 149 | "type": "library", 150 | "extra": { 151 | "branch-alias": { 152 | "dev-master": "1.4-dev" 153 | } 154 | }, 155 | "autoload": { 156 | "psr-4": { 157 | "GuzzleHttp\\Psr7\\": "src/" 158 | }, 159 | "files": [ 160 | "src/functions_include.php" 161 | ] 162 | }, 163 | "notification-url": "https://packagist.org/downloads/", 164 | "license": [ 165 | "MIT" 166 | ], 167 | "authors": [ 168 | { 169 | "name": "Michael Dowling", 170 | "email": "mtdowling@gmail.com", 171 | "homepage": "https://github.com/mtdowling" 172 | }, 173 | { 174 | "name": "Tobias Schultze", 175 | "homepage": "https://github.com/Tobion" 176 | } 177 | ], 178 | "description": "PSR-7 message implementation that also provides common utility methods", 179 | "keywords": [ 180 | "http", 181 | "message", 182 | "request", 183 | "response", 184 | "stream", 185 | "uri", 186 | "url" 187 | ], 188 | "time": "2017-03-20T17:10:46+00:00" 189 | }, 190 | { 191 | "name": "psr/http-message", 192 | "version": "1.0.1", 193 | "source": { 194 | "type": "git", 195 | "url": "https://github.com/php-fig/http-message.git", 196 | "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" 197 | }, 198 | "dist": { 199 | "type": "zip", 200 | "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", 201 | "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", 202 | "shasum": "" 203 | }, 204 | "require": { 205 | "php": ">=5.3.0" 206 | }, 207 | "type": "library", 208 | "extra": { 209 | "branch-alias": { 210 | "dev-master": "1.0.x-dev" 211 | } 212 | }, 213 | "autoload": { 214 | "psr-4": { 215 | "Psr\\Http\\Message\\": "src/" 216 | } 217 | }, 218 | "notification-url": "https://packagist.org/downloads/", 219 | "license": [ 220 | "MIT" 221 | ], 222 | "authors": [ 223 | { 224 | "name": "PHP-FIG", 225 | "homepage": "http://www.php-fig.org/" 226 | } 227 | ], 228 | "description": "Common interface for HTTP messages", 229 | "homepage": "https://github.com/php-fig/http-message", 230 | "keywords": [ 231 | "http", 232 | "http-message", 233 | "psr", 234 | "psr-7", 235 | "request", 236 | "response" 237 | ], 238 | "time": "2016-08-06T14:39:51+00:00" 239 | } 240 | ], 241 | "packages-dev": [], 242 | "aliases": [], 243 | "minimum-stability": "stable", 244 | "stability-flags": [], 245 | "prefer-stable": true, 246 | "prefer-lowest": false, 247 | "platform": [], 248 | "platform-dev": [] 249 | } 250 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | ./tests/ 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/Contract/PardotApi.php: -------------------------------------------------------------------------------- 1 | /version/3/do/// 9 | * message body: api_key=&user_key=& 10 | */ 11 | interface PardotApi 12 | { 13 | /** 14 | * Returns the API version 15 | * 16 | * @return integer 17 | */ 18 | public function getVersion(): int; 19 | 20 | /** 21 | * Sets the API authenticator isntance 22 | * 23 | * @param PardotAuthenticator $authenticator 24 | * @return PardotApi 25 | */ 26 | public function setAuthenticator(PardotAuthenticator $authenticator): PardotApi; 27 | 28 | /** 29 | * Returns the API authenticator instance 30 | * 31 | * @return PardotAuthenticator 32 | */ 33 | public function getAuthenticator(): PardotAuthenticator; 34 | 35 | /** 36 | * Sets debugging on or off 37 | * 38 | * @param boolean $debug 39 | * @return PardotApi 40 | */ 41 | public function setDebug(bool $debug): PardotApi; 42 | 43 | /** 44 | * Returns whether debugging has been enabled 45 | * 46 | * @return boolean 47 | */ 48 | public function getDebug(): bool; 49 | 50 | /** 51 | * Sets the output format 52 | * 53 | * @param string $format 54 | * @return PardotApi 55 | */ 56 | public function setFormat(string $format): PardotApi; 57 | 58 | /** 59 | * Returns the output format 60 | * 61 | * @return string 62 | */ 63 | public function getFormat(): string; 64 | 65 | /** 66 | * Sets the output type 67 | * 68 | * @param string $output 69 | * @return PardotApi 70 | */ 71 | public function setOuput(string $output): PardotApi; 72 | 73 | /** 74 | * Returns the output type 75 | * 76 | * @return string 77 | */ 78 | public function getOutput(): string; 79 | 80 | /** 81 | * Returns the formatter class namespace 82 | * 83 | * @return string 84 | */ 85 | public function getFormatter(): string; 86 | 87 | /** 88 | * Performs a query request against any API endpoint 89 | * 90 | * @param string $object 91 | * @param string $operator 92 | * @param array $data 93 | * @return mixed 94 | */ 95 | public function request(string $object, string $operator, array $data = []); 96 | } -------------------------------------------------------------------------------- /src/Contract/PardotAuthenticator.php: -------------------------------------------------------------------------------- 1 | 16 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 17 | * @license https://github.com/cyber-duck/pardot-api/license 18 | * @version 1.0.0 19 | * @link https://github.com/cyber-duck/pardot-api 20 | * @since 1.0.0 21 | */ 22 | interface PardotAuthenticator 23 | { 24 | 25 | /** 26 | * Returns the Business Unit ID for use in query requests 27 | * 28 | * @return string 29 | */ 30 | public function getBusinessUnitID(): string; 31 | 32 | /** 33 | * Performs the login authentication request to return and set the API key 34 | * 35 | * @return void 36 | */ 37 | public function doAuthentication(); 38 | 39 | /** 40 | * Returns the Response object or null on failure 41 | * 42 | * @return Response|null 43 | */ 44 | public function getResponse(): ?Response; 45 | 46 | /** 47 | * Returns whether the login authentication request has been attempted 48 | * 49 | * @return boolean 50 | */ 51 | public function isAuthenticated(): bool; 52 | 53 | /** 54 | * Returns whether the login authentication request has been successful 55 | * 56 | * @return boolean 57 | */ 58 | public function isAuthenticatedSuccessfully(): bool; 59 | 60 | /** 61 | * Returns the Access Token returned from the login request for use in query requests 62 | * 63 | * @return string|null 64 | */ 65 | public function getAccessToken(): ?string; 66 | } 67 | -------------------------------------------------------------------------------- /src/Contract/QueryObject.php: -------------------------------------------------------------------------------- 1 | 14 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 15 | * @license https://github.com/cyber-duck/pardot-api/license 16 | * @version 1.0.0 17 | * @link https://github.com/cyber-duck/pardot-api 18 | * @since 1.0.0 19 | */ 20 | class JsonFormatter 21 | { 22 | /** 23 | * Input data 24 | * 25 | * @var string 26 | */ 27 | private $data; 28 | 29 | /** 30 | * Required property name 31 | * 32 | * @var string 33 | */ 34 | private $property; 35 | 36 | /** 37 | * Sets the required properties 38 | * 39 | * @param string $data 40 | * @param string $property 41 | */ 42 | public function __construct(string $data, string $property) 43 | { 44 | $this->data = $data; 45 | $this->property = $property; 46 | } 47 | 48 | /** 49 | * Returns the formatted output data 50 | * 51 | * @return stdClass 52 | */ 53 | public function getData(): stdClass 54 | { 55 | $data = json_decode($this->data); 56 | 57 | if(!is_object($data)) { 58 | throw new Exception('Pardot API error: invalid response'); 59 | } 60 | if(property_exists($data, 'err')) { 61 | throw new Exception(sprintf('Pardot API error: %s', $data->err)); 62 | } 63 | if(!property_exists($data, $this->property)) { 64 | throw new Exception(sprintf('Pardot API error: cannot find property %s in response', $this->property)); 65 | } 66 | return $data; 67 | } 68 | } -------------------------------------------------------------------------------- /src/PardotApi.php: -------------------------------------------------------------------------------- 1 | 45 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 46 | * @license https://github.com/cyber-duck/pardot-api/license 47 | * @version 1.0.0 48 | * @link https://github.com/cyber-duck/pardot-api 49 | * @since 1.0.0 50 | */ 51 | class PardotApi implements PardotApiInterface 52 | { 53 | /** 54 | * Pardot API version, currently 4 55 | * This package maintains a high level of compatibility with version 3 56 | * 57 | * @var int 58 | */ 59 | protected $version = 4; 60 | 61 | /** 62 | * API authenticator instance 63 | * 64 | * @var PardotAuthenticator 65 | */ 66 | protected $authenticator; 67 | 68 | /** 69 | * Whether debugging is enabled 70 | * 71 | * @var boolean 72 | */ 73 | protected $debug = false; 74 | 75 | /** 76 | * Response output format 77 | * 78 | * @var string 79 | */ 80 | protected $format = 'json'; 81 | 82 | /** 83 | * Allowed response output formats 84 | * 85 | * @var array 86 | */ 87 | protected $formats = [ 88 | 'json' => JsonFormatter::class 89 | ]; 90 | 91 | /** 92 | * Response output type 93 | * 94 | * @var string 95 | */ 96 | protected $output = 'full'; 97 | 98 | /** 99 | * Allowed response output types 100 | * 101 | * @var array 102 | */ 103 | protected $outputs = [ 104 | 'full', 105 | 'simple', 106 | 'mobile', 107 | 'bulk' 108 | ]; 109 | 110 | /** 111 | * Array of query object signatures available via a function call 112 | * Object is returned via __call() 113 | * 114 | * @var array 115 | */ 116 | protected $signatures = [ 117 | 'account' => AccountsQuery::class, 118 | 'campaign' => CampaignsQuery::class, 119 | 'customField' => CustomFieldsQuery::class, 120 | 'customRedirect' => CustomRedirectsQuery::class, 121 | 'dynamicContent' => DynamicContentQuery::class, 122 | 'emailClick' => EmailClicksQuery::class, 123 | 'email' => EmailQuery::class, 124 | 'emailTemplate' => EmailTemplatesQuery::class, 125 | 'form' => FormsQuery::class, 126 | 'lifecycleHistory' => LifecycleHistoriesQuery::class, 127 | 'lifecycleStage' => LifecycleStagesQuery::class, 128 | 'listMembership' => ListMembershipsQuery::class, 129 | 'list' => ListsQuery::class, 130 | 'opportunity' => OpportunitiesQuery::class, 131 | 'prospectAccount' => ProspectAccountsQuery::class, 132 | 'prospect' => ProspectsQuery::class, 133 | 'tagObject' => TagObjectsQuery::class, 134 | 'tag' => TagsQuery::class, 135 | 'user' => UsersQuery::class, 136 | 'visitorActivity' => VisitorActivitiesQuery::class, 137 | 'visitor' => VisitorsQuery::class, 138 | 'visit' => VisitsQuery::class, 139 | ]; 140 | 141 | /** 142 | * Sets the PardotAuthenticator instance with the passed credentials and 143 | * sets the API version 144 | * 145 | * @param string $email 146 | * @param string $password 147 | * @param string $userKey 148 | * @param integer $version 149 | */ 150 | 151 | /** 152 | * PardotApi constructor. 153 | * @param string $email 154 | * @param string $password 155 | * @param string $clientID 156 | * @param string $clientSecret 157 | * @param string $businessUnitID 158 | * @param int|int $version 159 | */ 160 | public function __construct(string $email, string $password, string $clientID, string $clientSecret, string $businessUnitID, int $version = 4) 161 | { 162 | $this->authenticator = new PardotAuthenticator( 163 | $this, $email, $password, $clientID, $clientSecret, $businessUnitID 164 | ); 165 | $this->version = $version; 166 | } 167 | 168 | /** 169 | * Returns the API version 170 | * 171 | * @return integer 172 | */ 173 | public function getVersion(): int 174 | { 175 | return $this->version; 176 | } 177 | 178 | /** 179 | * Sets the API authenticator isntance 180 | * 181 | * @param PardotAuthenticatorInterface $authenticator 182 | * @return PardotApiInterface 183 | */ 184 | public function setAuthenticator(PardotAuthenticatorInterface $authenticator): PardotApiInterface 185 | { 186 | $this->authenticator = $authenticator; 187 | return $this; 188 | } 189 | 190 | /** 191 | * Returns the API authenticator instance 192 | * 193 | * @return PardotAuthenticatorInterface 194 | */ 195 | public function getAuthenticator(): PardotAuthenticatorInterface 196 | { 197 | return $this->authenticator; 198 | } 199 | 200 | /** 201 | * Sets debugging on or off 202 | * 203 | * @param boolean $debug 204 | * @return PardotApiInterface 205 | */ 206 | public function setDebug(bool $debug): PardotApiInterface 207 | { 208 | $this->debug = $debug; 209 | return $this; 210 | } 211 | 212 | /** 213 | * Returns whether debugging has been enabled 214 | * 215 | * @return boolean 216 | */ 217 | public function getDebug(): bool 218 | { 219 | return $this->debug; 220 | } 221 | 222 | /** 223 | * Sets the output format 224 | * 225 | * @param string $format 226 | * @return PardotApiInterface 227 | */ 228 | public function setFormat(string $format): PardotApiInterface 229 | { 230 | if(!array_key_exists($format, $this->formats)) { 231 | throw new Exception(sprintf('%s is not an acceptable format', $format)); 232 | } 233 | $this->format = $format; 234 | return $this; 235 | } 236 | 237 | /** 238 | * Returns the output format 239 | * 240 | * @return string 241 | */ 242 | public function getFormat(): string 243 | { 244 | return $this->format; 245 | } 246 | 247 | /** 248 | * Sets the output type 249 | * 250 | * @param string $output 251 | * @return PardotApiInterface 252 | */ 253 | public function setOuput(string $output): PardotApiInterface 254 | { 255 | if(!in_array($output, $this->outputs)) { 256 | throw new Exception(sprintf('%s is not an acceptable output type', $output)); 257 | } 258 | $this->output = $output; 259 | return $this; 260 | } 261 | 262 | /** 263 | * Returns the output type 264 | * 265 | * @return string 266 | */ 267 | public function getOutput(): string 268 | { 269 | return $this->output; 270 | } 271 | 272 | /** 273 | * Returns the formatter class namespace 274 | * 275 | * @return string 276 | */ 277 | public function getFormatter(): string 278 | { 279 | return $this->formats[$this->format]; 280 | } 281 | 282 | /** 283 | * Magic method to return a query object form the signatures array 284 | * 285 | * @param string $name 286 | * @param mixed $arguments 287 | * @return void 288 | */ 289 | public function __call(string $name, $arguments) 290 | { 291 | if(array_key_exists($name, $this->signatures)) { 292 | return $this->signatures[$name]::obj($this); 293 | } 294 | } 295 | 296 | /** 297 | * Performs a query request against any API endpoint 298 | * 299 | * @param string $object 300 | * @param string $operator 301 | * @param array $data 302 | * @return mixed 303 | */ 304 | public function request(string $object, string $operator, array $data = []) 305 | { 306 | return Query::obj($this) 307 | ->setObject($object) 308 | ->setOperator($operator) 309 | ->setData($data) 310 | ->request($object); 311 | } 312 | } 313 | -------------------------------------------------------------------------------- /src/PardotAuthenticator.php: -------------------------------------------------------------------------------- 1 | 22 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 23 | * @license https://github.com/cyber-duck/pardot-api/license 24 | * @version 1.0.0 25 | * @link https://github.com/cyber-duck/pardot-api 26 | * @since 1.0.0 27 | */ 28 | class PardotAuthenticator implements PardotAuthenticatorInterface 29 | { 30 | /** 31 | * Main API class instance 32 | * 33 | * @var PardotApi 34 | */ 35 | protected $api; 36 | 37 | /** 38 | * Auth user email credential 39 | * 40 | * @var string 41 | */ 42 | protected $email; 43 | 44 | /** 45 | * Auth user password credential 46 | * 47 | * @var string 48 | */ 49 | protected $password; 50 | 51 | /** 52 | * Auth client id credential 53 | * 54 | * @var string 55 | */ 56 | protected $clientID; 57 | 58 | /** 59 | * Auth client secret credential 60 | * 61 | * @var string 62 | */ 63 | protected $clientSecret; 64 | 65 | /** 66 | * Auth business unit id credential 67 | * 68 | * @var string 69 | */ 70 | protected $businessUnitID; 71 | 72 | /** 73 | * Returned request access token 74 | * 75 | * @var string 76 | */ 77 | protected $accessToken; 78 | 79 | /** 80 | * Login endpoint 81 | * 82 | * @var string 83 | */ 84 | protected $endpoint = 'https://login.salesforce.com/services/oauth2/token'; 85 | 86 | /** 87 | * Returns response 88 | * 89 | * @var Response|null 90 | */ 91 | protected $response; 92 | 93 | /** 94 | * Flag to indicate the authentication request has been sent 95 | * 96 | * @var boolean 97 | */ 98 | protected $authenticated = false; 99 | 100 | /** 101 | * Flag to indicate the authentication request has been successful 102 | * 103 | * @var boolean 104 | */ 105 | protected $success = false; 106 | 107 | /** 108 | * Sets the required APi credentials and request client instance 109 | * 110 | * @param PardotApi $api 111 | * @param string $email 112 | * @param string $password 113 | * @param string $clientID 114 | * @param string $clientSecret 115 | */ 116 | public function __construct(PardotApi $api, string $email, string $password, string $clientID, string $clientSecret, string $businessUnitID) 117 | { 118 | $this->api = $api; 119 | $this->email = $email; 120 | $this->password = $password; 121 | $this->clientID = $clientID; 122 | $this->clientSecret = $clientSecret; 123 | $this->businessUnitID = $businessUnitID; 124 | 125 | $this->client = new Client(); 126 | } 127 | 128 | /** 129 | * Performs the login authentication request to return and set the Access Token 130 | * 131 | * @return static 132 | * @throws Exception 133 | */ 134 | public function doAuthentication() 135 | { 136 | try { 137 | $this->authenticated = true; 138 | 139 | $this->response = $this->client->request('POST', 140 | $this->getLoginRequestEndpoint(), 141 | $this->getLoginRequestOptions() 142 | ); 143 | 144 | if($this->response->getStatusCode() !== 200) { 145 | throw new Exception('Pardot API error: 200 response not returned'); 146 | } 147 | $namespace = $this->api->getFormatter(); 148 | $formatter = new $namespace((string) $this->response->getBody(), 'access_token'); 149 | 150 | $this->success = true; 151 | $this->accessToken = $formatter->getData()->access_token; 152 | } catch(Exception $e) { 153 | if($this->api->getDebug() === true) { 154 | echo $e->getMessage(); 155 | die; 156 | } 157 | } 158 | return $this; 159 | } 160 | 161 | /** 162 | * Returns the Response object or null on failure 163 | * 164 | * @return Response|null 165 | */ 166 | public function getResponse():? Response 167 | { 168 | return $this->response; 169 | } 170 | 171 | /** 172 | * Returns the Access Token returned from the login request for use in query requests 173 | * 174 | * @return string 175 | */ 176 | public function getAccessToken():string 177 | { 178 | return $this->accessToken; 179 | } 180 | 181 | /** 182 | * Returns the Business Unit ID for use in query requests 183 | * 184 | * @return string 185 | */ 186 | public function getBusinessUnitID(): string 187 | { 188 | return $this->businessUnitID; 189 | 190 | } 191 | 192 | /** 193 | * Returns whether the login authentication request has been attempted 194 | * 195 | * @return boolean 196 | */ 197 | public function isAuthenticated(): bool 198 | { 199 | return $this->authenticated; 200 | } 201 | 202 | /** 203 | * Returns whether the login authentication request has been successful 204 | * 205 | * @return boolean 206 | */ 207 | public function isAuthenticatedSuccessfully(): bool 208 | { 209 | return $this->success; 210 | } 211 | 212 | /** 213 | * Returns the login request endpoint URL 214 | * 215 | * @return string 216 | */ 217 | private function getLoginRequestEndpoint(): string 218 | { 219 | return sprintf( 220 | $this->endpoint, 221 | $this->api->getVersion() 222 | ); 223 | } 224 | 225 | /** 226 | * Returns the login request additional options 227 | * 228 | * @return array 229 | */ 230 | private function getLoginRequestOptions(): array 231 | { 232 | return [ 233 | 'form_params' => [ 234 | 'grant_type' => 'password', 235 | 'username' => $this->email, 236 | 'password' => $this->password, 237 | 'client_id' => $this->clientID, 238 | 'client_secret' => $this->clientSecret, 239 | 'format' => $this->api->getFormat(), 240 | 'output' => $this->api->getOutput() 241 | ] 242 | ]; 243 | } 244 | } 245 | -------------------------------------------------------------------------------- /src/Query/AccountsQuery.php: -------------------------------------------------------------------------------- 1 | 13 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 14 | * @license https://github.com/cyber-duck/pardot-api/license 15 | * @version 1.0.0 16 | * @link https://github.com/cyber-duck/pardot-api 17 | * @since 1.0.0 18 | */ 19 | class AccountsQuery extends Query 20 | { 21 | /** 22 | * Object name 23 | * 24 | * @var string 25 | */ 26 | protected $object = 'account'; 27 | 28 | /** 29 | * Returns the data for the account of the currently logged in user. 30 | * 31 | * /api/account/version/{version}/do/read 32 | * 33 | * required: user_key, api_key 34 | */ 35 | public function read():? stdClass 36 | { 37 | return $this->setOperator('read')->request($this->object); 38 | } 39 | } -------------------------------------------------------------------------------- /src/Query/CampaignsQuery.php: -------------------------------------------------------------------------------- 1 | 22 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 23 | * @license https://github.com/cyber-duck/pardot-api/license 24 | * @version 1.0.0 25 | * @link https://github.com/cyber-duck/pardot-api 26 | * @since 1.0.0 27 | */ 28 | class CampaignsQuery extends Query implements QueryObject 29 | { 30 | use CanQuery, CanCreate, CanRead, CanUpdate; 31 | 32 | /** 33 | * Object name 34 | * 35 | * @var string 36 | */ 37 | protected $object = 'campaign'; 38 | 39 | /** 40 | * Returns an array of allowed query criteria and validators for the values 41 | * 42 | * @return array 43 | */ 44 | public function getQueryCriteria(): array 45 | { 46 | return [ 47 | 'name' => new StringValidator, 48 | 'created_after' => new DateValidator, 49 | 'created_before' => new DateValidator, 50 | 'id_greater_than' => new PositiveIntValidator, 51 | 'id_less_than' => new PositiveIntValidator, 52 | 'updated_before' => new DateValidator, 53 | 'updated_after' => new DateValidator 54 | ]; 55 | } 56 | 57 | /** 58 | * Returns an array of allowed query navigation params and validators for the values 59 | * 60 | * @return array 61 | */ 62 | public function getQueryNavigation(): array 63 | { 64 | return [ 65 | 'limit' => new PositiveIntValidator, 66 | 'offset' => new PositiveIntValidator, 67 | 'sort_by' => new FixedValuesValidator('created_at', 'id', 'name', 'updated_at', 'cost'), 68 | 'sort_order' => new SortOrderValidator 69 | ]; 70 | } 71 | } -------------------------------------------------------------------------------- /src/Query/CustomFieldsQuery.php: -------------------------------------------------------------------------------- 1 | 21 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 22 | * @license https://github.com/cyber-duck/pardot-api/license 23 | * @version 1.0.0 24 | * @link https://github.com/cyber-duck/pardot-api 25 | * @since 1.0.0 26 | */ 27 | class CustomFieldsQuery extends Query implements QueryObject 28 | { 29 | use CanQuery, CanRead, CanUpdate, CanCreate, CanDelete; 30 | 31 | /** 32 | * Object name 33 | * 34 | * @var string 35 | */ 36 | protected $object = 'customField'; 37 | 38 | /** 39 | * Returns an array of allowed query criteria and validators for the values 40 | * 41 | * @return array 42 | */ 43 | public function getQueryCriteria(): array 44 | { 45 | return [ 46 | 'created_after' => new DateValidator, 47 | 'created_before' => new DateValidator, 48 | 'id_greater_than' => new PositiveIntValidator, 49 | 'id_less_than' => new PositiveIntValidator 50 | ]; 51 | } 52 | 53 | /** 54 | * Returns an array of allowed query navigation params and validators for the values 55 | * 56 | * @return array 57 | */ 58 | public function getQueryNavigation(): array 59 | { 60 | return [ 61 | 'limit' => new PositiveIntValidator, 62 | 'offset' => new PositiveIntValidator, 63 | 'sort_by' => new FixedValuesValidator('created_at', 'id', 'name'), 64 | 'sort_order' => new SortOrderValidator 65 | ]; 66 | } 67 | } -------------------------------------------------------------------------------- /src/Query/CustomRedirectsQuery.php: -------------------------------------------------------------------------------- 1 | 20 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 21 | * @license https://github.com/cyber-duck/pardot-api/license 22 | * @version 1.0.0 23 | * @link https://github.com/cyber-duck/pardot-api 24 | * @since 1.0.0 25 | */ 26 | class CustomRedirectsQuery extends Query implements QueryObject 27 | { 28 | use CanQuery, CanRead; 29 | 30 | /** 31 | * Object name 32 | * 33 | * @var string 34 | */ 35 | protected $object = 'customRedirect'; 36 | 37 | /** 38 | * Returns an array of allowed query criteria and validators for the values 39 | * 40 | * @return array 41 | */ 42 | public function getQueryCriteria(): array 43 | { 44 | return [ 45 | 'created_after' => new DateValidator, 46 | 'created_before' => new DateValidator, 47 | 'id_greater_than' => new PositiveIntValidator, 48 | 'id_less_than' => new PositiveIntValidator, 49 | 'updated_before' => new DateValidator, 50 | 'updated_after' => new DateValidator 51 | ]; 52 | } 53 | 54 | /** 55 | * Returns an array of allowed query navigation params and validators for the values 56 | * 57 | * @return array 58 | */ 59 | public function getQueryNavigation(): array 60 | { 61 | return [ 62 | 'limit' => new PositiveIntValidator, 63 | 'offset' => new PositiveIntValidator, 64 | 'sort_by' => new FixedValuesValidator('created_at', 'id', 'updated_at'), 65 | 'sort_order' => new SortOrderValidator 66 | ]; 67 | } 68 | } -------------------------------------------------------------------------------- /src/Query/DynamicContentQuery.php: -------------------------------------------------------------------------------- 1 | 20 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 21 | * @license https://github.com/cyber-duck/pardot-api/license 22 | * @version 1.0.0 23 | * @link https://github.com/cyber-duck/pardot-api 24 | * @since 1.0.0 25 | */ 26 | class DynamicContentQuery extends Query implements QueryObject 27 | { 28 | use CanQuery, CanRead; 29 | 30 | /** 31 | * Object name 32 | * 33 | * @var string 34 | */ 35 | protected $object = 'dynamicContent'; 36 | 37 | /** 38 | * Returns an array of allowed query criteria and validators for the values 39 | * 40 | * @return array 41 | */ 42 | public function getQueryCriteria(): array 43 | { 44 | return [ 45 | 'created_after' => new DateValidator, 46 | 'created_before' => new DateValidator, 47 | 'id_greater_than' => new PositiveIntValidator, 48 | 'id_less_than' => new PositiveIntValidator, 49 | 'updated_before' => new DateValidator, 50 | 'updated_after' => new DateValidator 51 | ]; 52 | } 53 | 54 | /** 55 | * Returns an array of allowed query navigation params and validators for the values 56 | * 57 | * @return array 58 | */ 59 | public function getQueryNavigation(): array 60 | { 61 | return [ 62 | 'limit' => new PositiveIntValidator, 63 | 'offset' => new PositiveIntValidator, 64 | 'sort_by' => new FixedValuesValidator('created_at', 'id', 'updated_at'), 65 | 'sort_order' => new SortOrderValidator 66 | ]; 67 | } 68 | } -------------------------------------------------------------------------------- /src/Query/EmailClicksQuery.php: -------------------------------------------------------------------------------- 1 | 16 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 17 | * @license https://github.com/cyber-duck/pardot-api/license 18 | * @version 1.0.0 19 | * @link https://github.com/cyber-duck/pardot-api 20 | * @since 1.0.0 21 | */ 22 | class EmailClicksQuery extends Query implements QueryObject 23 | { 24 | use CanQuery; 25 | 26 | /** 27 | * Object name 28 | * 29 | * @var string 30 | */ 31 | protected $object = 'emailClick'; 32 | 33 | /** 34 | * Returns an array of allowed query criteria and validators for the values 35 | * 36 | * @return array 37 | */ 38 | public function getQueryCriteria(): array 39 | { 40 | return [ 41 | 'created_after' => new DateValidator, 42 | 'created_before' => new DateValidator, 43 | 'id_greater_than' => new PositiveIntValidator, 44 | 'list_email_id' => new PositiveIntValidator, 45 | 'drip_program_action_id' => new PositiveIntValidator, 46 | 'email_template_id' => new PositiveIntValidator, 47 | 'tracker_redirect_id' => new PositiveIntValidator 48 | ]; 49 | } 50 | 51 | /** 52 | * Returns an array of allowed query navigation params and validators for the values 53 | * 54 | * @return array 55 | */ 56 | public function getQueryNavigation(): array 57 | { 58 | return [ 59 | 'limit' => new PositiveIntValidator, 60 | 'id_greater_than' => new PositiveIntValidator 61 | ]; 62 | } 63 | } -------------------------------------------------------------------------------- /src/Query/EmailQuery.php: -------------------------------------------------------------------------------- 1 | 13 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 14 | * @license https://github.com/cyber-duck/pardot-api/license 15 | * @version 1.0.0 16 | * @link https://github.com/cyber-duck/pardot-api 17 | * @since 1.0.0 18 | */ 19 | class EmailQuery extends Query 20 | { 21 | use CanRead; 22 | 23 | /** 24 | * Object name 25 | * 26 | * @var string 27 | */ 28 | protected $object = 'email'; 29 | 30 | /** 31 | * Returns the statistical data for the list email specified by . 32 | * is the Pardot ID of the target email. 33 | * 34 | * /api/email/version/{version}/do/stats/id/?... 35 | * 36 | * required: user_key, api_key, list_email_id 37 | * 38 | * @return stClass|null 39 | */ 40 | public function stats(int $id):? stClass 41 | { 42 | return $this->setOperator(sprintf('stats/id/%s', $id))->request('stats'); 43 | } 44 | 45 | /** 46 | * Sends a one-to-one email to the prospect identified by 47 | * 48 | * /api/email/version/3/do/send/prospect_id/?... 49 | * 50 | * required: user_key, api_key, campaign_id, (email_template_id OR (text_content, name, subject, & ((from_email & from_name) OR from_user_id))) 51 | * 52 | * @param integer $id 53 | * @param array $params 54 | * @return stClass|null 55 | * @todo validate passed params 56 | */ 57 | public function sendToID(int $id, array $params):? stClass 58 | { 59 | return $this->setOperator(sprintf('send/prospect_id/%s', $id))->request('email'); 60 | } 61 | 62 | /** 63 | * Sends a one-to-one email to the prospect identified by 64 | * 65 | * /api/email/version/3/do/send/prospect_email/?... 66 | * 67 | * required: user_key, api_key, campaign_id, (email_template_id OR (text_content, name, subject, & ((from_email & from_name) OR from_user_id))) 68 | * 69 | * @param string $email 70 | * @param array $params 71 | * @return stClass|null 72 | * @todo validate passed params 73 | */ 74 | public function sendToEmail(string $email, array $params):? stClass 75 | { 76 | return $this->setOperator(sprintf('send/prospect_email/%s', $id))->request('email'); 77 | } 78 | 79 | /** 80 | * Sends an email to all the prospects in a list identified by list_ids[] 81 | * 82 | * /api/email/version/4/do/send 83 | * 84 | * required: user_key, api_key, list_ids[], campaign_id, (email_template_id OR (text_content, name, subject, & ((from_email & from_name) OR from_user_id))) 85 | * 86 | * @param string $email 87 | * @param array $params 88 | * @return stClass|null 89 | * @todo validate passed params 90 | */ 91 | public function send(array $params):? stClass 92 | { 93 | return $this->setOperator('send')->request('email'); 94 | } 95 | } -------------------------------------------------------------------------------- /src/Query/EmailTemplatesQuery.php: -------------------------------------------------------------------------------- 1 | 13 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 14 | * @license https://github.com/cyber-duck/pardot-api/license 15 | * @version 1.0.0 16 | * @link https://github.com/cyber-duck/pardot-api 17 | * @since 1.0.0 18 | */ 19 | class EmailTemplatesQuery extends Query 20 | { 21 | use CanRead; 22 | 23 | /** 24 | * Object name 25 | * 26 | * @var string 27 | */ 28 | protected $object = 'emailTemplate'; 29 | 30 | /** 31 | * Returns a list of email templates which are enabled for use in one to one emails. 32 | * 33 | * /api/emailTemplate/version/{version}/do/listOneToOne 34 | * 35 | * required: user_key, api_key 36 | * 37 | * @return array|null 38 | */ 39 | public function listOneToOne():? array 40 | { 41 | return $this->setOperator('listOneToOne')->request($this->object); 42 | } 43 | } -------------------------------------------------------------------------------- /src/Query/FormsQuery.php: -------------------------------------------------------------------------------- 1 | 20 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 21 | * @license https://github.com/cyber-duck/pardot-api/license 22 | * @version 1.0.0 23 | * @link https://github.com/cyber-duck/pardot-api 24 | * @since 1.0.0 25 | */ 26 | class FormsQuery extends Query implements QueryObject 27 | { 28 | use CanQuery, CanRead; 29 | 30 | /** 31 | * Object name 32 | * 33 | * @var string 34 | */ 35 | protected $object = 'form'; 36 | 37 | /** 38 | * Returns an array of allowed query criteria and validators for the values 39 | * 40 | * @return array 41 | */ 42 | public function getQueryCriteria(): array 43 | { 44 | return [ 45 | 'created_after' => new DateValidator, 46 | 'created_before' => new DateValidator, 47 | 'id_greater_than' => new PositiveIntValidator, 48 | 'id_less_than' => new PositiveIntValidator, 49 | 'updated_before' => new DateValidator, 50 | 'updated_after' => new DateValidator 51 | ]; 52 | } 53 | 54 | /** 55 | * Returns an array of allowed query navigation params and validators for the values 56 | * 57 | * @return array 58 | */ 59 | public function getQueryNavigation(): array 60 | { 61 | return [ 62 | 'limit' => new PositiveIntValidator, 63 | 'offset' => new PositiveIntValidator, 64 | 'sort_by' => new FixedValuesValidator('created_at', 'id', 'updated_at'), 65 | 'sort_order' => new SortOrderValidator 66 | ]; 67 | } 68 | } -------------------------------------------------------------------------------- /src/Query/LifecycleHistoriesQuery.php: -------------------------------------------------------------------------------- 1 | 19 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 20 | * @license https://github.com/cyber-duck/pardot-api/license 21 | * @version 1.0.0 22 | * @link https://github.com/cyber-duck/pardot-api 23 | * @since 1.0.0 24 | */ 25 | class LifecycleHistoriesQuery extends Query implements QueryObject 26 | { 27 | use CanQuery, CanRead; 28 | 29 | /** 30 | * Object name 31 | * 32 | * @var string 33 | */ 34 | protected $object = 'lifecycleHistory'; 35 | 36 | /** 37 | * Returns an array of allowed query criteria and validators for the values 38 | * 39 | * @return array 40 | */ 41 | public function getQueryCriteria(): array 42 | { 43 | return [ 44 | 'created_after' => new DateValidator, 45 | 'created_before' => new DateValidator, 46 | 'id_greater_than' => new PositiveIntValidator, 47 | 'id_less_than' => new PositiveIntValidator 48 | ]; 49 | } 50 | 51 | /** 52 | * Returns an array of allowed query navigation params and validators for the values 53 | * 54 | * @return array 55 | */ 56 | public function getQueryNavigation(): array 57 | { 58 | return [ 59 | 'limit' => new PositiveIntValidator, 60 | 'offset' => new PositiveIntValidator, 61 | 'sort_by' => new FixedValuesValidator('created_at', 'id'), 62 | 'sort_order' => new SortOrderValidator 63 | ]; 64 | } 65 | } -------------------------------------------------------------------------------- /src/Query/LifecycleStagesQuery.php: -------------------------------------------------------------------------------- 1 | 17 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 18 | * @license https://github.com/cyber-duck/pardot-api/license 19 | * @version 1.0.0 20 | * @link https://github.com/cyber-duck/pardot-api 21 | * @since 1.0.0 22 | */ 23 | class LifecycleStagesQuery extends Query implements QueryObject 24 | { 25 | use CanQuery; 26 | 27 | /** 28 | * Object name 29 | * 30 | * @var string 31 | */ 32 | protected $object = 'lifecycleStage'; 33 | 34 | /** 35 | * Returns an array of allowed query criteria and validators for the values 36 | * 37 | * @return array 38 | */ 39 | public function getQueryCriteria(): array 40 | { 41 | return [ 42 | 'id_greater_than' => new PositiveIntValidator, 43 | 'id_less_than' => new PositiveIntValidator 44 | ]; 45 | } 46 | 47 | /** 48 | * Returns an array of allowed query navigation params and validators for the values 49 | * 50 | * @return array 51 | */ 52 | public function getQueryNavigation(): array 53 | { 54 | return [ 55 | 'limit' => new PositiveIntValidator, 56 | 'offset' => new PositiveIntValidator, 57 | 'sort_by' => new FixedValuesValidator('position', 'id'), 58 | 'sort_order' => new SortOrderValidator 59 | ]; 60 | } 61 | 62 | } -------------------------------------------------------------------------------- /src/Query/ListMembershipsQuery.php: -------------------------------------------------------------------------------- 1 | 11 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 12 | * @license https://github.com/cyber-duck/pardot-api/license 13 | * @version 1.0.0 14 | * @link https://github.com/cyber-duck/pardot-api 15 | * @since 1.0.0 16 | */ 17 | class ListMembershipsQuery extends Query 18 | { 19 | 20 | } -------------------------------------------------------------------------------- /src/Query/ListsQuery.php: -------------------------------------------------------------------------------- 1 | 11 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 12 | * @license https://github.com/cyber-duck/pardot-api/license 13 | * @version 1.0.0 14 | * @link https://github.com/cyber-duck/pardot-api 15 | * @since 1.0.0 16 | */ 17 | class ListsQuery extends Query 18 | { 19 | 20 | } -------------------------------------------------------------------------------- /src/Query/OpportunitiesQuery.php: -------------------------------------------------------------------------------- 1 | 11 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 12 | * @license https://github.com/cyber-duck/pardot-api/license 13 | * @version 1.0.0 14 | * @link https://github.com/cyber-duck/pardot-api 15 | * @since 1.0.0 16 | */ 17 | class OpportunitiesQuery extends Query 18 | { 19 | 20 | } -------------------------------------------------------------------------------- /src/Query/ProspectAccountsQuery.php: -------------------------------------------------------------------------------- 1 | 11 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 12 | * @license https://github.com/cyber-duck/pardot-api/license 13 | * @version 1.0.0 14 | * @link https://github.com/cyber-duck/pardot-api 15 | * @since 1.0.0 16 | */ 17 | class ProspectAccountsQuery extends Query 18 | { 19 | 20 | } -------------------------------------------------------------------------------- /src/Query/ProspectsQuery.php: -------------------------------------------------------------------------------- 1 | 10 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 11 | * @license https://github.com/cyber-duck/pardot-api/license 12 | * @version 1.0.0 13 | * @link https://github.com/cyber-duck/pardot-api 14 | * @since 1.0.0 15 | */ 16 | class ProspectsQuery extends Query 17 | { 18 | 19 | } -------------------------------------------------------------------------------- /src/Query/Query.php: -------------------------------------------------------------------------------- 1 | 18 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 19 | * @license https://github.com/cyber-duck/pardot-api/license 20 | * @version 1.0.0 21 | * @link https://github.com/cyber-duck/pardot-api 22 | * @since 1.0.0 23 | */ 24 | class Query 25 | { 26 | /** 27 | * Pardot API andpoint 28 | * 29 | * @var string 30 | */ 31 | protected $endpoint = 'https://pi.pardot.com/api/%s/version/%s/do/%s'; 32 | 33 | /** 34 | * API instance 35 | * 36 | * @var PardotApi 37 | */ 38 | protected $api; 39 | 40 | /** 41 | * API identifier 42 | * /api//version/4/do/// 43 | * 44 | * @var string 45 | */ 46 | protected $object; 47 | 48 | /** 49 | * API identifier 50 | * /api//version/4/do/// 51 | * 52 | * @var string 53 | */ 54 | protected $operator; 55 | 56 | /** 57 | * Array of request data 58 | * 59 | * @var array 60 | */ 61 | protected $data = []; 62 | 63 | /** 64 | * Sets the API instance 65 | * 66 | * @param PardotApi $api 67 | */ 68 | public function __construct(PardotApi $api) 69 | { 70 | $this->api = $api; 71 | } 72 | 73 | /** 74 | * Static binding call to initiate method chaining 75 | * 76 | * @param PardotApi $api 77 | * @return void 78 | */ 79 | public static function obj(PardotApi $api) 80 | { 81 | return new static($api); 82 | } 83 | 84 | /** 85 | * Sets the API object identifier 86 | * 87 | * @param string $object 88 | * @return Query 89 | */ 90 | protected function setObject(string $object): Query 91 | { 92 | $this->object = $object; 93 | return $this; 94 | } 95 | 96 | /** 97 | * Sets the API operator identifier 98 | * 99 | * @param string $operator 100 | * @return Query 101 | */ 102 | protected function setOperator(string $operator): Query 103 | { 104 | $this->operator = $operator; 105 | return $this; 106 | } 107 | 108 | /** 109 | * Sets the request data - can used in things like insert and update actions 110 | * 111 | * @param array $data 112 | * @return Query 113 | */ 114 | protected function setData(array $data): Query 115 | { 116 | $this->data = $data; 117 | return $this; 118 | } 119 | 120 | /** 121 | * Performs the API query 122 | * 123 | * The passed property value is the property on the response object to return 124 | * and is dependent on the type of data being returned 125 | * 126 | * Reading an individual account may require reading the property 127 | * while reading a results list may require reading property 128 | * 129 | * @param string $property 130 | * @return mixed 131 | * @throws Exception 132 | */ 133 | protected function request(string $property) 134 | { 135 | if(!$this->api->getAuthenticator()->isAuthenticated()) { 136 | $this->api->getAuthenticator()->doAuthentication(); 137 | } 138 | 139 | if($this->api->getAuthenticator()->isAuthenticatedSuccessfully()) { 140 | try { 141 | $client = new Client(); 142 | $response = $client->request('POST', 143 | $this->getQueryEndpoint(), 144 | $this->getQueryRequestOptions() 145 | ); 146 | if($response->getStatusCode() !== 200) { 147 | throw new Exception('Pardot query error: 200 response not returned'); 148 | } 149 | $namespace = $this->api->getFormatter(); 150 | $formatter = new $namespace((string) $response->getBody(), $property); 151 | 152 | return $formatter->getData()->{$property}; 153 | } catch(Exception $e) { 154 | if($this->api->getDebug() === true) { 155 | echo $e->getMessage(); 156 | die; 157 | } 158 | } 159 | } 160 | return null; 161 | } 162 | 163 | /** 164 | * Returns the query request endpoint URL 165 | * 166 | * @return string 167 | */ 168 | protected function getQueryEndpoint(): string 169 | { 170 | return sprintf( 171 | $this->endpoint, 172 | $this->object, 173 | $this->api->getVersion(), 174 | $this->operator 175 | ); 176 | } 177 | 178 | /** 179 | * Returns the query request additional options 180 | * 181 | * @return array 182 | */ 183 | protected function getQueryRequestOptions(): array 184 | { 185 | return [ 186 | 'headers' => [ 187 | 'Pardot-Business-Unit-Id' => $this->api->getAuthenticator()->getBusinessUnitID(), 188 | 'Authorization' => "Bearer {$this->api->getAuthenticator()->getAccessToken()}" 189 | ], 190 | 'form_params' => array_merge([ 191 | 'format' => $this->api->getFormat(), 192 | 'output' => $this->api->getOutput() 193 | ], $this->data) 194 | ]; 195 | } 196 | } 197 | -------------------------------------------------------------------------------- /src/Query/TagObjectsQuery.php: -------------------------------------------------------------------------------- 1 | 20 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 21 | * @license https://github.com/cyber-duck/pardot-api/license 22 | * @version 1.0.0 23 | * @link https://github.com/cyber-duck/pardot-api 24 | * @since 1.0.0 25 | */ 26 | class TagObjectsQuery extends Query implements QueryObject 27 | { 28 | use CanQuery, CanRead; 29 | 30 | /** 31 | * Object name 32 | * 33 | * @var string 34 | */ 35 | protected $object = 'tagObject'; 36 | 37 | /** 38 | * Returns an array of allowed query criteria and validators for the values 39 | * 40 | * @return array 41 | */ 42 | public function getQueryCriteria(): array 43 | { 44 | return [ 45 | 'created_after' => new DateValidator, 46 | 'created_before' => new DateValidator, 47 | 'id_greater_than' => new PositiveIntValidator, 48 | 'id_less_than' => new PositiveIntValidator, 49 | 'tag_id' => new PositiveIntValidator, 50 | 'object_id' => new PositiveIntValidator, 51 | 'type' => new FixedValuesValidator( 52 | 'Automation', 'Block', 'Campaign', 'Competitor', 53 | 'Prospect Custom Field', 'Custom URL', 'Drip Program', 54 | 'Email', 'Email Draft', 'Email Template', 'Email Template Draft', 55 | 'File', 'Form', 'Form Field', 'Form Handler', 'Group', 'Keyword', 56 | 'Landing Page', 'Layout Template', 'List', 'Opportunity', 57 | 'Paid Search Campaign', 'Personalization', 'Profile', 'Prospect', 58 | 'Prospect Default Field', 'Segmentation Rule', 'Site', 59 | 'Site Search', 'Social Message', 'User', 'Dynamic Content' 60 | ) 61 | ]; 62 | } 63 | 64 | /** 65 | * Returns an array of allowed query navigation params and validators for the values 66 | * 67 | * @return array 68 | */ 69 | public function getQueryNavigation(): array 70 | { 71 | return [ 72 | 'limit' => new PositiveIntValidator, 73 | 'offset' => new PositiveIntValidator, 74 | 'sort_by' => new FixedValuesValidator('created_at', 'id'), 75 | 'sort_order' => new SortOrderValidator 76 | ]; 77 | } 78 | } -------------------------------------------------------------------------------- /src/Query/TagsQuery.php: -------------------------------------------------------------------------------- 1 | 20 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 21 | * @license https://github.com/cyber-duck/pardot-api/license 22 | * @version 1.0.0 23 | * @link https://github.com/cyber-duck/pardot-api 24 | * @since 1.0.0 25 | */ 26 | class TagsQuery extends Query implements QueryObject 27 | { 28 | use CanQuery, CanRead; 29 | 30 | /** 31 | * Object name 32 | * 33 | * @var string 34 | */ 35 | protected $object = 'tag'; 36 | 37 | /** 38 | * Returns an array of allowed query criteria and validators for the values 39 | * 40 | * @return array 41 | */ 42 | public function getQueryCriteria(): array 43 | { 44 | return [ 45 | 'name' => new StringValidator, 46 | 'created_after' => new DateValidator, 47 | 'created_before' => new DateValidator, 48 | 'id_greater_than' => new PositiveIntValidator, 49 | 'id_less_than' => new PositiveIntValidator, 50 | 'updated_before' => new DateValidator, 51 | 'updated_after' => new DateValidator 52 | ]; 53 | } 54 | 55 | /** 56 | * Returns an array of allowed query navigation params and validators for the values 57 | * 58 | * @return array 59 | */ 60 | public function getQueryNavigation(): array 61 | { 62 | return [ 63 | 'limit' => new PositiveIntValidator, 64 | 'offset' => new PositiveIntValidator, 65 | 'sort_by' => new FixedValuesValidator('created_at', 'id', 'name', 'updated_at'), 66 | 'sort_order' => new SortOrderValidator 67 | ]; 68 | } 69 | } -------------------------------------------------------------------------------- /src/Query/UsersQuery.php: -------------------------------------------------------------------------------- 1 | 19 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 20 | * @license https://github.com/cyber-duck/pardot-api/license 21 | * @version 1.0.0 22 | * @link https://github.com/cyber-duck/pardot-api 23 | * @since 1.0.0 24 | */ 25 | class UsersQuery extends Query implements QueryObject 26 | { 27 | use CanQuery, CanRead; 28 | 29 | /** 30 | * Object name 31 | * 32 | * @var string 33 | */ 34 | protected $object = 'user'; 35 | 36 | /** 37 | * Returns an array of allowed query criteria and validators for the values 38 | * 39 | * @return array 40 | */ 41 | public function getQueryCriteria(): array 42 | { 43 | return [ 44 | 'created_after' => new DateValidator, 45 | 'created_before' => new DateValidator, 46 | 'id_greater_than' => new PositiveIntValidator, 47 | 'id_less_than' => new PositiveIntValidator 48 | ]; 49 | } 50 | 51 | /** 52 | * Returns an array of allowed query navigation params and validators for the values 53 | * 54 | * @return array 55 | */ 56 | public function getQueryNavigation(): array 57 | { 58 | return [ 59 | 'limit' => new PositiveIntValidator, 60 | 'offset' => new PositiveIntValidator, 61 | 'sort_by' => new FixedValuesValidator('created_at', 'id'), 62 | 'sort_order' => new SortOrderValidator 63 | ]; 64 | } 65 | 66 | /** 67 | * Sends the request to retrieve the user object by email and returns it from the API 68 | * 69 | * /api/user/version/{version}/do/read/email/?... 70 | * 71 | * required: user_key, api_key, email 72 | * 73 | * @param int $id 74 | * @return stdClass|null 75 | */ 76 | public function readByEmail(string $email):? stdClass 77 | { 78 | return $this->setOperator(sprintf('read/email/%s', $email))->request($this->object); 79 | } 80 | } -------------------------------------------------------------------------------- /src/Query/VisitorActivitiesQuery.php: -------------------------------------------------------------------------------- 1 | 11 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 12 | * @license https://github.com/cyber-duck/pardot-api/license 13 | * @version 1.0.0 14 | * @link https://github.com/cyber-duck/pardot-api 15 | * @since 1.0.0 16 | */ 17 | class VisitorActivitiesQuery extends Query 18 | { 19 | 20 | } -------------------------------------------------------------------------------- /src/Query/VisitorsQuery.php: -------------------------------------------------------------------------------- 1 | 22 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 23 | * @license https://github.com/cyber-duck/pardot-api/license 24 | * @version 1.0.0 25 | * @link https://github.com/cyber-duck/pardot-api 26 | * @since 1.0.0 27 | */ 28 | class VisitorsQuery extends Query implements QueryObject 29 | { 30 | use CanQuery, CanRead; 31 | 32 | /** 33 | * Object name 34 | * 35 | * @var string 36 | */ 37 | protected $object = 'visitor'; 38 | 39 | /** 40 | * Returns an array of allowed query criteria and validators for the values 41 | * 42 | * @return array 43 | */ 44 | public function getQueryCriteria(): array 45 | { 46 | return [ 47 | 'created_after' => new DateValidator, 48 | 'created_before' => new DateValidator, 49 | 'id_greater_than' => new PositiveIntValidator, 50 | 'id_less_than' => new PositiveIntValidator, 51 | 'updated_before' => new DateValidator, 52 | 'updated_after' => new DateValidator, 53 | 'only_identified' => new BooleanValidator, 54 | 'prospect_ids' => new PositiveIntListValidator 55 | ]; 56 | } 57 | 58 | /** 59 | * Returns an array of allowed query navigation params and validators for the values 60 | * 61 | * @return array 62 | */ 63 | public function getQueryNavigation(): array 64 | { 65 | return [ 66 | 'limit' => new PositiveIntValidator, 67 | 'offset' => new PositiveIntValidator, 68 | 'output' => new FixedValuesValidator('simple', 'mobile'), 69 | 'sort_by' => new FixedValuesValidator('created_at', 'id', 'updated_at'), 70 | 'sort_order' => new SortOrderValidator 71 | ]; 72 | } 73 | 74 | /** 75 | * Assigns or reassigns the visitor specified by to a specified prospect. 76 | * The parameters must be provided to identify the target prospect. 77 | * 78 | * /api/visitor/version/{visitor}/do/assign/id/?... 79 | * 80 | * required: user_key, api_key, id, prospect_id 81 | * 82 | * @param int $id 83 | * @param int $prospectId 84 | * @return stdClass|null 85 | */ 86 | public function assign(int $id, int $prospectId):? stdClass 87 | { 88 | return $this->setOperator(sprintf('assign/id/%s', $id))->setData(['prospect_id' => $prospectId])->request($this->object); 89 | } 90 | } -------------------------------------------------------------------------------- /src/Query/VisitsQuery.php: -------------------------------------------------------------------------------- 1 | 17 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 18 | * @license https://github.com/cyber-duck/pardot-api/license 19 | * @version 1.0.0 20 | * @link https://github.com/cyber-duck/pardot-api 21 | * @since 1.0.0 22 | */ 23 | class VisitsQuery extends Query implements QueryObject 24 | { 25 | use CanQuery, CanRead; 26 | 27 | /** 28 | * Object name 29 | * 30 | * @var string 31 | */ 32 | protected $object = 'visit'; 33 | 34 | /** 35 | * Returns an array of allowed query criteria and validators for the values 36 | * 37 | * One of the following parameters must be used when issuing a visit query 38 | * @todo make sure one of the below list keys is set 39 | * 40 | * @return array 41 | */ 42 | public function getQueryCriteria(): array 43 | { 44 | return [ 45 | 'ids' => new PositiveIntListValidator, 46 | 'visitor_ids' => new PositiveIntListValidator, 47 | 'prospect_ids' => new PositiveIntListValidator 48 | ]; 49 | } 50 | 51 | /** 52 | * Returns an array of allowed query navigation params and validators for the values 53 | * 54 | * @return array 55 | */ 56 | public function getQueryNavigation(): array 57 | { 58 | return [ 59 | 'limit' => new PositiveIntValidator, 60 | 'offset' => new PositiveIntValidator 61 | ]; 62 | } 63 | } -------------------------------------------------------------------------------- /src/Traits/CanCreate.php: -------------------------------------------------------------------------------- 1 | 16 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 17 | * @license https://github.com/cyber-duck/pardot-api/license 18 | * @version 1.0.0 19 | * @link https://github.com/cyber-duck/pardot-api 20 | * @since 1.0.0 21 | */ 22 | trait CanCreate 23 | { 24 | /** 25 | * Sends the request to create the new object and returns it from the API 26 | * 27 | * /api/{object}/version/{version}/do/create?... 28 | * 29 | * required: user_key, api_key, ...others depend on object type 30 | * 31 | * @param array $data 32 | * @return stdClass|null 33 | */ 34 | public function create(array $data):? stdClass 35 | { 36 | return $this->setOperator('create')->setData($data)->request($this->object); 37 | } 38 | } -------------------------------------------------------------------------------- /src/Traits/CanDelete.php: -------------------------------------------------------------------------------- 1 | 11 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 12 | * @license https://github.com/cyber-duck/pardot-api/license 13 | * @version 1.0.0 14 | * @link https://github.com/cyber-duck/pardot-api 15 | * @since 1.0.0 16 | */ 17 | trait CanDelete 18 | { 19 | /** 20 | * Sends the request to delete the object 21 | * 22 | * /api/{object}/version/{version}/do/delete/id/?... 23 | * 24 | * required: user_key, api_key, id 25 | * 26 | * @param int $id 27 | * @return int 28 | * @todo returns HTTP 204 No Content on success 29 | */ 30 | public function delete(int $id):? stdClass 31 | { 32 | return $this->setOperator(sprintf('delete/id/%s', $id))->request($this->object); 33 | } 34 | } -------------------------------------------------------------------------------- /src/Traits/CanQuery.php: -------------------------------------------------------------------------------- 1 | 16 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 17 | * @license https://github.com/cyber-duck/pardot-api/license 18 | * @version 1.0.0 19 | * @link https://github.com/cyber-duck/pardot-api 20 | * @since 1.0.0 21 | */ 22 | trait CanQuery 23 | { 24 | /** 25 | * Sends the request to query the object results and returns them from the API 26 | * 27 | * /api/{operator}/version/{version}/do/query?... 28 | * 29 | * required: user_key, api_key 30 | * 31 | * @param array $criteria 32 | * @return mixed 33 | */ 34 | public function query(array $criteria = []) 35 | { 36 | return $this->setOperator('query')->setData($criteria)->request('result'); 37 | } 38 | } -------------------------------------------------------------------------------- /src/Traits/CanRead.php: -------------------------------------------------------------------------------- 1 | 13 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 14 | * @license https://github.com/cyber-duck/pardot-api/license 15 | * @version 1.0.0 16 | * @link https://github.com/cyber-duck/pardot-api 17 | * @since 1.0.0 18 | */ 19 | trait CanRead 20 | { 21 | /** 22 | * Sends the request to retrieve the object and returns it from the API 23 | * 24 | * /api/{operator}/version/{version}/do/read/id/?... 25 | * 26 | * required: user_key, api_key, id 27 | * 28 | * @param int $id 29 | * @return stdClass|null 30 | */ 31 | public function read(int $id):? stdClass 32 | { 33 | return $this->setOperator(sprintf('read/id/%s', $id))->request($this->object); 34 | } 35 | } -------------------------------------------------------------------------------- /src/Traits/CanUpdate.php: -------------------------------------------------------------------------------- 1 | 13 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 14 | * @license https://github.com/cyber-duck/pardot-api/license 15 | * @version 1.0.0 16 | * @link https://github.com/cyber-duck/pardot-api 17 | * @since 1.0.0 18 | */ 19 | trait CanUpdate 20 | { 21 | /** 22 | * Sends the request to update the object and return it from the API 23 | * 24 | * /api/{operator}/version/{version}/do/update/id/?... 25 | * 26 | * required: user_key, api_key, id 27 | * 28 | * @param int $id 29 | * @param array $data 30 | * @return stdClass|null 31 | */ 32 | public function update(int $id, array $data):? stdClass 33 | { 34 | return $this->setOperator(sprintf('update/id/%s', $id))->setData($data)->request($this->object); 35 | } 36 | } -------------------------------------------------------------------------------- /src/Validator/BooleanValidator.php: -------------------------------------------------------------------------------- 1 | 11 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 12 | * @license https://github.com/cyber-duck/pardot-api/license 13 | * @version 1.0.0 14 | * @link https://github.com/cyber-duck/pardot-api 15 | * @since 1.0.0 16 | */ 17 | class BooleanValidator extends Validator 18 | { 19 | /** 20 | * Validation method 21 | * 22 | * @param mixed $value 23 | * @return boolean 24 | */ 25 | public function validate($value): bool 26 | { 27 | return is_bool($value); 28 | } 29 | } -------------------------------------------------------------------------------- /src/Validator/DateValidator.php: -------------------------------------------------------------------------------- 1 | 11 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 12 | * @license https://github.com/cyber-duck/pardot-api/license 13 | * @version 1.0.0 14 | * @link https://github.com/cyber-duck/pardot-api 15 | * @since 1.0.0 16 | */ 17 | class DateValidator extends Validator 18 | { 19 | /** 20 | * Allowed date query values 21 | * 22 | * @var array 23 | */ 24 | protected $values = [ 25 | 'today', 26 | 'yesterday', 27 | 'last_7_days', 28 | 'this_month', 29 | 'last_month' 30 | ]; 31 | 32 | /** 33 | * Validation method 34 | * 35 | * @param mixed $value 36 | * @return boolean 37 | */ 38 | public function validate($value): bool 39 | { 40 | if(in_array($value, $this->values)) { 41 | return true; 42 | } 43 | // custom_time @todo 44 | } 45 | } -------------------------------------------------------------------------------- /src/Validator/FixedValuesValidator.php: -------------------------------------------------------------------------------- 1 | 11 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 12 | * @license https://github.com/cyber-duck/pardot-api/license 13 | * @version 1.0.0 14 | * @link https://github.com/cyber-duck/pardot-api 15 | * @since 1.0.0 16 | */ 17 | class FixedValuesValidator extends Validator 18 | { 19 | /** 20 | * Allowed query values 21 | * 22 | * @var array 23 | */ 24 | protected $values = []; 25 | 26 | /** 27 | * Sets the allowed values 28 | * 29 | * @param string[] ...$args 30 | */ 31 | public function __construct(...$args) 32 | { 33 | $this->values = func_get_args(); 34 | } 35 | 36 | /** 37 | * Validation method 38 | * 39 | * @param mixed $value 40 | * @return boolean 41 | */ 42 | public function validate($value): bool 43 | { 44 | return in_array($value, $this->values); 45 | } 46 | } -------------------------------------------------------------------------------- /src/Validator/PositiveIntListValidator.php: -------------------------------------------------------------------------------- 1 | 11 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 12 | * @license https://github.com/cyber-duck/pardot-api/license 13 | * @version 1.0.0 14 | * @link https://github.com/cyber-duck/pardot-api 15 | * @since 1.0.0 16 | */ 17 | class PositiveIntListValidator extends Validator 18 | { 19 | /** 20 | * Validation method 21 | * 22 | * @param mixed $value 23 | * @return boolean 24 | */ 25 | public function validate($value): bool 26 | { 27 | foreach(explode(',', $value) as $value) { 28 | if(!is_numeric($value)) return false; 29 | } 30 | return true; 31 | } 32 | } -------------------------------------------------------------------------------- /src/Validator/PositiveIntValidator.php: -------------------------------------------------------------------------------- 1 | 11 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 12 | * @license https://github.com/cyber-duck/pardot-api/license 13 | * @version 1.0.0 14 | * @link https://github.com/cyber-duck/pardot-api 15 | * @since 1.0.0 16 | */ 17 | class PositiveIntValidator extends Validator 18 | { 19 | /** 20 | * Validation method 21 | * 22 | * @param mixed $value 23 | * @return boolean 24 | */ 25 | public function validate($value): bool 26 | { 27 | return is_numeric($value) && $value > 0; 28 | } 29 | } -------------------------------------------------------------------------------- /src/Validator/SortOrderValidator.php: -------------------------------------------------------------------------------- 1 | 11 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 12 | * @license https://github.com/cyber-duck/pardot-api/license 13 | * @version 1.0.0 14 | * @link https://github.com/cyber-duck/pardot-api 15 | * @since 1.0.0 16 | */ 17 | class SortOrderValidator extends Validator 18 | { 19 | /** 20 | * Allowed query values 21 | * 22 | * @var array 23 | */ 24 | protected $values = [ 25 | 'ascending', 26 | 'descending' 27 | ]; 28 | 29 | /** 30 | * Validation method 31 | * 32 | * @param mixed $value 33 | * @return boolean 34 | */ 35 | public function validate($value): bool 36 | { 37 | return in_array($value, $this->values); 38 | } 39 | } -------------------------------------------------------------------------------- /src/Validator/StringValidator.php: -------------------------------------------------------------------------------- 1 | 11 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 12 | * @license https://github.com/cyber-duck/pardot-api/license 13 | * @version 1.0.0 14 | * @link https://github.com/cyber-duck/pardot-api 15 | * @since 1.0.0 16 | */ 17 | class StringValidator extends Validator 18 | { 19 | /** 20 | * Validation method 21 | * 22 | * @param mixed $value 23 | * @return boolean 24 | */ 25 | public function validate($value): bool 26 | { 27 | return is_string($value); 28 | } 29 | } -------------------------------------------------------------------------------- /src/Validator/Validator.php: -------------------------------------------------------------------------------- 1 | 11 | * @copyright Copyright (c) 2018, Andrew Mc Cormack 12 | * @license https://github.com/cyber-duck/pardot-api/license 13 | * @version 1.0.0 14 | * @link https://github.com/cyber-duck/pardot-api 15 | * @since 1.0.0 16 | */ 17 | abstract class Validator 18 | { 19 | /** 20 | * Validation method 21 | * 22 | * @param mixed $value 23 | * @return boolean 24 | */ 25 | abstract public function validate($value): bool; 26 | } --------------------------------------------------------------------------------