Skip to content

Commit d23f717

Browse files
author
John O
committed
Initial commit.
0 parents  commit d23f717

17 files changed

+2688
-0
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/vendor
2+
composer.lock
3+
/.idea
4+
/tests/_support/_generated
5+
.env

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 PICR
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+198
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
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

codeception.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
actor: Tester
2+
paths:
3+
tests: tests
4+
log: tests/_output
5+
data: tests/_data
6+
support: tests/_support
7+
settings:
8+
bootstrap: _bootstrap.php
9+
colors: true
10+
memory_limit: 1024M

composer.json

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "picr/php-autopilothq",
3+
"type": "library",
4+
"description": "PHP wrapper for interacting with the AutopilotHQ API.",
5+
"homepage": "https://github.com/finicprint/php-autopilothq",
6+
"keywords": ["picr", "autopilothq", "autopilot"],
7+
"version": "0.0.9",
8+
"license": "MIT",
9+
"authors": [
10+
{
11+
"name": "John O",
12+
"email": "[email protected]"
13+
}
14+
],
15+
"require": {
16+
"php": ">=5.5.9",
17+
"guzzlehttp/guzzle": "~6.0",
18+
"vlucas/phpdotenv": "~1.0"
19+
},
20+
"require-dev": {
21+
"codeception/codeception": "~2.1.",
22+
"codeception/aspect-mock": "dev-master"
23+
},
24+
"autoload": {
25+
"psr-4": {
26+
"Autopilot\\": "src/",
27+
"Tests\\": "tests/"
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)