function gsAPI($key = null, $secret = null)
 {
     if (!empty($key)) {
         self::$ws_key = $key;
     }
     if (!empty($secret)) {
         self::$ws_secret = $secret;
     }
     if (empty(self::$ws_key) || empty(self::$ws_secret)) {
         trigger_error("gsapi class requires a valid key and secret.", E_USER_ERROR);
     }
     if (!isset(self::$instance)) {
         self::$instance = $this;
     }
     self::$headers = array();
 }
Beispiel #2
0
 public static function addClientIP($ip = null)
 {
     if (empty($ip)) {
         $ip = $_SERVER['REMOTE_ADDR'];
     }
     if (empty(self::$headers)) {
         self::$headers = array("X-Client-IP: " . $ip);
     } else {
         $newHeaders = array();
         foreach (self::$headers as $header) {
             if (strpos($header, 'X-Client-IP:') !== 0) {
                 $newHeaders[] = $header;
             }
         }
         $newHeaders[] = "X-Client-IP: " . $ip;
         self::$headers = $newHeaders;
     }
 }
Beispiel #3
0
<?php

session_start();
// Make sure to validate and cleanse this and stuff.
$songID = $_POST['song'];
// Load up API wrapper
require "gsAPI.php";
$gsapi = new gsAPI('API-USERNAME', 'API-KEY');
gsAPI::$headers = array("X-Client-IP: " . $_SERVER['REMOTE_ADDR']);
// Session caching stuff
if (isset($_SESSION['gsSession']) && !empty($_SESSION['gsSession'])) {
    $gsapi->setSession($_SESSION['gsSession']);
} else {
    $_SESSION['gsSession'] = $gsapi->startSession();
}
if (!$_SESSION['gsSession']) {
    die("noSession");
}
if (isset($_SESSION['gsCountry']) && !empty($_SESSION['gsCountry'])) {
    $gsapi->setCountry($_SESSION['gsCountry']);
} else {
    $_SESSION['gsCountry'] = $gsapi->getCountry();
}
if (!$_SESSION['gsCountry']) {
    die("noCountry");
}
// Make request to Grooveshark and return data as JSON
$streamInfo = $gsapi->getStreamKeyStreamServer($songID, false);
echo json_encode($streamInfo);