Created
October 1, 2015 14:14
-
-
Save shadda/9095df49cae929b30f0b 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 | |
| error_reporting(E_ALL); | |
| ini_set('display_errors', 1); | |
| $response = [ | |
| 'success' => false, | |
| 'lowest_price' => null, | |
| 'volume' => null, | |
| 'median_price' => null | |
| ]; | |
| if(isset($_GET['item'])) | |
| { | |
| try | |
| { | |
| $q = new PDO('mysql:host=localhost;db=mydb'); | |
| $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | |
| $q = $db->prepare('SELECT * FROM items WHERE name = :name'); | |
| $q->execute([ | |
| 'name' => $_GET['item'] | |
| ]); | |
| if($q->rowCount()) | |
| { | |
| $url = 'https://steamcommunity.com/market/priceoverviewy_/'; | |
| $params = [ | |
| 'currency' => '1', | |
| 'appid' => '730', | |
| 'market_hash_name' => $_GET['item'] | |
| ]; | |
| $headers = [ | |
| 'User-Agent' => 'LBGT IceWwasel/1.0' | |
| ]; | |
| $req = new HTTP\Client\Request('GET', $url, $headers); | |
| $req->addQuery($params); | |
| $cli = new HTTP\Client; | |
| $cli->setOptions(['redirect' => true]); | |
| $cli->enqueue($req)->send(); | |
| $res = $cli->getResponse(); | |
| if($res->getResponseCode() == 200) | |
| { | |
| $result = $res->getBody()->toString(); | |
| $result = (array) json_decode($result); | |
| $response = array_merge($response, $result); | |
| } | |
| } | |
| } | |
| catch(PDOException $e) | |
| { | |
| //deal with db errors | |
| var_dump($e); | |
| } | |
| catch(Exception $e) | |
| { | |
| //deal with any errors | |
| var_dump($e); | |
| } | |
| } | |
| header('Content-Type: text/json'); | |
| echo json_encode($response); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment