|
1 | 1 | # FreshMail |
2 | 2 |
|
3 | | -A php library which implements the functionality of FreshMail REST API. |
| 3 | +A php library which implements connection to FreshMail REST API. |
4 | 4 |
|
5 | 5 | This API client covers all functions of API V2 such as: |
6 | 6 | - subscribers management |
7 | 7 | - list management |
8 | 8 | - campaign management |
9 | 9 | - sending transactional SMS messages |
10 | | - - sending transactional mail messages (in a legacy way) |
11 | 10 |
|
12 | 11 | If You want to send transactional messages in rich format please use new [API V3 client](https://github.com/FreshMail/php-api-client). |
13 | 12 |
|
14 | | -## Installation via composer |
| 13 | +## Installation via composer (compatible with PHP >=7.0) |
15 | 14 |
|
16 | | -Add to `composer.json` file: |
| 15 | +Add via composer: |
| 16 | + |
| 17 | + composer require freshmail/rest-api:^3.0 |
17 | 18 |
|
18 | | - { |
19 | | - "require": { |
20 | | - "freshmail/rest-api": "dev-master" |
21 | | - } |
22 | | - } |
| 19 | +## Installation of old version of library (compatible with PHP >=5.3) |
23 | 20 |
|
24 | | -Use in php project: |
| 21 | +Add via composer: |
| 22 | + |
| 23 | + composer require freshmail/rest-api:^2.0 |
25 | 24 |
|
26 | | - use FreshMail\RestApi as FmRestApi; |
| 25 | +## Usage |
27 | 26 |
|
28 | | -## Installation by hand |
| 27 | +Below some simple examples, for whole API function see [full API V2 doc](https://freshmail.pl/developer-api/jak-zaczac/) |
29 | 28 |
|
30 | | - require_once 'class.rest.php'; |
31 | | - require_once 'config.php'; |
| 29 | +#### Test connection |
| 30 | + |
| 31 | + use \FreshMail\ApiV2\Client; |
| 32 | + |
| 33 | + $token = 'MY_APP_TOKEN'; |
| 34 | + $apiClient = new Client($token); |
| 35 | + |
| 36 | + $apiClient->doRequest('ping'); |
| 37 | + |
| 38 | +#### Create subscribers list |
32 | 39 |
|
33 | | -## Examples |
| 40 | + use \FreshMail\ApiV2\Client; |
| 41 | + |
| 42 | + $token = 'MY_APP_TOKEN'; |
| 43 | + $apiClient = new Client($token); |
| 44 | + |
| 45 | + $data = [ |
| 46 | + 'name' => 'List with subscribers from my website' |
| 47 | + ]; |
| 48 | + |
| 49 | + $apiClient->doRequest('subscribers_list/create', $data); |
| 50 | + |
| 51 | +#### Add subscriber to list |
34 | 52 |
|
35 | | -All samples included in samples directory. |
| 53 | + use \FreshMail\ApiV2\Client; |
| 54 | + |
| 55 | + $token = 'MY_APP_TOKEN'; |
| 56 | + $apiClient = new Client($token); |
| 57 | + |
| 58 | + $data = [ |
| 59 | + 'email' => 'example@email.address', |
| 60 | + 'list' => 'list_hash' |
| 61 | + ]; |
| 62 | + |
| 63 | + $apiClient->doRequest('subscriber/add', $data); |
36 | 64 |
|
37 | | -## Thanks to |
38 | | -@adam187 |
| 65 | +## Proxy setup |
| 66 | + |
| 67 | +To use proxy You can pass Your own GuzzleHttp Client: |
| 68 | + |
| 69 | + use \FreshMail\ApiV2\Client; |
| 70 | + |
| 71 | + $guzzleClient = new \GuzzleHttp\Client( |
| 72 | + [ |
| 73 | + 'proxy' => 'my proxy url' |
| 74 | + ] |
| 75 | + ); |
| 76 | + |
| 77 | + $token = 'MY_APP_TOKEN'; |
| 78 | + $apiClient = new Client($token); |
| 79 | + $apiClient->setGuzzleHttpClient($guzzleClient); |
| 80 | + |
| 81 | +## Debugging |
| 82 | + |
| 83 | +#### PSR-3 Logger Interface |
| 84 | + |
| 85 | +You can use any library that implements [PSR-3](https://www.php-fig.org/psr/psr-3/) `Psr\Log\LoggerInterface`, example with Monolog below: |
| 86 | + |
| 87 | + use \FreshMail\ApiV2\Client; |
| 88 | + |
| 89 | + $logger = new \Monolog\Logger('myCustomLogger'); |
| 90 | + $logger->pushHandler(new \Monolog\Handler\StreamHandler('php://stderr', \Monolog\Logger::DEBUG)); |
| 91 | + |
| 92 | + $token = 'MY_APP_TOKEN'; |
| 93 | + $apiClient = new Client($token); |
| 94 | + $apiClient->setLogger($monolog); |
| 95 | + |
| 96 | +#### Using Guzzle |
| 97 | + |
| 98 | +You can also pass Your own GuzzleHttp Client with proper configuration: |
| 99 | + |
| 100 | + |
| 101 | + use \FreshMail\ApiV2\Client; |
| 102 | + |
| 103 | + $stack = \GuzzleHttp\HandlerStack::create(); |
| 104 | + $stack->push( |
| 105 | + \GuzzleHttp\Middleware::log( |
| 106 | + new \Monolog\Logger('Logger'), |
| 107 | + new \GuzzleHttp\MessageFormatter(\GuzzleHttp\MessageFormatter::DEBUG) |
| 108 | + ) |
| 109 | + ); |
| 110 | + |
| 111 | + $guzzleClient = new \GuzzleHttp\Client( |
| 112 | + [ |
| 113 | + 'handler' => $stack, |
| 114 | + ] |
| 115 | + ); |
| 116 | + |
| 117 | + $token = 'MY_APP_TOKEN'; |
| 118 | + $apiClient = new Client($token); |
| 119 | + $apiClient->setGuzzleHttpClient($guzzleClient); |
0 commit comments