-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathmaster_report_sample.php
78 lines (71 loc) · 2.2 KB
/
master_report_sample.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
ini_set("default_socket_timeout", 30);
require_once 'restapi.php';
$config = parse_ini_file("sample.ini");
print_r($config);
function debug($obj, $detail = false)
{
if (is_array($obj)) {
echo "size : " . count($obj) . "\n";
}
if ($detail) {
print_r($obj);
}
}
// #. detail log
$DEBUG = false;
$api = new RestApi($config['BASE_URL'], $config['API_KEY'], $config['SECRET_KEY'], $config['CUSTOMER_ID']);
echo "Test Master Report\n";
$item = "Keyword";
$master_full_req = array(
"item" => $item
);
echo " #1. full master\n";
$response = $api->POST("/master-reports", $master_full_req);
debug($response, $DEBUG);
$id = $response["id"];
$status = $response["status"];
echo "registed : id = $id, status = " . $status . "\n";
while ($status == 'REGIST' || $status == 'RUNNING') {
echo "waiting a report..\n";
sleep(5);
$response = $api->GET("/master-reports/" . $id);
$status = $response["status"];
echo "check : id = $id, status = " . $status . "\n";
}
if ($status == 'BUILT') {
echo "downloadUrl => " . $response["downloadUrl"] . "\n";
$api->DOWNLOAD($response["downloadUrl"], $item . "-" . $id . ".tsv");
} else if ($status == 'ERROR') {
echo "failed to build master report\n";
} else if ($status == 'NONE') {
echo "master has no data\n";
}
echo " #2. delta master\n";
$fromTime = "2016-04-01T00:00:00Z";
$master_delta_req = array(
"item" => $item,
"fromTime" => $fromTime
);
$response = $api->POST("/master-reports", $master_delta_req);
debug($response, $DEBUG);
$id = $response["id"];
$status = $response["status"];
echo "registed : id = $id, status = " . $status . "\n";
while ($status == 'REGIST' || $status == 'RUNNING') {
echo "waiting a report..\n";
sleep(5);
$response = $api->GET("/master-reports/" . $id);
$status = $response["status"];
echo "check : id = $id, status = " . $status . "\n";
}
if ($status == 'BUILT') {
echo "downloadUrl => " . $response["downloadUrl"] . "\n";
$api->DOWNLOAD($response["downloadUrl"], "delta-" . $item . "-" . $id . ".tsv");
} else if ($status == 'ERROR') {
echo "failed to build master report\n";
} else if ($status == 'NONE') {
echo "master has no data\n";
}
echo "\nTest End\n";
?>