Skip to content

Commit 462f633

Browse files
committed
pre-changes
1 parent e428a90 commit 462f633

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed

Diff for: Client.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
class Client {
1515

1616
// Make screenshot action
17-
const MAKE_SCREENSHOT_ACTION = '/makeScreenshot';
17+
const MAKE_SCREENSHOT_ACTION = '/create-job';
1818
// Get screenshot action
19-
const GET_SCREENSHOT_ACTION = '/getScreenshot';
19+
const GET_SCREENSHOT_ACTION = '/get-job-result';
2020

2121
/** @var Logger\LoggerInterface */
2222
private $_logger;
@@ -59,7 +59,7 @@ public function setLogger(Logger\LoggerInterface $logger) {
5959
*/
6060
public function makeScreenshot(Params\MakeParams $params, Adapter\AdapterInterface $adapter, ImageCreator $creator) {
6161
// Make request
62-
$params = $params->getParams($this->_secret);
62+
$params = $params->getParams();
6363
if ($response = $this->postRequest($this->getActionUrl(self::MAKE_SCREENSHOT_ACTION), $params)) {
6464
$adapter->makeScreenshot($response, $creator);
6565
}
@@ -72,7 +72,7 @@ public function makeScreenshot(Params\MakeParams $params, Adapter\AdapterInterfa
7272
*/
7373
public function getScreenshot(Params\GetParams $params, Adapter\AdapterInterface $adapter) {
7474
// Make request
75-
$params = $params->getParams($this->_secret);
75+
$params = $params->getParams();
7676
if ($response = $this->postRequest($this->getActionUrl(self::GET_SCREENSHOT_ACTION), $params)) {
7777
$adapter->getScreenshot($response);
7878
}
@@ -116,6 +116,11 @@ protected function postRequest($url, $data = []) {
116116
curl_setopt($ch, CURLOPT_POST, 1);
117117
curl_setopt($ch, CURLOPT_POSTFIELDS, $postString);
118118
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
119+
curl_setopt($ch, CURLOPT_HTTPHEADER, [
120+
'Authorization: Bearer '. $this->_secret,
121+
"Cache-Control: no-cache",
122+
]);
123+
119124
$response = curl_exec($ch);
120125

121126
if(curl_errno($ch)) {

Diff for: Params/BaseParams.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@ abstract class BaseParams {
1515
* @param string $secret - client key
1616
* @return array
1717
*/
18-
public function getParams($secret) {
19-
return [
20-
'secret' => $secret,
21-
'params' => $this->params()
22-
];
18+
public function getParams() {
19+
return $this->params();
2320
}
2421

2522
abstract public function params();

Diff for: Params/MakeParams.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class MakeParams extends BaseParams {
1212

13-
const AUTO_SCALE = 'auto';
13+
const AUTO_SCALE = 0;
1414

1515
/**@var string - url to take screenshot */
1616
private $_url;

Diff for: README.md

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
Cagoi screenshots
22
=================
33

4-
Library for easy screenshots making
4+
Library for an easy screenshots making
55

66

77
Quick structure description
88
---------------------------
99

10-
###"Root directory"
10+
### "Root directory"
11+
1112
**Cagoi\Screenshots\Client** - this class manages all process;
1213

1314
**Cagoi\Screenshots\ImageCreator** - helps create images by response from server;
1415

1516
**Cagoi\Screenshots\Exception** - library exception;
1617

17-
###"Adapter" directory
18+
### "Adapter" directory
19+
1820
In this directory you can find predefined adapters. Now available adapter for MongoDb, but you can define new adapter
1921
for your own purposes.
2022

@@ -23,10 +25,10 @@ It needs for handle such operations:
2325
- Get screenshot;
2426
- Callback processing.
2527

26-
###"Logger" directory
28+
### "Logger" directory
2729
Classes for log work process. You can define new logger for your own purposes. Cagoi\Screenshots\Logger\FileLogger - log in file
2830

29-
###"Params" directory
31+
### "Params" directory
3032
Classes in this directory helps prepare request parameters:
3133

3234
**Cagoi\Screenshots\Params\GetParams** - helps with parameters for get screenshot request
@@ -82,19 +84,19 @@ $params->setCallback("http://my.site.com/callback");
8284
$params->setElementId("<element id>");
8385
// Delay in milliseconds
8486
$params->setDelay(1000);
85-
// Set scale width = 300px, height = auto scale
87+
// Set scale width = 300px, height = 0 (auto scale)
8688
$params->addWidthScale(300);
87-
// Set scale width = auto scale, height = 300px
89+
// Set scale width = 0 (auto scale), height = 300px
8890
$params->addHeightScale(300);
8991
// Set scale width = 300px, height = 300px
9092
$params->addScale(300, 300);
9193

9294
$creator = Cagoi\Screenshots\ImageCreator();
9395
// Create full image
9496
$creator->add('full', '<path to save>', '<filename>');
95-
// Create image with width = 300px, height = auto scale
97+
// Create image with width = 300px, height = 0 (auto scale)
9698
$creator->add('300x0', '<path to save>', '<filename>');
97-
// Create image with width = auto scale, height = 300px
99+
// Create image with width = 0 (auto scale), height = 300px
98100
$creator->add('0x300', '<path to save>', '<filename>');
99101
// Create image with width = 300px, height = 300px
100102
$creator->add('300x300', '<path to save>', '<filename>');

0 commit comments

Comments
 (0)