<?php
public function get_api_data($query, $offset = 0, $update_offset = false){
$url = "http://stark-api.com/api/v1". $query;
$args = array(
'headers' => array(
'Authorization' =>
'Basic ' . base64_encode( $this-> options['username'] . ':' . $this-> options['password'] ),
'Accept' => 'application/json'
)
);
$results = array();
$data = wp_remote_get( $url.$offset, $args );
if(is_wp_error( $data ) ){
}
if( $data['response']['code'] !== 200 ) {
echo 'error '.$data['response']["message"];
}else{
$json = json_decode( $data['body'], true );
}
if( $json['moreResults'] == false && $update_offset){
$this-> set_api_offset(0);
}elseif($update_offset){
$this->inc_api_offset();
}
// LOGGLY
if (isset($_ENV['PANTHEON_ENVIRONMENT'])) {
$environment = $_ENV['PANTHEON_ENVIRONMENT'];
} else {
$environment = 'notpantheon';
}
$log = new Logger('YMCA');
$log->pushHandler(new LogglyHandler('ASDF-SFASFA-SFASDFASF-ASFD/tag/' . $environment, Logger::INFO));
$log_data = array(
'url' => $url,
'query' => $query,
'offset_sent' => $json['offset'],
'offset_start' => $offset,
'offset_end' => $this->get_api_offset(),
'moreResults' => $json['moreResults'],
'numRecords' => count($json['data']),
'data' => $json['data']);
$log->addInfo('get_api_data' , $log_data);
// LOGGLY
return $json['data'];
}