|
| 1 | +# php-autopilothq |
| 2 | + |
| 3 | +A php library for interacting with AutopilotHQ API http://docs.autopilot.apiary.io/#. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +```sh |
| 8 | +$ composer require picr/php-autopilothq |
| 9 | +``` |
| 10 | + |
| 11 | +Create an `.env` file |
| 12 | +```env |
| 13 | +AUTOPILOT_SECRET=your-secret-key |
| 14 | +``` |
| 15 | + |
| 16 | +## Usage |
| 17 | +--- |
| 18 | +All interaction occurs in the `AutopilotManager` class. |
| 19 | + |
| 20 | +### initialize manager |
| 21 | +```php |
| 22 | +// NOTE: AUTOPILOT_SECRET must be defined in .env file |
| 23 | +// NOTE: if AUTOPILOT_HOST is not defined in .env file, will use 'https://api2.autopilothq.com/v1/' |
| 24 | +$manager = new AutopilotManager(); |
| 25 | +``` |
| 26 | + |
| 27 | +### getContact |
| 28 | +```php |
| 29 | +$manager->getContact($id|$email); |
| 30 | +``` |
| 31 | + |
| 32 | +### saveContact |
| 33 | +```php |
| 34 | +$manager->saveContact(AutopilotContact $contact); |
| 35 | +``` |
| 36 | + |
| 37 | +### saveContacts |
| 38 | +```php |
| 39 | +$manager->saveContacts(array $contacts); |
| 40 | +``` |
| 41 | + |
| 42 | +### deleteContact |
| 43 | +```php |
| 44 | +$manager->deleteContact($id|$email); |
| 45 | +``` |
| 46 | + |
| 47 | +### unsubscribeContact |
| 48 | +```php |
| 49 | +$manager->unsubscribeContact($id|$email); |
| 50 | +``` |
| 51 | + |
| 52 | +### subscribeContact |
| 53 | +```php |
| 54 | +$manager->subscribeContact($id|$email); |
| 55 | +``` |
| 56 | + |
| 57 | +### updateContactEmail |
| 58 | +```php |
| 59 | +$manager->updateContactEmail($oldEmail, $newEmail); |
| 60 | +``` |
| 61 | + |
| 62 | +### getAllLists |
| 63 | +```php |
| 64 | +$manager->getAllLists(); |
| 65 | +``` |
| 66 | + |
| 67 | +### createList |
| 68 | +```php |
| 69 | +$manager->createList($list); |
| 70 | +``` |
| 71 | + |
| 72 | +### getListByName |
| 73 | +```php |
| 74 | +$manager->getListByName($list); |
| 75 | +``` |
| 76 | + |
| 77 | +### deleteList |
| 78 | +```php |
| 79 | +//TODO: AutopilotHQ hasn't implemented this yet |
| 80 | +$manager->deleteList($list); |
| 81 | +``` |
| 82 | + |
| 83 | +### getAllContactsInList |
| 84 | +```php |
| 85 | +$manager->getAllContactsInList($list); |
| 86 | +``` |
| 87 | + |
| 88 | +### addContactToList |
| 89 | +```php |
| 90 | +$manager->addContactToList($list, $id|$email); |
| 91 | +``` |
| 92 | + |
| 93 | +### removeContactFromList |
| 94 | +```php |
| 95 | +$manager->removeContactFromList($list, $id|$email); |
| 96 | +``` |
| 97 | + |
| 98 | +### checkContactInList |
| 99 | +```php |
| 100 | +$manager->checkContactInList($list, $id|$email); |
| 101 | +``` |
| 102 | + |
| 103 | +### allTriggers |
| 104 | +```php |
| 105 | +$manager->allTriggers(); |
| 106 | +``` |
| 107 | + |
| 108 | +### addContactToJourney |
| 109 | +```php |
| 110 | +$manager->addContactToJourney($journey, $id|$email); |
| 111 | +``` |
| 112 | + |
| 113 | +## AutopilotContact |
| 114 | +--- |
| 115 | +### get value |
| 116 | +```php |
| 117 | +// magic method |
| 118 | +$value = $contact->$name; |
| 119 | +// getter |
| 120 | +$value = $contact->getFieldValue($name); |
| 121 | +``` |
| 122 | + |
| 123 | +### set value |
| 124 | +```php |
| 125 | +// magic method |
| 126 | +$contact->$name = $value; |
| 127 | +// setter |
| 128 | +$contact->setFieldValue($name, $value); |
| 129 | +``` |
| 130 | + |
| 131 | +### unset value |
| 132 | +```php |
| 133 | +// magic method |
| 134 | +unset($contact->$name); |
| 135 | +// method |
| 136 | +$contact->unsetFieldValue($name); |
| 137 | +``` |
| 138 | + |
| 139 | +### isset value |
| 140 | +```php |
| 141 | +// magic method |
| 142 | +isset($contact->$name); |
| 143 | +// method |
| 144 | +$contact->issetFieldValue($name); |
| 145 | +``` |
| 146 | + |
| 147 | +### getAllContactLists |
| 148 | +```php |
| 149 | +//NOTE: this only reads cached "lists" array returned for a "contact info" request |
| 150 | +$contact->getAllContactLists(); |
| 151 | +``` |
| 152 | + |
| 153 | +### hasList |
| 154 | +```php |
| 155 | +//NOTE: this only reads cached "lists" array returned for a "contact info" request |
| 156 | +$contact->hasList($list); |
| 157 | +``` |
| 158 | + |
| 159 | +### fill |
| 160 | +```php |
| 161 | +// read array of values and populate properties |
| 162 | +// NOTE: automatically formats attributes according to AutopilotHQ's "naming convention" (doesn't really exist) |
| 163 | +$contact->fill([ |
| 164 | + 'firstName' => 'John', |
| 165 | + 'lastName' => 'Smith', |
| 166 | + 'age' => 42, |
| 167 | +]); |
| 168 | +``` |
| 169 | + |
| 170 | +### toRequest |
| 171 | +```php |
| 172 | +// return array ready to be pushed to the API |
| 173 | +$user = $contact->toRequest(); |
| 174 | +``` |
| 175 | + |
| 176 | +### toArray |
| 177 | +```php |
| 178 | +// return array of [ property => value ] no matter if custom or defined field |
| 179 | +$user = $contact->toArray(); |
| 180 | +/* [ |
| 181 | + * 'firstName' => 'John', |
| 182 | + * 'lastName' => 'Smith', |
| 183 | + * 'age' => 42, |
| 184 | + * ] |
| 185 | + */ |
| 186 | +``` |
| 187 | + |
| 188 | +### jsonSerialize |
| 189 | +```php |
| 190 | +// json representation of "toArray()" |
| 191 | +$user = $contact->jsonSerialze(); |
| 192 | +$user = json_encode($contact); |
| 193 | +``` |
| 194 | + |
| 195 | +License |
| 196 | +--- |
| 197 | + |
| 198 | +MIT |
0 commit comments