basis-band 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -6,51 +6,56 @@ Includes a command line tool that can be used to either capture the raw JSON
6
6
  responses from app.mybasis.com, or to convert the metrics from the API
7
7
  responses into CSV.
8
8
 
9
- ## Usage
9
+ ## Authentication
10
10
 
11
11
  There are two different versions of the API available at app.mybasis.com. The
12
12
  V1 API (which holds most of the detailed data about heartrate and steps) uses a
13
13
  user id, while the V2 API (which holds information about activities like
14
- walking, running or biking state) uses an access token. You can use the -l
15
- option to the command line tool to dump out both values.
16
- Just pass the username and password joined with a colon (:).
14
+ walking, running or biking state) uses an access token. The basis-band-login
15
+ command takes a username and password and spits out both identifiers.
17
16
  Assuming your username is
18
17
  'mikerowehl@gmail.com' and your password is 'pppppp' the command would look
19
18
  like this:
20
19
 
21
20
  ```
22
- > miker $ basis-band -l mikerowehl@gmail.com:pppppp
21
+ > miker $ basis-band-login -e mikerowehl@gmail.com -p pppppp
23
22
  ID for V1 api: 1234567890abcdef12345678
24
23
  token for V2 api: abcdef1234567890abcdef1234567890
25
24
  ```
26
25
 
27
26
  In this example the userid returned is '1234567890abcdef12345678' and the
28
- token is 'abcdef1234567890abcdef1234567890'.
29
-
30
- If you pass -u and -d options the raw text will be fetched from the API and
31
- output on standard output:
27
+ token is 'abcdef1234567890abcdef1234567890'. The userid lives for a long time,
28
+ but the token needs to be refreshed each session. If you want to store the
29
+ userid you can add it to a ~/.basis-band file, to avoid entering it on the
30
+ command line every time. Just create a file like this as ~/.basis-band:
32
31
 
33
32
  ```
34
- > miker $ basis-band -u 1234567890abcdef12345678 -d 2013-10-14
35
- {"metrics":{"skin_temp":{"min":77.0,"max":95.0,"sum":113642.0,"summary":{"max_skin_temp_per_minute":null...
33
+ ---
34
+ :userid: '1234567890abcdef12345678'
36
35
  ```
37
36
 
38
- If you want the metric data as CSV instead of raw JSON:
37
+ ## Data Retrieval
38
+
39
+ The main basis-band command requires the name of a cache directory to use.
40
+ You can either pass it on the command line using --cachedir, or add it to the
41
+ ~/basis-band initialization file. The cache directory must exist before
42
+ running the commands.
43
+
44
+ The default is to fetch metrics for a given day (expressed in YYYY-MM-DD
45
+ format). Assuming you have userid and cachedir setup in your config file the
46
+ commands look like below.
47
+
48
+ To fetch metrics for a given day:
39
49
 
40
50
  ```
41
- > miker $ basis-band -u 1234567890abcdef12345678 -d 2013-10-14 -c
42
- t,state,skin_temp,heartrate,air_temp,calories,gsr,steps
43
- 2013/10/01 00:00:00,inactive,83.8,58,80.6,1.3,0.000439,0
44
- 2013/10/01 00:01:00,inactive,83.8,62,80.6,1.4,0.000402,0
45
- 2013/10/01 00:02:00,inactive,83.8,64,80.6,1.4,0.000464,0
46
- ...
51
+ > miker $ basis-band -d 2013-10-14
52
+ {"metrics":{"skin_temp":{"min":77.0,"max":95.0,"sum":113642.0,"summary":{"max_skin_temp_per_minute":null...
47
53
  ```
48
54
 
49
- If you already have the JSON in a local file, you can pass it in on standard
50
- input and transform it to CSV:
55
+ If you want the metric data as CSV instead of raw JSON:
51
56
 
52
57
  ```
53
- > miker $ basis-band -c < cache/2013-10-14.json
58
+ > miker $ basis-band -d 2013-10-14 -c
54
59
  t,state,skin_temp,heartrate,air_temp,calories,gsr,steps
55
60
  2013/10/01 00:00:00,inactive,83.8,58,80.6,1.3,0.000439,0
56
61
  2013/10/01 00:01:00,inactive,83.8,62,80.6,1.4,0.000402,0
@@ -59,10 +64,10 @@ t,state,skin_temp,heartrate,air_temp,calories,gsr,steps
59
64
  ```
60
65
 
61
66
  If you want the activity info for a given day pass in the access token using
62
- -t and the date you want with -d:
67
+ -t and set --type to 'activities'
63
68
 
64
69
  ```
65
- > miker $ basis-band -t abcdef1234567890abcdef1234567890 -d 2013-11-05 | python -mjson.tool
70
+ > miker $ basis-band -t abcdef1234567890abcdef1234567890 -d 2013-11-05 -T activities | python -mjson.tool
66
71
  {
67
72
  "content": {
68
73
  "activities": [
@@ -85,15 +90,3 @@ If you want the activity info for a given day pass in the access token using
85
90
  ...
86
91
  ```
87
92
 
88
- ## Optional
89
-
90
- The command line tool parses the ~/.basis-band file as YAML to pick up
91
- persistent options. So if you want to avoid having to keep passing the userid
92
- on the command line you can just add it to the options file:
93
-
94
- ```
95
- ---
96
- :userid: '1234567890abcdef12345678'
97
- ```
98
-
99
- And that value will be used as if you passed a -u to the command.
@@ -51,11 +51,18 @@ end.parse!
51
51
  b = BasisBand.new(options[:cachedir])
52
52
 
53
53
  if options[:summary]
54
- all = b.data_for_all
54
+ all = b.metrics_for_all
55
+ puts "date,air_temp,calories,gsr,heartrate,skin_temp,steps"
55
56
  all.each do |k,v|
56
- puts "Data for day #{k}"
57
+ line = [k]
57
58
  t = ApiResponseModel.new(v).summary
58
- puts " average air_temp = #{t["air_temp"]["avg"]}"
59
+ line << t['air_temp']['avg']
60
+ line << t['calories']['avg']
61
+ line << t['gsr']['avg']
62
+ line << t['heartrate']['avg']
63
+ line << t['skin_temp']['avg']
64
+ line << t['steps']['avg']
65
+ puts line.join(',')
59
66
  end
60
67
  exit
61
68
  end
@@ -44,7 +44,7 @@ class BasisBand
44
44
  def metrics_for_all
45
45
  metrics = metrics_cache_files.collect { |f|
46
46
  date = File.basename(f, "_metrics.json")
47
- [d, cached_value(f)]
47
+ [date, cached_value(f)]
48
48
  }
49
49
  Hash[metrics]
50
50
  end
@@ -1,3 +1,3 @@
1
1
  module BasisBandMeta
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: basis-band
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-09 00:00:00.000000000 Z
12
+ date: 2013-11-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json