public function testClientOptions()
 {
     $shariff = new Backend(array("domain" => 'www.heise.de', "cache" => array("ttl" => 1), "services" => $this->services, "client" => array("timeout" => 0.005, "connect_timeout" => 0.005)));
     $counts = $shariff->get('http://www.heise.de');
     // expect no response in 5 ms
     $this->assertCount(0, $counts);
 }
Ejemplo n.º 2
0
 public function testClientOptions()
 {
     $this->markTestSkipped("Some APIs are too fast for this. We need mock APIs.");
     $shariff = new Backend(array("domain" => 'www.heise.de', "cache" => array("ttl" => 1), "services" => $this->services, "client" => array("timeout" => 0.005, "connect_timeout" => 0.005)));
     $counts = $shariff->get('http://www.heise.de');
     // expect no response in 5 ms
     $this->assertCount(0, $counts);
 }
 /**
  * Get the information from the backend for the given url
  *
  * @param $url
  * @return array
  */
 public function get($url)
 {
     $backend = new Backend($this->config->toArray());
     try {
         return $backend->get($url);
     } catch (GuzzleException $e) {
         return '{}';
     }
 }
Ejemplo n.º 4
0
 public static function run()
 {
     header('Content-type: application/json');
     if (!isset($_GET["url"])) {
         echo json_encode(null);
         return;
     }
     $reader = new Json();
     $shariff = new Backend($reader->fromFile('shariff.json'));
     echo json_encode($shariff->get($_GET["url"]));
 }
 public function listenAction()
 {
     header('Content-type: application/json');
     $url = $this->getParam('url');
     if (empty($url)) {
         echo json_encode(null);
         return;
     }
     $configFile = \Pimcore\Config::locateConfigFile("shariff.php");
     if (is_file($configFile)) {
         $confArray = (include $configFile);
     } else {
         $reader = new Json();
         $confArray = $reader->fromFile(PIMCORE_PLUGINS_PATH . '/Shariff/config/shariff.json');
     }
     $shariff = new Backend($confArray);
     echo json_encode($shariff->get($url));
     exit;
 }
Ejemplo n.º 6
0
// if we do not have a tmp-dir, we use the content dir of WP
if (empty($tmp["cache"]["cacheDir"])) {
    $upload_dir = wp_upload_dir('/');
    $cache_dir = $upload_dir['basedir'] . '/shariff3uu_cache';
    // if it doesn't exit, try to create it
    if (!file_exists($cache_dir)) {
        wp_mkdir_p($cache_dir);
    }
    $tmp["cache"]["cacheDir"] = $cache_dir;
}
// final check that temp dir is usuable
if (!is_writable($tmp["cache"]["cacheDir"])) {
    die("No usable tmp dir found. Please check " . $tmp["cache"]["cacheDir"]);
}
// use proxy if set in wp_config.php
if (defined('WP_PROXY_HOST') && defined('WP_PROXY_PORT')) {
    $proxy = WP_PROXY_HOST . ':' . WP_PROXY_PORT;
    $tmp["client"]["proxy"] = $proxy;
}
// start backend
$shariff = new Backend($tmp);
// draw results, if we have some
$share_counts = $shariff->get($_GET["url"]);
if (isset($share_counts) && $share_counts != null) {
    echo json_encode($share_counts);
} else {
    // it's actually just a guess, but very likely
    echo 'Invalid URL (e.g. wrong domain)! ';
    // in case we have some usefull information, but most likley will be "null"
    echo 'Message: ' . json_encode($share_counts);
}