public
Description: MIT licensed code without warranty ; )
Homepage: http://www.debuggable.com/
Clone URL: git://github.com/felixge/debuggable-scraps.git
debuggable-scraps / cakephp / datasources / amazon_associates / amazon_associates_source.php
100644 68 lines (62 sloc) 1.639 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
<?php
/**
* A CakePHP datasource for interacting with the amazon associates API.
*
* Copyright 2008, Debuggable, Ltd.
* Hibiskusweg 26c
* 13089 Berlin, Germany
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2008, Debuggable, Ltd.
* @version 0.1
* @author Felix Geisendörfer <felix@debuggable.com>, Tim Koschützki <tim@debuggable.com>
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
App::import('Xml');
class AmazonAssociatesSource extends DataSource{
var $description = "AmazonAssociates Data Source";
 
function __construct($config) {
parent::__construct($config);
App::import('HttpSocket');
$this->Http = new HttpSocket();
}
 
function find($type, $query = array()) {
if (is_array($type)) {
$query = $type;
} else {
$query['type'] = $type;
}
if (!is_array($query)) {
$query = array('Title' => $query);
}
$map = array(
'info' => 'ResponseGroup',
'type' => 'SearchIndex',
);
foreach ($map as $old => $new) {
$query[$new] = $query[$old];
unset($query[$old]);
}
foreach ($query as $key => $val) {
if (preg_match('/^[a-z]/', $key)) {
$query[Inflector::camelize($key)] = $val;
unset($query[$key]);
}
}
$query = am(array(
'Service' => 'AWSECommerceService',
'AWSAccessKeyId' => $this->config['key'],
'Operation' => 'ItemSearch',
'Version' => '2008-06-28',
), $query);
$r = $this->Http->get('http://ecs.amazonaws.com/onca/xml', $query);
$r = Set::reverse(new Xml($r));
return $r;
}
 
function close() {
return true;
}
}
 
 
 
?>