public function uploadActivity($file)
 {
     $request = new FormRequest(FormRequest::METHOD_POST);
     // Set the request URL
     $url = new Url('https://connect.garmin.com/proxy/upload-service-1.1/json/upload/.fit');
     $url->applyToRequest($request);
     // Set the form fields
     $request->setField('responseContentType', 'text/html');
     $data = new FormUpload($file);
     $data->setContentType('image/x-fits');
     $request->setField('data', $data);
     $response = new Response();
     $this->browser->getClient()->send($request, $response);
     return json_decode($response->getContent(), true);
 }
Ejemplo n.º 2
0
 /**
  * Sends a request.
  *
  * @param string $url     The URL to call
  * @param string $method  The request method to use
  * @param array  $headers An array of request headers
  * @param string $content The request content
  * @param int $cacheLifetime serverside cache lifetime
  *
  * @return MessageInterface The response object
  */
 public function call($url, $method, $headers = array(), $content = '', $cacheLifetime = null)
 {
     if ($this->cacher == null) {
         return parent::call($url, $method, $headers, $content, $cacheLifetime);
     }
     $request = $this->factory->createRequest($method);
     if (!$url instanceof Url) {
         $url = new Url($url);
     }
     $url->applyToRequest($request);
     $request->addHeaders($headers);
     $request->setContent($content);
     $this->data = $this->cacher->retrieveCachedResponse($request);
     if (!$this->data) {
         $this->fromCache = false;
         $this->send($request);
         $this->data = array('request' => parent::getLastRequest(), 'response' => parent::getLastResponse());
         $this->cacher->cacheResponse($this->data['request'], $this->data['response'], $cacheLifetime);
     }
     return $this->data['response'];
 }
Ejemplo n.º 3
0
 /**
  * A convenience method for populating the current request from a URL.
  *
  * @param Url|string $url An URL
  */
 public function fromUrl($url)
 {
     if (!$url instanceof Url) {
         $url = new Url($url);
     }
     $url->applyToRequest($this);
 }
Ejemplo n.º 4
0
 /**
  * Sends a form request.
  *
  * @param string $url     The URL to submit to
  * @param array  $fields  An array of fields
  * @param string $method  The request method to use
  * @param array  $headers An array of request headers
  *
  * @return Response The response object
  */
 public function submit($url, array $fields, $method = RequestInterface::METHOD_POST, $headers = array())
 {
     $request = $this->factory->createFormRequest();
     if (!$url instanceof Url) {
         $url = new Url($url);
     }
     $url->applyToRequest($request);
     $request->addHeaders($headers);
     $request->setMethod($method);
     $request->setFields($fields);
     return $this->send($request);
 }