[med-svn] [python-fitbit] 01/05: Imported Upstream version 0.1.3
Iain Learmonth
irl-guest at moszumanska.debian.org
Sun Feb 8 01:04:53 UTC 2015
This is an automated email from the git hooks/post-receive script.
irl-guest pushed a commit to branch master
in repository python-fitbit.
commit 7010d9443e754f8460f4e50f34d72a3fc24ace81
Author: Iain R. Learmonth <irl at fsfe.org>
Date: Sun Feb 8 00:39:32 2015 +0000
Imported Upstream version 0.1.3
---
CHANGELOG.rst | 54 ++++++++++++++++++++++++++++++++++++++++++++
LICENSE | 2 +-
README.rst | 23 +++++++++++++++++++
docs/conf.py | 6 ++---
fitbit/__init__.py | 6 ++---
fitbit/api.py | 49 +++++++++++++++++++++++++++++++++++++++-
fitbit_tests/test_api.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++++
requirements/dev.txt | 2 +-
8 files changed, 191 insertions(+), 9 deletions(-)
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
new file mode 100644
index 0000000..9724eb7
--- /dev/null
+++ b/CHANGELOG.rst
@@ -0,0 +1,54 @@
+0.1.3 (2015-02-04)
+==================
+
+* Support Intraday Time Series API
+* Use connection pooling to avoid a TCP and SSL handshake for every API call
+
+0.1.2 (2014-09-19)
+==================
+
+* Quick fix for response objects without a status code
+
+0.1.1 (2014-09-18)
+==================
+
+* Fix the broken foods log date endpoint
+* Integrate with travis-ci.org, coveralls.io, and requires.io
+* Add HTTPTooManyRequests exception with retry_after_secs information
+* Enable adding parameters to authorize token URL
+
+0.1.0 (2014-04-15)
+==================
+
+* Officially test/support Python 3.2+ and PyPy in addition to Python 2.x
+* Clean up OAuth workflow, change the API slightly to match oauthlib terminology
+* Fix some minor bugs
+
+0.0.5 (2014-03-30)
+==================
+
+* Switch from python-oauth2 to the better supported oauthlib
+* Add get_bodyweight and get_bodyfat methods
+
+0.0.3 (2014-02-05)
+==================
+
+* Add get_badges method
+* Include error messages in the exception
+* Add API for alarms
+* Add API for log activity
+* Correctly pass headers on requests
+* Way more test coverage
+* Publish to PyPI
+
+0.0.2 (2012-10-02)
+==================
+
+* Add docs, including Readthedocs support
+* Add tests
+* Use official oauth2 version from pypi
+
+0.0.1 (2012-02-25)
+==================
+
+* Initial release
diff --git a/LICENSE b/LICENSE
index 0d95e9a..eb83cdf 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,4 +1,4 @@
-Copyright 2012-2014 ORCAS
+Copyright 2012-2015 ORCAS
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
diff --git a/README.rst b/README.rst
index 0e9d667..ff23090 100644
--- a/README.rst
+++ b/README.rst
@@ -19,3 +19,26 @@ Requirements
============
* Python 2.6+
+* `python-dateutil`_ (always)
+* `requests-oauthlib`_ (always)
+* `Sphinx`_ (to create the documention)
+* `tox`_ (for running the tests)
+* `coverage`_ (to create test coverage reports)
+
+.. _python-dateutil: https://pypi.python.org/pypi/python-dateutil/2.4.0
+.. _requests-oauthlib: https://pypi.python.org/pypi/requests-oauthlib
+.. _Sphinx: https://pypi.python.org/pypi/Sphinx
+.. _tox: https://pypi.python.org/pypi/tox
+.. _coverage: https://pypi.python.org/pypi/coverage/
+
+To use the library, you need to install the run time requirements:
+
+ sudo pip install -r requirements/base.txt
+
+To modify and test the library, you need to install the developer requirements:
+
+ sudo pip install -r requirements/dev.txt
+
+To run the library on a continuous integration server, you need to install the test requirements:
+
+ sudo pip install -r requirements/test.txt
diff --git a/docs/conf.py b/docs/conf.py
index cd95ecc..205c641 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -41,16 +41,16 @@ master_doc = 'index'
# General information about the project.
project = u'Python-Fitbit'
-copyright = u'Copyright 2014 ORCAS'
+copyright = u'Copyright 2012-2015 ORCAS'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
-version = '0.1'
+version = '0.1.3'
# The full version, including alpha/beta/rc tags.
-release = '0.1.0'
+release = '0.1.3'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
diff --git a/fitbit/__init__.py b/fitbit/__init__.py
index f100b8a..9d37ed0 100644
--- a/fitbit/__init__.py
+++ b/fitbit/__init__.py
@@ -3,7 +3,7 @@
Fitbit API Library
------------------
-:copyright: 2012-2014 ORCAS.
+:copyright: 2012-2015 ORCAS.
:license: BSD, see LICENSE for more details.
"""
@@ -14,10 +14,10 @@ from .api import Fitbit, FitbitOauthClient
__title__ = 'fitbit'
__author__ = 'Issac Kelly and ORCAS'
__author_email__ = 'bpitcher at orcasinc.com'
-__copyright__ = 'Copyright 2012-2014 ORCAS'
+__copyright__ = 'Copyright 2012-2015 ORCAS'
__license__ = 'Apache 2.0'
-__version__ = '0.1.2'
+__version__ = '0.1.3'
# Module namespace.
diff --git a/fitbit/api.py b/fitbit/api.py
index 48b72e4..06a83d4 100644
--- a/fitbit/api.py
+++ b/fitbit/api.py
@@ -43,6 +43,7 @@ class FitbitOauthClient(object):
us and read it that way.
"""
+ self.session = requests.Session()
self.client_key = client_key
self.client_secret = client_secret
self.resource_owner_key = resource_owner_key
@@ -61,7 +62,7 @@ class FitbitOauthClient(object):
"""
A simple wrapper around requests.
"""
- return requests.request(method, url, **kwargs)
+ return self.session.request(method, url, **kwargs)
def make_request(self, url, data={}, method=None, **kwargs):
"""
@@ -362,6 +363,52 @@ class Fitbit(object):
)
return self.make_request(url)
+ def intraday_time_series(self, resource, base_date='today', detail_level='1min', start_time=None, end_time=None):
+ """
+ The intraday time series extends the functionality of the regular time series, but returning data at a
+ more granular level for a single day, defaulting to 1 minute intervals. To access this feature, one must
+ send an email to api at fitbit.com and request to have access to the Partner API
+ (see https://wiki.fitbit.com/display/API/Fitbit+Partner+API). For details on the resources available, see:
+
+ https://wiki.fitbit.com/display/API/API-Get-Intraday-Time-Series
+ """
+
+ if start_time and not end_time:
+ raise TypeError("You must provide an end time when you provide a start time")
+
+ if end_time and not start_time:
+ raise TypeError("You must provide a start time when you provide an end time")
+
+ if not isinstance(base_date, str):
+ base_date = base_date.strftime('%Y-%m-%d')
+
+ if not detail_level in ['1min', '15min']:
+ raise ValueError("Period must be either '1min' or '15min'")
+
+ url = "%s/%s/user/-/%s/date/%s/1d/%s" % (
+ self.API_ENDPOINT,
+ self.API_VERSION,
+ resource,
+ base_date,
+ detail_level
+ )
+
+ if start_time:
+ time_init = start_time
+ if not isinstance(time_init, str):
+ time_init = start_time.strftime('%H:%M')
+ url = url + ('/time/%s' % (time_init))
+
+ if end_time:
+ time_fin = end_time
+ if not isinstance(time_fin, str):
+ time_fin = time_fin.strftime('%H:%M')
+ url = url + ('/%s' % (time_fin))
+
+ url = url + '.json'
+
+ return self.make_request(url)
+
def activity_stats(self, user_id=None, qualifier=''):
"""
* https://wiki.fitbit.com/display/API/API-Get-Activity-Stats
diff --git a/fitbit_tests/test_api.py b/fitbit_tests/test_api.py
index 4b93142..bef4aa0 100644
--- a/fitbit_tests/test_api.py
+++ b/fitbit_tests/test_api.py
@@ -257,6 +257,64 @@ class MiscTest(TestBase):
test_timeseries(self.fb, resource, user_id=user_id, base_date=datetime.date(1992,5,12), period=None, end_date=end_date,
expected_url=URLBASE + "/BAR/FOO/date/1992-05-12/1998-12-31.json")
+ def test_intraday_timeseries(self):
+ resource = 'FOO'
+ base_date = '1918-05-11'
+
+ # detail_level must be valid
+ self.assertRaises(
+ ValueError,
+ self.fb.intraday_time_series,
+ resource,
+ base_date,
+ detail_level="xyz",
+ start_time=None,
+ end_time=None)
+
+ # provide end_time if start_time provided
+ self.assertRaises(
+ TypeError,
+ self.fb.intraday_time_series,
+ resource,
+ base_date,
+ detail_level="1min",
+ start_time='12:55',
+ end_time=None)
+
+ # provide start_time if end_time provided
+ self.assertRaises(
+ TypeError,
+ self.fb.intraday_time_series,
+ resource,
+ base_date,
+ detail_level="1min",
+ start_time=None,
+ end_time='12:55')
+
+ def test_intraday_timeseries(fb, resource, base_date, detail_level, start_time, end_time, expected_url):
+ with mock.patch.object(fb, 'make_request') as make_request:
+ retval = fb.intraday_time_series(resource, base_date, detail_level, start_time, end_time)
+ args, kwargs = make_request.call_args
+ self.assertEqual((expected_url,), args)
+
+ # Default
+ test_intraday_timeseries(self.fb, resource, base_date=base_date,
+ detail_level='1min', start_time=None, end_time=None,
+ expected_url=URLBASE + "/-/FOO/date/1918-05-11/1d/1min.json")
+ # start_date can be a date object
+ test_intraday_timeseries(self.fb, resource, base_date=datetime.date(1918, 5, 11),
+ detail_level='1min', start_time=None, end_time=None,
+ expected_url=URLBASE + "/-/FOO/date/1918-05-11/1d/1min.json")
+ # start_time can be a datetime object
+ test_intraday_timeseries(self.fb, resource, base_date=base_date,
+ detail_level='1min', start_time=datetime.time(3,56), end_time='15:07',
+ expected_url=URLBASE + "/-/FOO/date/1918-05-11/1d/1min/time/03:56/15:07.json")
+ # end_time can be a datetime object
+ test_intraday_timeseries(self.fb, resource, base_date=base_date,
+ detail_level='1min', start_time='3:56', end_time=datetime.time(15,7),
+ expected_url=URLBASE + "/-/FOO/date/1918-05-11/1d/1min/time/3:56/15:07.json")
+
+
def test_foods(self):
today = datetime.date.today().strftime('%Y-%m-%d')
self.common_api_test('recent_foods', ("USER_ID",), {}, (URLBASE+"/USER_ID/foods/log/recent.json",), {})
diff --git a/requirements/dev.txt b/requirements/dev.txt
index d586338..491e39f 100644
--- a/requirements/dev.txt
+++ b/requirements/dev.txt
@@ -2,4 +2,4 @@
-r test.txt
Sphinx==1.2.3
-tox==1.7.2
+tox==1.8.1
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/python-fitbit.git
More information about the debian-med-commit
mailing list