Example #1
0
 /**
  * Return Link metrics from the (free) Mozscape (f.k.a. Seomoz) API.
  *
  * @access        public
  * @param   cols  string     The bit flags you want returned.
  * @param   url   string     The URL to get metrics for.
  */
 public static function getCols($cols, $url = false)
 {
     if ('' == Config\ApiKeys::MOZSCAPE_ACCESS_ID || '' == Config\ApiKeys::MOZSCAPE_SECRET_KEY) {
         throw new E('In order to use the Mozscape API, you must obtain
             and set an API key first (see SEOstats\\Config\\ApiKeys.php).');
         exit(0);
     }
     $expires = time() + 300;
     $apiEndpoint = sprintf(Config\Services::MOZSCAPE_API_URL, urlencode(Helper\Url::parseHost(parent::getUrl($url))), $cols, Config\ApiKeys::MOZSCAPE_ACCESS_ID, $expires, urlencode(self::_getUrlSafeSignature($expires)));
     $ret = parent::_getPage($apiEndpoint);
     return !$ret || empty($ret) || '{}' == (string) $ret ? parent::noDataDefaultValue() : Helper\Json::decode($ret, true);
 }
Example #2
0
 public static function getPagespeedAnalysis($url = false, $strategy = 'desktop')
 {
     if ('' == Config\ApiKeys::GOOGLE_SIMPLE_API_ACCESS_KEY) {
         throw new E('In order to use the PageSpeed API, you must obtain
             and set an API key first (see SEOstats\\Config\\ApiKeys.php).');
         exit(0);
     }
     $url = parent::getUrl($url);
     $url = sprintf(Config\Services::GOOGLE_PAGESPEED_URL, $url, $strategy, Config\ApiKeys::GOOGLE_SIMPLE_API_ACCESS_KEY);
     $ret = static::_getPage($url);
     return Helper\Json::decode($ret);
 }
Example #3
0
 public static function getApiCredits()
 {
     self::guardApiKey();
     $dataUrl = sprintf(Config\Services::SISTRIX_API_CREDITS_URL, Config\ApiKeys::SISTRIX_API_ACCESS_KEY);
     $json = static::_getPage($dataUrl);
     if (empty($json)) {
         return parent::noDataDefaultValue();
     }
     $json_decoded = Helper\Json::decode($json, true);
     if (!isset($json_decoded['answer'][0]['credits'][0]['value'])) {
         return parent::noDataDefaultValue();
     }
     return $json_decoded['answer'][0]['credits'][0]['value'];
 }
Example #4
0
 /**
  *
  * @dataProvider providerTestEncode
  */
 public function testEncode($var, $assert)
 {
     $result = Json::encode($var);
     $this->assertEquals($assert, $result);
 }
Example #5
0
 /**
  * Returns the total count of URL shares via StumpleUpon
  *
  * @access        public
  * @param   url   string     The URL to check.
  * @return        integer    Returns the total count of URL shares.
  */
 public static function getStumbleUponShares($url = false)
 {
     $url = parent::getUrl($url);
     $dataUrl = sprintf(Config\Services::STUMBLEUPON_INFO_URL, urlencode($url));
     $jsonData = parent::_getPage($dataUrl);
     $phpArray = Helper\Json::decode($jsonData, true);
     return isset($phpArray['result']['in_index']) && true == $phpArray['result']['in_index'] ? intval($phpArray['result']['views']) : parent::noDataDefaultValue();
 }
Example #6
0
 private static function getApiData($url)
 {
     $json = parent::_getPage($url);
     return Helper\Json::decode($json, true);
 }
Example #7
0
 protected static function getApiData($url)
 {
     $json = static::_getPage($url);
     return Helper\Json::decode($json, true);
 }