/** * Test dumping a workout to a TCX string. */ public function testDumpToStringMultiActivity() { $workout = new Workout(); $workout->addTrack(new Track(array($this->getTrackPoint('53.551075', '9.993672', '2014-05-30T17:12:58+00:00', 11, null, 78), $this->getTrackPoint('53.550085', '9.992682', '2014-05-30T17:12:59+00:00', 10, 128, 88)), SportMapperInterface::RUNNING)); $workout->addTrack(new Track(array($this->getTrackPoint('53.549075', '9.991672', '2014-05-30T17:13:00+00:00', 9, 258, 98), $this->getTrackPoint('53.548085', '9.990682', '2014-05-30T17:13:01+00:00', 8, 456, 108)), SportMapperInterface::SWIMMING)); $tcx = new TCX(); $actual = $tcx->dumpToString($workout); $this->assertXmlStringEqualsXmlFile(__DIR__ . '/Expected/testDumpToStringMultiActivity.tcx', $actual); }
/** * Post a workout to endomondo. * * Each track of a workout is uploaded individually. * * @param Workout $workout The workout to post. * @return string Status message. * @throws \RuntimeException If there is a problem with the upload. */ public function postWorkout(Workout $workout) { $tcx = new TCXDumper(); $workoutFile = new PostFile('file', $tcx->dumpToString($workout), uniqid('SportTrackerConnectorWorkout_')); try { $response = $this->httpClient->post(self::STRAVA_URL_WORKOUT_POST, ['body' => ['data_type' => 'tcx', 'file' => $workoutFile]]); $responseData = $response->json(); if ($response->getStatusCode() !== 201 || $responseData['error'] !== null) { throw new RuntimeException('Strava returned error message: ' . $responseData['error'] . ' Status: ' . $responseData['status']); } return $responseData['status']; } catch (ClientException $e) { $response = $e->getResponse()->json(); $errorMessage = 'Could not upload workout to strava.com.'; if (isset($response['status'])) { $errorMessage .= ' ' . $response['status'] . ' Error: ' . $response['error']; } throw new RuntimeException($errorMessage, null, $e); } }