Skip to content

Commit 053b7ec

Browse files
Merge pull request #10 from FreshMail/feature-APPDEV-5347
New version of API Client V3
2 parents 0a36e43 + a8e61d0 commit 053b7ec

24 files changed

Lines changed: 719 additions & 597 deletions

README.md

Lines changed: 99 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,119 @@
11
# FreshMail
22

3-
A php library which implements the functionality of FreshMail REST API.
3+
A php library which implements connection to FreshMail REST API.
44

55
This API client covers all functions of API V2 such as:
66
- subscribers management
77
- list management
88
- campaign management
99
- sending transactional SMS messages
10-
- sending transactional mail messages (in a legacy way)
1110

1211
If You want to send transactional messages in rich format please use new [API V3 client](https://github.com/FreshMail/php-api-client).
1312

14-
## Installation via composer
13+
## Installation via composer (compatible with PHP >=7.0)
1514

16-
Add to `composer.json` file:
15+
Add via composer:
16+
17+
composer require freshmail/rest-api:^3.0
1718

18-
{
19-
"require": {
20-
"freshmail/rest-api": "dev-master"
21-
}
22-
}
19+
## Installation of old version of library (compatible with PHP >=5.3)
2320

24-
Use in php project:
21+
Add via composer:
22+
23+
composer require freshmail/rest-api:^2.0
2524

26-
use FreshMail\RestApi as FmRestApi;
25+
## Usage
2726

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/)
2928

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
3239

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
3452

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);
3664

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);

class.rest.php

Lines changed: 0 additions & 13 deletions
This file was deleted.

composer.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,16 @@
3131
}
3232
],
3333
"require": {
34-
"php": ">=5.3.0",
34+
"php": ">=7.0",
3535
"ext-curl": "*",
36-
"ext-json": "*"
36+
"ext-json": "*",
37+
"psr/log": "^1.1",
38+
"monolog/monolog": "^1.25",
39+
"guzzlehttp/guzzle": "^6.5"
3740
},
3841
"autoload": {
39-
"psr-0": {
40-
"FreshMail": "src/"
42+
"psr-4": {
43+
"FreshMail\\ApiV2\\": "src/FreshMail/"
4144
}
4245
}
4346
}

0 commit comments

Comments
 (0)