-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathamazonLookup.php
More file actions
93 lines (63 loc) · 1.8 KB
/
amazonLookup.php
File metadata and controls
93 lines (63 loc) · 1.8 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
require_once dirname(__FILE__).'/inc/AmazonSearchWrapper.php';
require_once dirname(__FILE__).'/inc/AmazonBookDetail.php';
require_once dirname(__FILE__).'/inc/APIResponse.php';
$amazonID = "";
$token = "";
$tokenLookup = $_ENV['FF_API_TOKEN'];
$accessKey = $_ENV['FF_AWS_ACCESS_KEY'];
$secretKey = $_ENV['FF_AWS_SECRET_KEY'];
$country = $_ENV['FF_COUNTRY'];
$associateTag = $_ENV['FF_ASSOCIATE_TAG'];
$bookCoverURL = $_ENV['FF_BOOK_COVER_SERVER'];
if ("cli" !== PHP_SAPI)
{
header ("content-type: application/json");
$amazonID = $_REQUEST['amazonID'];
$token = $_REQUEST['token'];
$returnVal = new APIResponse();
$returnVal->response = array();
$returnVal->http_response = 200;
$returnVal->message = "";
if( !isset( $token ) )
{
$msg = 'token is missing';
$returnVal->http_response = 400;
$returnVal->message = $msg;
$returnVal->ex_time = microtime(true) - $starttime;
header("HTTP/1.1 400 $msg");
echo json_encode($returnVal);
return FALSE;
}
if( $token != $tokenLookup )
{
$msg = 'token is incorrect';
$returnVal->http_response = 400;
$returnVal->message = $msg;
$returnVal->ex_time = microtime(true) - $starttime;
header("HTTP/1.1 400 $msg");
echo json_encode($returnVal);
return FALSE;
}
} else {
$amazonID = $argv[1];
$token = $argv[2];
if( !isset( $token ) )
{
$msg = 'token is missing';
echo $msg;
return FALSE;
}
if( $token != $tokenLookup )
{
$msg = 'token is incorrect';
echo $msg;
return FALSE;
}
}
$asw = new AmazonSearchWrapper($accessKey, $secretKey, $country, $associateTag, $bookCoverURL);
$searchArray = array();
$searchArray['searchresults'] = $asw->lookup( $amazonID );
$response = array();
$response['response'] = $searchArray;
echo json_encode($response);