Skip to content

Commit 1b3df38

Browse files
committed
Added version 2.5.1.
0 parents  commit 1b3df38

30 files changed

+10389
-0
lines changed

api/LICENSE

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
Copyright (c) 2010 Toby Brain
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.
20+
21+
------------------------------------------------------------------------------
22+
For Services_JSON Library (classes/services_json.php)
23+
------------------------------------------------------------------------------
24+
Redistribution and use in source and binary forms, with or
25+
without modification, are permitted provided that the following
26+
conditions are met: Redistributions of source code must retain the
27+
above copyright notice, this list of conditions and the following
28+
disclaimer. Redistributions in binary form must reproduce the above
29+
copyright notice, this list of conditions and the following disclaimer
30+
in the documentation and/or other materials provided with the
31+
distribution.
32+
33+
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
34+
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
35+
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
36+
NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
37+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
38+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
39+
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
40+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
41+
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
42+
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
43+
DAMAGE.
44+
Author: Michal Migurski <mike-json@teczno.com>
45+
Author: Matt Knapp <mdknapp[at]gmail[dot]com>
46+
Author: Brett Stimmerman <brettstimmerman[at]gmail[dot]com>
47+
Copyright (c) 2005 Michal Migurski
48+
http://www.opensource.org/licenses/bsd-license.php

api/README.md

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
# createsend [![Build Status](https://secure.travis-ci.org/campaignmonitor/createsend-php.png)][travis]
2+
A PHP library which implements the complete functionality of the [Campaign Monitor API](http://www.campaignmonitor.com/api/).
3+
4+
[travis]: http://travis-ci.org/campaignmonitor/createsend-php
5+
6+
## Installation
7+
8+
If you use [Composer](http://getcomposer.org/), you can add [campaignmonitor/createsend-php](https://packagist.org/packages/campaignmonitor/createsend-php) to your `composer.json` file:
9+
10+
```json
11+
{
12+
"require": {
13+
"campaignmonitor/createsend-php": "{version}"
14+
}
15+
}
16+
```
17+
18+
Otherwise you can simply [download](https://github.com/campaignmonitor/createsend-php/tags) the library and include it in your project.
19+
20+
After you have installed the library, simply include the relevant API class, as follows:
21+
22+
```php
23+
require_once 'csrest_campaigns.php'
24+
```
25+
26+
## Authenticating
27+
28+
The Campaign Monitor API supports authentication using either OAuth or an API key.
29+
30+
### Using OAuth
31+
32+
Depending on the environment you are developing in, you may wish to use a PHP OAuth library to get access tokens for your users. If you don't use an OAuth library, you will need to get access tokens for your users by following the instructions included in the Campaign Monitor API [documentation](http://www.campaignmonitor.com/api/getting-started/#authenticating_with_oauth). This package provides functionality to help you do this, as described below. You may also wish to reference this [example application](https://gist.github.com/jdennes/4973318), which is implemented using [Slim](http://slimframework.com/) but could easily be adapted for use with any PHP framework.
33+
34+
The first thing your application should do is redirect your user to the Campaign Monitor authorization URL where they will have the opportunity to approve your application to access their Campaign Monitor account. You can get this authorization URL by using the `CS_REST_General::authorize_url()` method, like so:
35+
36+
```php
37+
require_once 'csrest_general.php';
38+
39+
$authorize_url = CS_REST_General::authorize_url(
40+
'Client ID for your application',
41+
'Redirect URI for your application',
42+
'The permission level your application requires',
43+
'Optional state data to be included'
44+
);
45+
# Redirect your users to $authorize_url.
46+
```
47+
48+
If your user approves your application, they will then be redirected to the `redirect_uri` you specified, which will include a `code` parameter, and optionally a `state` parameter in the query string. Your application should implement a handler which can exchange the code passed to it for an access token, using `CS_REST_General::exchange_token()` like so:
49+
50+
```php
51+
require_once 'csrest_general.php';
52+
53+
$result = CS_REST_General::exchange_token(
54+
'Client ID for your application',
55+
'Client Secret for your application',
56+
'Redirect URI for your application',
57+
'A unique code for your user' # Get the code parameter from the query string
58+
);
59+
60+
if ($result->was_successful()) {
61+
$access_token = $result->response->access_token;
62+
$expires_in = $result->response->expires_in;
63+
$refresh_token = $result->response->refresh_token;
64+
# Save $access_token, $expires_in, and $refresh_token.
65+
} else {
66+
echo 'An error occurred:\n';
67+
echo $result->response->error.': '.$result->response->error_description."\n";
68+
# Handle error...
69+
}
70+
```
71+
72+
At this point you have an access token and refresh token for your user which you should store somewhere convenient so that your application can look up these values when your user wants to make future Campaign Monitor API calls.
73+
74+
Once you have an access token and refresh token for your user, you can authenticate and make further API calls like so:
75+
76+
```php
77+
require_once 'csrest_general.php';
78+
79+
$auth = array(
80+
'access_token' => 'your access token',
81+
'refresh_token' => 'your refresh_token');
82+
$wrap = new CS_REST_General($auth);
83+
84+
$result = $wrap->get_clients();
85+
var_dump($result->response);
86+
```
87+
88+
All OAuth tokens have an expiry time, and can be renewed with a corresponding refresh token. If your access token expires when attempting to make an API call, you will receive an error response, so your code should handle this. Here's an example of how you could do this:
89+
90+
```php
91+
require_once 'csrest_general.php';
92+
93+
$auth = array(
94+
'access_token' => 'your access token',
95+
'refresh_token' => 'your refresh token'
96+
);
97+
$wrap = new CS_REST_General($auth);
98+
$result = $wrap->get_clients();
99+
if (!$result->was_successful()) {
100+
# If you receive '121: Expired OAuth Token', refresh the access token
101+
if ($result->response->Code == 121) {
102+
list($new_access_token, $new_expires_in, $new_refresh_token) =
103+
$wrap->refresh_token();
104+
# Save $new_access_token, $new_expires_in, and $new_refresh_token
105+
}
106+
# Make the call again
107+
$result = $wrap->get_clients();
108+
}
109+
var_dump($result->response);
110+
```
111+
112+
### Using an API key
113+
114+
```php
115+
require_once 'csrest_general.php';
116+
117+
$auth = array('api_key' => 'your API key');
118+
$wrap = new CS_REST_General($auth);
119+
120+
$result = $wrap->get_clients();
121+
var_dump($result->response);
122+
```
123+
124+
## Examples
125+
126+
Samples for creating or accessing all resources can be found in the samples directory.
127+
These samples can be used as the basis for your own application and provide an outline of
128+
the expected inputs for each API call.
129+
130+
Further documentation of the inputs and outputs of each call can be found in the
131+
documentation in each of the csrest_*.php files or simply by examining the
132+
var_dump results in each of the provided samples.
133+
134+
## Contributing
135+
136+
Please check the [guidelines for contributing](https://github.com/campaignmonitor/createsend-php/blob/master/CONTRIBUTING.md) to this repository.
137+
138+
## Releasing
139+
140+
Please check the [instructions for releasing](https://github.com/campaignmonitor/createsend-php/blob/master/RELEASE.md) this library.

0 commit comments

Comments
 (0)