/**
  * Getting the saved Google data
  *
  * @return array
  */
 protected function get_google_data()
 {
     $response = Yoast_GA_Dashboards_Data::get($this->graph_type);
     if (array_key_exists('body', $response['value'])) {
         $return = $response['value']['body'];
     } else {
         $return = $response;
     }
     return $this->filter_google_data($return);
 }
 /**
  * Set some test data
  */
 public function test_set_AND_get_data()
 {
     $dataobject = array('object' => array('test' => 'Value!'));
     $type = 'phpunit_test_values';
     $start_date = strtotime('-7 days');
     $end_date = time();
     $store_as = 'table';
     // Set the data object
     $set = Yoast_GA_Dashboards_Data::set($type, $dataobject, $start_date, $end_date, $store_as);
     $this->assertTrue($set);
     // Get the data object
     $result = Yoast_GA_Dashboards_Data::get($type);
     $expected = array('store_as' => $store_as, 'type' => $type, 'start_date' => $start_date, 'end_date' => $end_date, 'value' => $dataobject);
     $this->assertEquals($result, $expected);
 }
 /**
  * Handle the response from the Google Analytics api.
  *
  * @param array|boolean $response
  * @param string        $metric
  * @param array         $dimensions
  * @param string        $start_date
  * @param string        $end_date
  * @param string        $store_as
  * @param string        $storage_name
  *
  * @return bool
  */
 private function handle_response($response, $metric, $dimensions, $start_date, $end_date, $store_as = 'table', $storage_name = 'auto')
 {
     if (is_array($response)) {
         // Success, store this data
         $filter_metrics = $this->get_filter_metrics();
         $extracted = str_replace('ga:', '', str_replace('ga:date,', '', $dimensions));
         if (isset($filter_metrics[$extracted])) {
             $name = $extracted;
         } else {
             $name = $metric;
         }
         if ($dimensions !== 'ga:date' && !isset($filter_metrics[$extracted])) {
             $name = str_replace('ga:date,', '', $dimensions);
         }
         // Overwrite the name if we have a defined one
         if ($storage_name != 'auto') {
             $name = $storage_name;
         }
         return Yoast_GA_Dashboards_Data::set($name, $response, strtotime($start_date), strtotime($end_date), $store_as);
     } else {
         // Failure on API call try to log it
         $this->log_error(print_r($response, true));
         return false;
     }
 }
 /**
  * Reset all dashboards data by removing the options of the registered dashboards
  *
  * @return bool
  */
 public function reset_dashboards_data()
 {
     if (!$this->dashboards_disabled) {
         $dashboards = $this->get_default_dashboards();
         if (is_array($dashboards) && count($dashboards) >= 1) {
             foreach ($dashboards as $name => $board) {
                 Yoast_GA_Dashboards_Data::reset($name);
             }
             // Make sure we fetch new data if we enable the dashboards by updating the last_run option
             update_option('yst_ga_last_wp_run', date('Y-m-d', strtotime('-2 days')));
             return true;
         }
     }
     return false;
 }