Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class SteamAPI {
- const version = '1.0';
- private $ids = '';
- private $api_key;
- private $pre_url = 'https://api.steampowered.com/';
- ###################
- # GENERAL METHODS #
- ###################
- private function add_steam_id($steamid){
- if(count($this->ids) == 0){
- $this->ids .= $steamid;
- } else {
- $this->ids .= ',' . $steamid;
- }
- }
- public function set_api_key($api_key){
- $this->api_key = $api_key;
- }
- private function get_content($uri){
- try{
- $content = file_get_contents($uri);
- $content = json_decode($content, true);
- return $content;
- } catch(Exception $e){
- echo $e->getMessage();
- }
- }
- private function array_steamids($steamids){
- return explode(',', $steamids);
- }
- ###############
- # API METHODS #
- ###############
- public function GetGamePrice($appid, $currency=[]){
- $country_codes = array(
- 'ae', 'au', 'br', 'cn', 'dk', 'es', 'gb', 'hr', 'ie', 'ir', 'jp', 'lt', 'ly', 'mx', 'no', 'ph', 'pt', 'rs', 'se', 'sk', 'tw', 'ar',
- 'be', 'ca', 'cz', 'dz', 'fi', 'gr', 'hu', 'il', 'is', 'kr', 'lu', 'mk', 'my', 'nz', 'pk', 're', 'ru', 'sg', 'th', 'ua', 'za', 'at',
- 'bg', 'cl', 'de', 'ee', 'fr', 'hk', 'id', 'in', 'it', 'kz', 'lv', 'mo', 'nl', 'pe', 'pl', 'ro', 'sa', 'si', 'tr', 'us', 'by'
- );
- $array_countries = [];
- if(!empty($currency) && is_array($currency)){
- $array_countries = $currency;
- } else {
- $array_countries = $country_codes;
- }
- $prices = [];
- foreach ($array_countries as $code) {
- $url = 'http://store.steampowered.com/api/appdetails?appids=' . $appid . '&filters=price_overview&cc=' . $code;
- $handler = $this->get_content($url);
- if($handler[$appid]['success']){
- foreach ($handler[$appid]['data'] as $h) {
- $price = [];
- $price['appid'] = $appid;
- $price['currency'] = $h['currency'];
- $price['initial'] = $h['initial'];
- $price['final'] = $h['final'];
- $price['discount_percent'] = $h['discount_percent'];
- array_push($prices, $price);
- }
- }
- }
- return $prices;
- }
- }
- $file = "prices.json";
- $steam_id = '57690';
- $api_key = 'BE66BE20E6C1C22C563A4DE0BCE08AAD';
- $steamAPI = new SteamAPI($steam_id, $api_key);
- $handler = $steamAPI->GetGamePrice($steam_id, array('pl', 'us'));
- header('Content-type:application/json;charset=utf-8');
- echo json_encode($handler);
- file_put_contents($file, json_encode($handler));
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement