Exemplo n.º 1
0
 /**
  * Construct
  * @param string $apiKey API Key Anda sebagaimana yang tercantum di akun panel RajaOngkir
  * @param string[] $additionalHeaders Header tambahan seperti android-key, ios-key, dll
  */
 public function __construct($apiKey, $additionalHeaders = [])
 {
     self::$apiKey = $apiKey;
     $this->rest = new RESTClient();
     $this->rest->initialize(array('server' => self::$host));
     $this->rest->set_header('Content-Type', 'application/x-www-form-urlencoded');
     $this->rest->set_header('key', self::$apiKey);
     foreach ($additionalHeaders as $key => $value) {
         $this->restrest->set_header($key, $value);
     }
 }
Exemplo n.º 2
0
 /**
  * Get Google Analytics page views rest API status
  * @param string $url make sure the url is not absolute. it just path url
  *                    based on your hostname.
  * @return integer
  */
 public static function viewsURLInAnalytics($url)
 {
     $rest = new RESTClient();
     $rest->initialize(array('server' => 'https://content.googleapis.com/analytics/v3/data/'));
     $rest->set_header('Content-type', 'application/json');
     $rest->option('RETURNTRANSFER', true);
     $rest->option(CURLOPT_SSL_VERIFYPEER, false);
     $rest->option(CURLOPT_SSL_VERIFYHOST, false);
     $response = $rest->get('ga', ['ids' => 'ga:94751193', 'dimensions' => 'ga:pagePath', 'metrics' => 'ga:pageviews', 'filters' => "ga:pagePath=={$url}", 'start-date' => '2014-11-01', 'end-date' => date('Y-m-d'), 'access_token' => 'ya29.4AD5ChEwzkLc8TBe3pmlKERuXJtQlcttN7WB_Bao95UeUxLeslkFjFoDIJkHAlvmeWTUU6r1pj71YQ', 'max-results' => '50', '_src' => 'explorer']);
     $json = CJSON::decode($response);
     return $json['totalsForAllResults']['ga:pageviews'];
 }