/**
  * executes callback for each record from collection, callback param - record
  * @param callable $callback
  * @throws \DreamCommerce\Exception\ResourceException
  */
 public function walk(callable $callback)
 {
     $page = 1;
     do {
         /**
          * @var $objects \ArrayObject
          */
         $objects = $this->resource->page($page)->get();
         foreach ($objects as $o) {
             $callback($o);
         }
         $page++;
     } while ($objects->page < $objects->pages);
 }
 /**
  * {@inheritdoc}
  */
 public function request(Resource $res, $method, $objectPath = null, $data = array(), $query = array())
 {
     $this->authenticate();
     $client = $this->getHttpClient();
     if (!method_exists($client, $method)) {
         throw new Exception('Method not supported', Exception::METHOD_NOT_SUPPORTED);
     }
     $client->setSkipSsl($this->skipSsl);
     $url = $this->entrypoint . '/' . $res->getName();
     if ($objectPath) {
         if (is_array($objectPath)) {
             $objectPath = join('/', $objectPath);
         }
         $url .= '/' . $objectPath;
     }
     $headers = array('Authorization' => 'Bearer ' . $this->getAccessToken(), 'Content-Type' => 'application/json', 'Accept-Language' => $this->getLocale() . ';q=0.8');
     $headers = $this->injectUserAgent($headers);
     try {
         // dispatch correct method
         if (in_array($method, array('get', 'delete', 'head'))) {
             return call_user_func(array($client, $method), $url, $query, $headers);
         } else {
             return call_user_func(array($client, $method), $url, $data, $query, $headers);
         }
     } catch (HttpException $ex) {
         // fire a handler for token reneval
         $previous = $ex->getPrevious();
         if ($previous instanceof HttpException) {
             $response = $previous->getResponse();
             $handler = $this->onTokenInvalidHandler;
             if ($response['error'] == 'unauthorized_client' && $handler) {
                 $exceptionHandled = $handler($this, $ex);
                 if ($exceptionHandled) {
                     return array();
                 }
             }
         }
         throw new Exception('HTTP error: ' . $ex->getMessage(), Exception::API_ERROR, $ex);
     }
 }