Created
April 12, 2011 06:38
-
-
Save v9n/915053 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $username = 'kureikain'; | |
| $apikey = 'xxx'; | |
| class Axcoto_Envato_Api { | |
| public function __construct($attb) { | |
| $this->_attb = $attb; | |
| } | |
| public function fetch($method, $param = array()) { | |
| $url = 'http://marketplace.envato.com/api/edge/'; | |
| if ($param) { | |
| $param = implode(':', $param); | |
| $url .= $method . ':' . $param; | |
| } else { | |
| $url .= $method; | |
| } | |
| $url .= '.json'; | |
| $ch = curl_init(); | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
| curl_setopt($ch, CURLOPT_URL, $url); | |
| $content = curl_exec($ch); | |
| curl_close($ch); | |
| return json_decode($content); | |
| } | |
| private $_attb = array( | |
| 'username' => '', 'apikey' => '' | |
| ); | |
| } | |
| $api = new Axcoto_Envato_Api(array('username' => $username, 'apikey' => $apikey)); | |
| echo "Start to fecth data \n"; | |
| $result = $api->fetch('user', array($username)); | |
| var_dump($result); | |
| if ($result && !empty($result->user->sales)) { | |
| if (file_exists($username . '.sale_count')) { | |
| $currentSales = (int)file_get_contents($username . '.sale_count'); | |
| } else { | |
| $currentSales = 0; | |
| } | |
| if ($currentSales<$result->user->sales) { | |
| echo "Got new sales! Start to send email \n"; | |
| $to = '[email protected]'; | |
| $subject = 'kureikain, u got new sales'; | |
| $message = sprintf('Your old total sales was %d! New total sales is %d', $currentSales, $result->user->sales); | |
| $headers = 'From: [email protected]' . "\r\n" . | |
| 'Reply-To: [email protected]' . "\r\n" . | |
| 'X-Mailer: PHP/' . phpversion(); | |
| mail($to, $subject, $message, $headers); | |
| echo "Email is sent \n"; | |
| } | |
| file_put_contents($username . '.sale_count', $result->user->sales); | |
| } | |
| $username = 'tuanrobo'; | |
| $result = $api->fetch('user', array($username)); | |
| var_dump($result); | |
| if ($result && !empty($result->user->sales)) { | |
| if (file_exists($username . '.sale_count')) { | |
| $currentSales = (int)file_get_contents($username . '.sale_count'); | |
| } else { | |
| $currentSales = 0; | |
| } | |
| if ($currentSales<$result->user->sales) { | |
| echo "Got new sales! Start to send email \n"; | |
| $to = '[email protected]'; | |
| $subject = 'kureikain, u got new sales'; | |
| $message = sprintf('Your old total sales was %d! New total sales is %d', $currentSales, $result->user->sales); | |
| $headers = 'From: [email protected]' . "\r\n" . | |
| 'Reply-To: [email protected]' . "\r\n" . | |
| 'X-Mailer: PHP/' . phpversion(); | |
| mail($to, $subject, $message, $headers); | |
| echo "Email is sent \n"; | |
| } | |
| file_put_contents($username . '.sale_count', $result->user->sales); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment