From 463dea826de601ed027db98b43062e32be1f9ffb Mon Sep 17 00:00:00 2001 From: jsamos Date: Mon, 16 Dec 2013 17:16:39 -0500 Subject: [PATCH 01/18] myname --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 71f8378..5730634 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "popthestack/fitbit", + "name": "jsamos/fitbit", "version": "0.6", "type": "library", "description": "Fitbit library with OAuth. This library is maintained.", From f357c5320bfd5d025ad79ecf619def89ddb29f76 Mon Sep 17 00:00:00 2001 From: jsamos Date: Mon, 16 Dec 2013 17:24:20 -0500 Subject: [PATCH 02/18] back to original name --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5730634..71f8378 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "jsamos/fitbit", + "name": "popthestack/fitbit", "version": "0.6", "type": "library", "description": "Fitbit library with OAuth. This library is maintained.", From fc97f3ddd1e91bfaec08c516d7db5dc0a465cebd Mon Sep 17 00:00:00 2001 From: jsamos Date: Mon, 16 Dec 2013 17:24:59 -0500 Subject: [PATCH 03/18] Author --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 71f8378..6996577 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ "license" : "Apache-2.0", "authors": [ { - "name": "Ryan Martinsen", + "name": ["Ryan Martinsen","Juni Samos"], "email": "ryan@ryanware.com", "homepage": "http://ryanmartinsen.com" }, From 109ba3e25164e1804c70f2ec022ba460c0eb780c Mon Sep 17 00:00:00 2001 From: Juni Samos Date: Mon, 16 Dec 2013 19:14:43 -0500 Subject: [PATCH 04/18] add time series method --- lib/Fitbit/EndpointGateway.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/Fitbit/EndpointGateway.php b/lib/Fitbit/EndpointGateway.php index cd27a49..e48d440 100644 --- a/lib/Fitbit/EndpointGateway.php +++ b/lib/Fitbit/EndpointGateway.php @@ -99,6 +99,30 @@ private function parseResponse($response) return $response; } + /** + * Get user foods for specific date + * + * @throws Exception + * @param \DateTime|string $baseDate + * @param string $period + * @param \DateTime|string $endDate + * @return mixed SimpleXMLElement or the value encoded in json as an object + */ + public function getSeries($path, $baseDate = null, $period = null, $endDate = null) + { + $baseDate = $baseDate ?: 'today'; + $end = ($period) ? $period : ($endDate) ?: '1d'; + + if ($baseDate instanceof Datetime) + $baseDate = $baseDate->format("Y-m-d"); + + if ($end instanceof Datetime) + $end = $end->format("Y-m-d"); + + $endpoint = sprintf('user/%s/%s/%s/%s', $this->userID, $path, $baseDate, $end); + return $this->makeApiRequest($endpoint); + } + /** * Get CLIENT+VIEWER and CLIENT rate limiting quota status * From 2b9469462ba4938f1c9ba70ffc5ce40fac1379b7 Mon Sep 17 00:00:00 2001 From: Juni Samos Date: Mon, 16 Dec 2013 19:15:04 -0500 Subject: [PATCH 05/18] add food time series --- lib/Fitbit/FoodGateway.php | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/lib/Fitbit/FoodGateway.php b/lib/Fitbit/FoodGateway.php index 8bf537f..1e71494 100644 --- a/lib/Fitbit/FoodGateway.php +++ b/lib/Fitbit/FoodGateway.php @@ -1,6 +1,7 @@ makeApiRequest('user/' . $this->userID . '/foods/log/date/' . $dateStr); } + /** + * Get user foods for specific date + * + * {@inheritdoc} + */ + public function getSeries($path, $baseDate = null, $period = null, $endDate = null) + { + $path = sprintf('foods/log/%s/date', $path); + return parent::getSeries($path, $baseDate, $period, $endDate); + } + + /** + * Get user calories in for a timespan + * + * @throws Exception + * @param \DateTime|string $baseDate + * @param string $period + * @param \DateTime|string $endDate + * @return mixed SimpleXMLElement or the value encoded in json as an object + */ + public function getCaloriesIn($baseDate = null, $period = null, $endDate = null) + { + return $this->getSeries('caloriesIn', $baseDate, $period, $endDate); + } + + /** + * Get user water in for a timespan + * + * @throws Exception + * @param \DateTime|string $baseDate + * @param string $period + * @param \DateTime|string $endDate + * @return mixed SimpleXMLElement or the value encoded in json as an object + */ + public function getWater($baseDate = null, $period = null, $endDate = null) + { + return $this->getSeries('water', $baseDate, $period, $endDate); + } + /** * Get user recent foods * From 5050ac1e3119170592da56067f5d63f7171164af Mon Sep 17 00:00:00 2001 From: Juni Samos Date: Mon, 16 Dec 2013 20:18:30 -0500 Subject: [PATCH 06/18] activities time series --- lib/Fitbit/ActivityTimeSeriesGateway.php | 33 ++++++++++++++++++++++++ lib/Fitbit/ApiGatewayFactory.php | 7 +++++ 2 files changed, 40 insertions(+) create mode 100644 lib/Fitbit/ActivityTimeSeriesGateway.php diff --git a/lib/Fitbit/ActivityTimeSeriesGateway.php b/lib/Fitbit/ActivityTimeSeriesGateway.php new file mode 100644 index 0000000..dc4db11 --- /dev/null +++ b/lib/Fitbit/ActivityTimeSeriesGateway.php @@ -0,0 +1,33 @@ +getSeries($path, $baseDate, $period, $endDate); + } + + +} diff --git a/lib/Fitbit/ApiGatewayFactory.php b/lib/Fitbit/ApiGatewayFactory.php index 7ac2078..6f43dfe 100644 --- a/lib/Fitbit/ApiGatewayFactory.php +++ b/lib/Fitbit/ApiGatewayFactory.php @@ -167,6 +167,13 @@ public function getActivityGateway() return $gateway; } + public function getActivityTimeSeriesGateway() + { + $gateway = new ActivityTimeSeriesGateway; + $this->injectGatewayDependencies($gateway); + return $gateway; + } + public function getBodyGateway() { $gateway = new BodyGateway; From d2ed337d049a930879cb6a472e014fde4db97d34 Mon Sep 17 00:00:00 2001 From: Juni Samos Date: Tue, 17 Dec 2013 09:13:40 -0500 Subject: [PATCH 07/18] base time series class --- lib/Fitbit/ActivityTimeSeriesGateway.php | 2 +- lib/Fitbit/TimeSeriesEndpointGateway.php | 44 ++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 lib/Fitbit/TimeSeriesEndpointGateway.php diff --git a/lib/Fitbit/ActivityTimeSeriesGateway.php b/lib/Fitbit/ActivityTimeSeriesGateway.php index dc4db11..1b89273 100644 --- a/lib/Fitbit/ActivityTimeSeriesGateway.php +++ b/lib/Fitbit/ActivityTimeSeriesGateway.php @@ -2,7 +2,7 @@ namespace Fitbit; -class ActivityTimeSeriesGateway extends EndpointGateway { +class ActivityTimeSeriesGateway extends TimeSeriesEndpointGateway { /** * Dynamically pass methods to the default connection. diff --git a/lib/Fitbit/TimeSeriesEndpointGateway.php b/lib/Fitbit/TimeSeriesEndpointGateway.php new file mode 100644 index 0000000..32750b0 --- /dev/null +++ b/lib/Fitbit/TimeSeriesEndpointGateway.php @@ -0,0 +1,44 @@ +format("Y-m-d"); + + if ($end instanceof Datetime) + $end = $end->format("Y-m-d"); + + $endpoint = sprintf('user/%s/%s/%s/%s', $this->userID, $path, $baseDate, $end); + var_dump($endpoint); + return $this->makeApiRequest($endpoint); + } + +} From b050d073e1f20796068d1c0edae757d682ae1a0b Mon Sep 17 00:00:00 2001 From: Juni Samos Date: Tue, 17 Dec 2013 09:14:34 -0500 Subject: [PATCH 08/18] move food series to its own gateway --- lib/Fitbit/ApiGatewayFactory.php | 7 +++ lib/Fitbit/EndpointGateway.php | 24 --------- lib/Fitbit/FoodGateway.php | 39 --------------- lib/Fitbit/FoodTimeSeriesGateway.php | 73 ++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 63 deletions(-) create mode 100644 lib/Fitbit/FoodTimeSeriesGateway.php diff --git a/lib/Fitbit/ApiGatewayFactory.php b/lib/Fitbit/ApiGatewayFactory.php index 6f43dfe..e16ff69 100644 --- a/lib/Fitbit/ApiGatewayFactory.php +++ b/lib/Fitbit/ApiGatewayFactory.php @@ -188,6 +188,13 @@ public function getFoodGateway() return $gateway; } + public function getFoodTimeSeriesGateway() + { + $gateway = new FoodTimeSeriesGateway; + $this->injectGatewayDependencies($gateway); + return $gateway; + } + public function getSleepGateway() { $gateway = new SleepGateway; diff --git a/lib/Fitbit/EndpointGateway.php b/lib/Fitbit/EndpointGateway.php index e48d440..cd27a49 100644 --- a/lib/Fitbit/EndpointGateway.php +++ b/lib/Fitbit/EndpointGateway.php @@ -99,30 +99,6 @@ private function parseResponse($response) return $response; } - /** - * Get user foods for specific date - * - * @throws Exception - * @param \DateTime|string $baseDate - * @param string $period - * @param \DateTime|string $endDate - * @return mixed SimpleXMLElement or the value encoded in json as an object - */ - public function getSeries($path, $baseDate = null, $period = null, $endDate = null) - { - $baseDate = $baseDate ?: 'today'; - $end = ($period) ? $period : ($endDate) ?: '1d'; - - if ($baseDate instanceof Datetime) - $baseDate = $baseDate->format("Y-m-d"); - - if ($end instanceof Datetime) - $end = $end->format("Y-m-d"); - - $endpoint = sprintf('user/%s/%s/%s/%s', $this->userID, $path, $baseDate, $end); - return $this->makeApiRequest($endpoint); - } - /** * Get CLIENT+VIEWER and CLIENT rate limiting quota status * diff --git a/lib/Fitbit/FoodGateway.php b/lib/Fitbit/FoodGateway.php index 1e71494..6ec6a18 100644 --- a/lib/Fitbit/FoodGateway.php +++ b/lib/Fitbit/FoodGateway.php @@ -22,45 +22,6 @@ public function getFoods($date, $dateStr = null) return $this->makeApiRequest('user/' . $this->userID . '/foods/log/date/' . $dateStr); } - /** - * Get user foods for specific date - * - * {@inheritdoc} - */ - public function getSeries($path, $baseDate = null, $period = null, $endDate = null) - { - $path = sprintf('foods/log/%s/date', $path); - return parent::getSeries($path, $baseDate, $period, $endDate); - } - - /** - * Get user calories in for a timespan - * - * @throws Exception - * @param \DateTime|string $baseDate - * @param string $period - * @param \DateTime|string $endDate - * @return mixed SimpleXMLElement or the value encoded in json as an object - */ - public function getCaloriesIn($baseDate = null, $period = null, $endDate = null) - { - return $this->getSeries('caloriesIn', $baseDate, $period, $endDate); - } - - /** - * Get user water in for a timespan - * - * @throws Exception - * @param \DateTime|string $baseDate - * @param string $period - * @param \DateTime|string $endDate - * @return mixed SimpleXMLElement or the value encoded in json as an object - */ - public function getWater($baseDate = null, $period = null, $endDate = null) - { - return $this->getSeries('water', $baseDate, $period, $endDate); - } - /** * Get user recent foods * diff --git a/lib/Fitbit/FoodTimeSeriesGateway.php b/lib/Fitbit/FoodTimeSeriesGateway.php new file mode 100644 index 0000000..512c1ca --- /dev/null +++ b/lib/Fitbit/FoodTimeSeriesGateway.php @@ -0,0 +1,73 @@ +fragment($method); + array_unshift($parameters, $fragment); + return call_user_func_array(array($this, 'get'), $parameters); + } + + public function get($resrourceFragment, $baseDate = null, $period = null, $endDate = null) + { + $path = sprintf('foods/log/%s/date', $resrourceFragment); + return $this->getSeries($path, $baseDate, $period, $endDate); + } + + /** + * Get user foods for specific date + * + * {@inheritdoc} + */ + /* + public function getSeries($path, $baseDate = null, $period = null, $endDate = null) + { + $path = sprintf('foods/log/%s/date', $path); + return parent::getSeries($path, $baseDate, $period, $endDate); + } + */ + + /** + * Get user calories in for a timespan + * + * @throws Exception + * @param \DateTime|string $baseDate + * @param string $period + * @param \DateTime|string $endDate + * @return mixed SimpleXMLElement or the value encoded in json as an object + */ + /* + public function getCaloriesIn($baseDate = null, $period = null, $endDate = null) + { + return $this->getSeries('caloriesIn', $baseDate, $period, $endDate); + } + */ + + /** + * Get user water in for a timespan + * + * @throws Exception + * @param \DateTime|string $baseDate + * @param string $period + * @param \DateTime|string $endDate + * @return mixed SimpleXMLElement or the value encoded in json as an object + */ + /* + public function getWater($baseDate = null, $period = null, $endDate = null) + { + return $this->getSeries('water', $baseDate, $period, $endDate); + } + */ + + +} From 20318cc9aca8f6277460fbc18d5714f4ab61d2e1 Mon Sep 17 00:00:00 2001 From: Juni Samos Date: Tue, 17 Dec 2013 09:17:31 -0500 Subject: [PATCH 09/18] clean up and comment --- lib/Fitbit/FoodTimeSeriesGateway.php | 48 ++++------------------------ 1 file changed, 6 insertions(+), 42 deletions(-) diff --git a/lib/Fitbit/FoodTimeSeriesGateway.php b/lib/Fitbit/FoodTimeSeriesGateway.php index 512c1ca..f47ed1d 100644 --- a/lib/Fitbit/FoodTimeSeriesGateway.php +++ b/lib/Fitbit/FoodTimeSeriesGateway.php @@ -18,56 +18,20 @@ public function __call($method, $parameters) return call_user_func_array(array($this, 'get'), $parameters); } - public function get($resrourceFragment, $baseDate = null, $period = null, $endDate = null) - { - $path = sprintf('foods/log/%s/date', $resrourceFragment); - return $this->getSeries($path, $baseDate, $period, $endDate); - } - - /** - * Get user foods for specific date - * - * {@inheritdoc} - */ - /* - public function getSeries($path, $baseDate = null, $period = null, $endDate = null) - { - $path = sprintf('foods/log/%s/date', $path); - return parent::getSeries($path, $baseDate, $period, $endDate); - } - */ - /** - * Get user calories in for a timespan + * generic get method for time series calls * * @throws Exception + * @param string $fragment * @param \DateTime|string $baseDate * @param string $period * @param \DateTime|string $endDate * @return mixed SimpleXMLElement or the value encoded in json as an object */ - /* - public function getCaloriesIn($baseDate = null, $period = null, $endDate = null) - { - return $this->getSeries('caloriesIn', $baseDate, $period, $endDate); - } - */ - - /** - * Get user water in for a timespan - * - * @throws Exception - * @param \DateTime|string $baseDate - * @param string $period - * @param \DateTime|string $endDate - * @return mixed SimpleXMLElement or the value encoded in json as an object - */ - /* - public function getWater($baseDate = null, $period = null, $endDate = null) - { - return $this->getSeries('water', $baseDate, $period, $endDate); + public function get($fragment, $baseDate = null, $period = null, $endDate = null) + { + $path = sprintf('foods/log/%s/date', $fragment); + return $this->getSeries($path, $baseDate, $period, $endDate); } - */ - } From 4867cff60ac19539b326d355912edc84779d2806 Mon Sep 17 00:00:00 2001 From: Juni Samos Date: Tue, 17 Dec 2013 10:16:35 -0500 Subject: [PATCH 10/18] move __call and get to base time series class --- lib/Fitbit/ActivityTimeSeriesGateway.php | 48 ++++++++++++++++-------- lib/Fitbit/FoodTimeSeriesGateway.php | 30 ++------------- lib/Fitbit/TimeSeriesEndpointGateway.php | 44 ++++++++++++++++------ 3 files changed, 69 insertions(+), 53 deletions(-) diff --git a/lib/Fitbit/ActivityTimeSeriesGateway.php b/lib/Fitbit/ActivityTimeSeriesGateway.php index 1b89273..6004ed0 100644 --- a/lib/Fitbit/ActivityTimeSeriesGateway.php +++ b/lib/Fitbit/ActivityTimeSeriesGateway.php @@ -5,28 +5,44 @@ class ActivityTimeSeriesGateway extends TimeSeriesEndpointGateway { /** - * Dynamically pass methods to the default connection. + * base fragment for this resources uri + * + * @var sting + */ + protected static $format = 'activities/%s/date'; + + protected function trackerOnlyFragment($fragment) + { + return str_replace('activities', 'activities/tracker', $fragment); + } + + /** + * extended get to all for tracker only resource calls * - * @param string $method - * @param array $parameters - * @return mixed + * @throws Exception + * @param string $fragment + * @param bool $tracker + * @param \DateTime|string $baseDate + * @param string $period + * @param \DateTime|string $endDate + * @return mixed SimpleXMLElement or the value encoded in json as an object */ - public function __call($method, $parameters) + public function get($fragment, $tracker = false, $baseDate = null, $period = null, $endDate = null) { - $method = str_replace('get','', $method); - $method = strtolower($method[0]) . substr($method, 1); - array_unshift($parameters, $method); - - if (in_array($method, array('caloriesBMR'))) $parameters[1] = false; - - return call_user_func_array(array($this, 'get'), $parameters); + $fragment = ($tracker) ? $this->trackerOnlyFragment($fragment) : $fragment; + return parent::get($fragment, $baseDate, $period, $endDate); } - public function get($resrourceFragment, $tracker = false, $baseDate = null, $period = null, $endDate = null) + /** + * extended call, to ensure methods without tracker + * have tracker set to false + * + * {@inheritdoc} + */ + public function __call($method, $parameters) { - $resrourceFragment = ($tracker) ? 'tracker/' . $resrourceFragment : $resrourceFragment; - $path = sprintf('activities/%s/date', $resrourceFragment); - return $this->getSeries($path, $baseDate, $period, $endDate); + if (in_array($method, array('getCaloriesBMR'))) $parameters[0] = false; + return parent::__call($method, $parameters); } diff --git a/lib/Fitbit/FoodTimeSeriesGateway.php b/lib/Fitbit/FoodTimeSeriesGateway.php index f47ed1d..883679d 100644 --- a/lib/Fitbit/FoodTimeSeriesGateway.php +++ b/lib/Fitbit/FoodTimeSeriesGateway.php @@ -4,34 +4,12 @@ class FoodTimeSeriesGateway extends TimeSeriesEndpointGateway { - /** - * Dynamically pass methods to the default connection. - * - * @param string $method - * @param array $parameters - * @return mixed - */ - public function __call($method, $parameters) - { - $fragment = $this->fragment($method); - array_unshift($parameters, $fragment); - return call_user_func_array(array($this, 'get'), $parameters); - } /** - * generic get method for time series calls - * - * @throws Exception - * @param string $fragment - * @param \DateTime|string $baseDate - * @param string $period - * @param \DateTime|string $endDate - * @return mixed SimpleXMLElement or the value encoded in json as an object + * base fragment for this resources uri + * + * @var sting */ - public function get($fragment, $baseDate = null, $period = null, $endDate = null) - { - $path = sprintf('foods/log/%s/date', $fragment); - return $this->getSeries($path, $baseDate, $period, $endDate); - } + protected static $format = 'foods/log/%s/date'; } diff --git a/lib/Fitbit/TimeSeriesEndpointGateway.php b/lib/Fitbit/TimeSeriesEndpointGateway.php index 32750b0..fbb2c96 100644 --- a/lib/Fitbit/TimeSeriesEndpointGateway.php +++ b/lib/Fitbit/TimeSeriesEndpointGateway.php @@ -5,6 +5,13 @@ class TimeSeriesEndpointGateway extends EndpointGateway { + /** + * base fragment for the instantiated resource uri + * + * @var sting + */ + protected static $format; + /** * create a uri fragment from a method name * @@ -13,32 +20,47 @@ class TimeSeriesEndpointGateway extends EndpointGateway { public function fragment($method) { $method = substr($method, 3); - return strtolower($method[0]) . substr($method, 1); + $fragment = strtolower($method[0]) . substr($method, 1); + return sprintf(static::$format, $fragment); } /** - * Get user foods for specific date + * Get user time series * * @throws Exception + * @param string $fragment * @param \DateTime|string $baseDate * @param string $period * @param \DateTime|string $endDate * @return mixed SimpleXMLElement or the value encoded in json as an object */ - public function getSeries($path, $baseDate = null, $period = null, $endDate = null) + public function get($fragment, $baseDate = null, $period = null, $endDate = null) { - $baseDate = $baseDate ?: 'today'; - $end = ($period) ? $period : ($endDate) ?: '1d'; + $date1 = $baseDate ?: 'today'; + $date2 = ($period) ? $period : ($endDate) ?: '1d'; - if ($baseDate instanceof Datetime) - $baseDate = $baseDate->format("Y-m-d"); + if ($date1 instanceof Datetime) + $date1 = $date1->format("Y-m-d"); - if ($end instanceof Datetime) - $end = $end->format("Y-m-d"); + if ($date2 instanceof Datetime) + $date2 = $date2->format("Y-m-d"); - $endpoint = sprintf('user/%s/%s/%s/%s', $this->userID, $path, $baseDate, $end); - var_dump($endpoint); + $endpoint = sprintf('user/%s/%s/%s/%s', $this->userID, $fragment, $date1, $date2); return $this->makeApiRequest($endpoint); } + /** + * Dynamically pass methods to get. + * + * @param string $method + * @param array $parameters + * @return mixed + */ + public function __call($method, $parameters) + { + $fragment = $this->fragment($method); + array_unshift($parameters, $fragment); + return call_user_func_array(array($this, 'get'), $parameters); + } + } From d72fe43bd03aac8c932fe8d701a230ba819fef49 Mon Sep 17 00:00:00 2001 From: Juni Samos Date: Tue, 17 Dec 2013 10:16:52 -0500 Subject: [PATCH 11/18] body and sleep time series --- lib/Fitbit/ApiGatewayFactory.php | 14 ++++++++++++++ lib/Fitbit/BodyTimeSeriesGateway.php | 15 +++++++++++++++ lib/Fitbit/SleepTimeSeriesGateway.php | 15 +++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 lib/Fitbit/BodyTimeSeriesGateway.php create mode 100644 lib/Fitbit/SleepTimeSeriesGateway.php diff --git a/lib/Fitbit/ApiGatewayFactory.php b/lib/Fitbit/ApiGatewayFactory.php index e16ff69..105b9b9 100644 --- a/lib/Fitbit/ApiGatewayFactory.php +++ b/lib/Fitbit/ApiGatewayFactory.php @@ -181,6 +181,13 @@ public function getBodyGateway() return $gateway; } + public function getBodyTimeSeriesGateway() + { + $gateway = new BodyTimeSeriesGateway; + $this->injectGatewayDependencies($gateway); + return $gateway; + } + public function getFoodGateway() { $gateway = new FoodGateway; @@ -202,6 +209,13 @@ public function getSleepGateway() return $gateway; } + public function getSleepTimeSeriesGateway() + { + $gateway = new SleepTimeSeriesGateway; + $this->injectGatewayDependencies($gateway); + return $gateway; + } + public function getTimeGateway() { $gateway = new TimeGateway; diff --git a/lib/Fitbit/BodyTimeSeriesGateway.php b/lib/Fitbit/BodyTimeSeriesGateway.php new file mode 100644 index 0000000..faee522 --- /dev/null +++ b/lib/Fitbit/BodyTimeSeriesGateway.php @@ -0,0 +1,15 @@ + Date: Tue, 17 Dec 2013 10:18:11 -0500 Subject: [PATCH 12/18] document --- lib/Fitbit/ActivityTimeSeriesGateway.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/Fitbit/ActivityTimeSeriesGateway.php b/lib/Fitbit/ActivityTimeSeriesGateway.php index 6004ed0..4fc4ecd 100644 --- a/lib/Fitbit/ActivityTimeSeriesGateway.php +++ b/lib/Fitbit/ActivityTimeSeriesGateway.php @@ -11,6 +11,12 @@ class ActivityTimeSeriesGateway extends TimeSeriesEndpointGateway { */ protected static $format = 'activities/%s/date'; + /** + * convert to trcker only fragment + * + * @param string $fragment + * @return string + */ protected function trackerOnlyFragment($fragment) { return str_replace('activities', 'activities/tracker', $fragment); From 43b75fd67b3365d7b0af750f2076541450df7e91 Mon Sep 17 00:00:00 2001 From: Juni Samos Date: Tue, 17 Dec 2013 10:42:55 -0500 Subject: [PATCH 13/18] update readme --- README.md | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/README.md b/README.md index 8d9ac50..a5a0376 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,48 @@ print_r($foods); echo ''; ``` +## Time Series Data ## + +Time series data can be colected as described [http://wiki.fitbit.com/display/API/API-Get-Time-Series](http://wiki.fitbit.com/display/API/API-Get-Time-Series) + +The base class, TimeSeriesGateway uses the magic __call method to map methods calls to resource endpoints. The method name is converted to the last segment of the URI, the rest of the path is handled by the class. + +```php +$sleep_time_series_gateway = $factory->getTimeSeriesGateway(); +$minutes_asleep = $sleep_time_series_gateway->getMinutesAsleep(); +``` + +A method call with parameters will default to a time series of today/1d. A period, baseDate and endDate can be passeed to specify the time series. *Note: Period will override endDate. + +```php +//past seven days +$minutes_asleep = $sleep_time_series_gateway->getMinutesAsleep('today','7d'); + +//seven days before the new year (*Note you can also pass Datetime objects for baseDate and endDate) +$minutes_asleep = $sleep_time_series_gateway->getMinutesAsleep('2014-01-01','7d'); + +//first week of new year +$minutes_asleep = $sleep_time_series_gateway->getMinutesAsleep('2014-01-01', null, '2014-01-07'); +``` + +The Activities Time Series Resource allows you to limit the data collected to that logged only by the tracker. To do so pass true|false (default false) as the first argument in activites timeseries calls + +```php +$activities_time_series_gateway = $factory->getActivitiesSeriesGateway(); +//get the minutes of very active activity from the tracker only for the previous 7 days +$tracker_minutes_very_active = $activities_time_series_gateway->getMinutesVeryActive(true, 'today', '7d'); +``` +*Note: the activities/caloriesBMR resource does not appear to have a corresponding activities/tracker/caloriesBMR. The tracker parameter for getCaloriesBMR(true) will automatically be set to false. + + ## Notes ## * By default, all requests assume you want data for the authorized user (viewer). There are, however, several endpoints you can use to access the data of other Fitbit users, given that you have permission to access their data. This is accomplished by setting the Fitbit User ID with the `setUserID` method available on `ApiGatewayFactory` and the Endpoint Gateways (e.g. `UserGateway`, `FoodGateway`). * *Subscriptions*: this library has some basic methods to add/delete subscriptions, but it's your responsibility to track the list and maintain server endpoints to receive notifications from Fitbit, as well as register them at [http://dev.fitbit.com](http://dev.fitbit.com). See [Subscriptions API](https://wiki.fitbit.com/display/API/Fitbit+Subscriptions+API) for more information. + + ## Known Issues ## + +At the time of writing, the following resources do not currently work, or are documented incorrectly by Fitbit's documentation. + +activities/floors +activities/elevation From 297fd5b07d63512d1457f85ccb0613d7f224b955 Mon Sep 17 00:00:00 2001 From: Juni Samos Date: Tue, 17 Dec 2013 10:46:20 -0500 Subject: [PATCH 14/18] fix typos in readme --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a5a0376..91c8879 100644 --- a/README.md +++ b/README.md @@ -88,14 +88,14 @@ echo ''; Time series data can be colected as described [http://wiki.fitbit.com/display/API/API-Get-Time-Series](http://wiki.fitbit.com/display/API/API-Get-Time-Series) -The base class, TimeSeriesGateway uses the magic __call method to map methods calls to resource endpoints. The method name is converted to the last segment of the URI, the rest of the path is handled by the class. +The base class, TimeSeriesGateway, uses the magic __call method to map methods calls to resource endpoints. The method name is converted to the last segment of the URI, the rest of the path is handled by the class. ```php $sleep_time_series_gateway = $factory->getTimeSeriesGateway(); $minutes_asleep = $sleep_time_series_gateway->getMinutesAsleep(); ``` -A method call with parameters will default to a time series of today/1d. A period, baseDate and endDate can be passeed to specify the time series. *Note: Period will override endDate. +A method call without parameters will default to a time series of today/1d. A period, baseDate and endDate can be passed to specify the time series. *Note: period will override endDate. ```php //past seven days @@ -127,5 +127,5 @@ $tracker_minutes_very_active = $activities_time_series_gateway->getMinutesVeryAc At the time of writing, the following resources do not currently work, or are documented incorrectly by Fitbit's documentation. -activities/floors -activities/elevation +*activities/floors +*activities/elevation From b1a3ec7fe229b5cddc6503febeacf9d4c9767c99 Mon Sep 17 00:00:00 2001 From: Juni Samos Date: Tue, 17 Dec 2013 10:46:46 -0500 Subject: [PATCH 15/18] format list --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 91c8879..bf8fb7a 100644 --- a/README.md +++ b/README.md @@ -127,5 +127,5 @@ $tracker_minutes_very_active = $activities_time_series_gateway->getMinutesVeryAc At the time of writing, the following resources do not currently work, or are documented incorrectly by Fitbit's documentation. -*activities/floors -*activities/elevation +* activities/floors +* activities/elevation From d613a90a4e2ee58baae9d888d1a1062df59955dc Mon Sep 17 00:00:00 2001 From: Juni Samos Date: Tue, 17 Dec 2013 11:26:08 -0500 Subject: [PATCH 16/18] remove use Datetime --- lib/Fitbit/FoodGateway.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Fitbit/FoodGateway.php b/lib/Fitbit/FoodGateway.php index 6ec6a18..8bf537f 100644 --- a/lib/Fitbit/FoodGateway.php +++ b/lib/Fitbit/FoodGateway.php @@ -1,7 +1,6 @@ Date: Tue, 17 Dec 2013 11:29:33 -0500 Subject: [PATCH 17/18] use Datetime --- lib/Fitbit/TimeSeriesEndpointGateway.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Fitbit/TimeSeriesEndpointGateway.php b/lib/Fitbit/TimeSeriesEndpointGateway.php index fbb2c96..f785c0a 100644 --- a/lib/Fitbit/TimeSeriesEndpointGateway.php +++ b/lib/Fitbit/TimeSeriesEndpointGateway.php @@ -1,6 +1,7 @@ Date: Wed, 9 Apr 2014 12:10:47 -0700 Subject: [PATCH 18/18] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6996577..7037f94 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ ], "require": { "php": ">=5.3.0", - "lusitanian/oauth": "~0.2" + "lusitanian/oauth": "0.2.5" }, "autoload": { "psr-0": {