Skip to content

Instantly share code, notes, and snippets.

@ghisprince
Created August 14, 2014 04:03
Show Gist options
  • Save ghisprince/eb4ccc75c0ca520754c5 to your computer and use it in GitHub Desktop.
Save ghisprince/eb4ccc75c0ca520754c5 to your computer and use it in GitHub Desktop.
how to return streams
### CURRENT
# Result is a enum of streams in any order. To get a particular stream you loop through them,
# and ask for it's type. A particular requested stream is not returned if it's not
# on the activity (need to code defensively).
streams = client.get_activity_streams(123, types=types, resolution='medium')
heartrate_stream = None
for s in streams:
if s.type == 'heartrate':
heartrate_stream = s
break
if heartrate_stream is not None:
# do something
max(heartrate_stream.data)
### PROPOSED
# Instead of an enum, the get_activity_streams could return a dictionary type object.
# Put the type as the dict's key name.
streams = client.get_activity_streams(123, types=types, resolution='medium')
if 'heartrate' in streams.keys():
# do something
max(streams['heartrate'].data)
@hozn
Copy link

hozn commented Aug 14, 2014

Yeah, that seems like a useful improvement. I wonder if we should keep an option (e.g. optional param) for the current implementation -- or perhaps make a get_activity_stream_dict that returns a dict instead of a list. In the end, though, I think modifying the current function as long as api docs are updated to reflect new return type/structure, should be just fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment