Skip to content

Instantly share code, notes, and snippets.

@riaf
Created February 27, 2009 17:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save riaf/71584 to your computer and use it in GitHub Desktop.
Save riaf/71584 to your computer and use it in GitHub Desktop.
<?php
if(!class_exists('Rhaco')) require_once 'rhaco/Rhaco.php';
Rhaco::import('network.http.Browser');
class AmazonReport
{
var $base_url = 'https://affiliate.amazon.co.jp';
var $browser;
function AmazonReport($email, $password){
$this->login($email, $password);
}
function login($email, $password){
$browser = new Browser();
$browser->get($this->base_url . '/gp/associates/login/login.html');
$browser->setVariable('email', $email);
$browser->setVariable('password', $password);
$browser->submit('sign-in');
return $this->browser =& $browser;
}
function getData($param = array()){
return $this->parseXml($this->getXml($param));
}
function parseXml($xml){
$tag = new SimpleTag();
$tag->set($xml, 'Data');
return $tag->toHash();
}
function getXml($param = array()){
$this->browser->clearVariable();
list($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime();
$param_default = array(
'ie' => 'UTF8',
'reportType' => 'ordersReport',
'periodType' => 'exact',
'startMonth' => '1',
'startDat' => '1',
'startYear' => '2002',
'endMonth' => $mon + 1,
'endDay' => $mday,
'endYear' => $year + 1900,
);
foreach($param as $k => $v){
$param_default[$k] = $v;
}
$url = $this->base_url . '/network/reports/report.html/?' . http_build_query($param_default) . '&submit.download_XML';
return $this->browser->get($url);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment