/**
  * @param $object
  * @param $options
  * @return Uri
  * @throws Exception
  */
 private function prepareEndpointUri(MessageInterface $object, array $options)
 {
     $endpoint = $object->getEndpoint();
     $defaultParams = $object->getDefaultParams();
     $params = array_key_exists('params', $options) ? $options['params'] : [];
     if (substr($endpoint, 0, 4) !== 'http') {
         $endpoint = $this->apiUri . $endpoint;
     }
     $params = array_merge($params, $defaultParams);
     foreach ($params as $key => $value) {
         $endpoint = str_replace('{' . $key . '}', $value, $endpoint);
     }
     if (preg_match('/.*{.*}.*/', $endpoint)) {
         throw new Exception('Not all endpoint parameters was replaced: ' . $endpoint);
     }
     $uri = new Uri($endpoint);
     if (array_key_exists('paging', $options)) {
         $paging = $options['paging'];
         if (array_key_exists('offset', $paging)) {
             if (!is_numeric($paging['offset']) || $paging['offset'] < 0) {
                 throw new RuntimeException('Paging offset cam be only positive number and 0.');
             }
             $uri = Uri::withQueryValue($uri, 'offset', $paging['offset']);
         }
         if (array_key_exists('count', $paging)) {
             if (!is_numeric($paging['count']) || $paging['count'] < 1) {
                 throw new RuntimeException('Paging count cam be only positive number.');
             }
             $uri = Uri::withQueryValue($uri, 'count', $paging['count']);
         }
     }
     if (array_key_exists('fields', $options)) {
         if (is_array($options['fields'])) {
             $fields = implode(',', $options['fields']);
         } else {
             $fields = $options['fields'];
         }
         $uri = Uri::withQueryValue($uri, 'fields', $fields);
     }
     if (array_key_exists('exclude_fields', $options)) {
         if (array_key_exists('fields', $options)) {
             throw new RuntimeException('You can not use "fields" and "exclude_fields" in one API query.');
         }
         if (is_array($options['exclude_fields'])) {
             $exclude_fields = implode(',', $options['exclude_fields']);
         } else {
             $exclude_fields = $options['exclude_fields'];
         }
         $uri = Uri::withQueryValue($uri, 'exclude_fields', $exclude_fields);
     }
     return $uri;
 }