basis-band 0.1.1 → 0.2.0
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 +13 -0
- data/bin/basis-band +6 -4
- data/lib/basis-band.rb +59 -28
- data/lib/basis-band/api-fetch.rb +2 -2
- data/lib/basis-band/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
|
@@ -84,3 +84,16 @@ If you want the activity info for a given day pass in the access token using
|
|
|
84
84
|
},
|
|
85
85
|
...
|
|
86
86
|
```
|
|
87
|
+
|
|
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.
|
data/bin/basis-band
CHANGED
|
@@ -16,9 +16,11 @@ end
|
|
|
16
16
|
|
|
17
17
|
options = {}
|
|
18
18
|
options_file = File.expand_path('.basis-band', ENV['HOME'])
|
|
19
|
-
puts "Looking for options #{options_file}"
|
|
20
19
|
if File.exist?(options_file)
|
|
21
|
-
|
|
20
|
+
o = YAML::load_file options_file
|
|
21
|
+
if not o.nil?
|
|
22
|
+
options = YAML::load_file options_file
|
|
23
|
+
end
|
|
22
24
|
end
|
|
23
25
|
|
|
24
26
|
OptionParser.new do |opts|
|
|
@@ -70,9 +72,9 @@ if options[:summary]
|
|
|
70
72
|
end
|
|
71
73
|
|
|
72
74
|
if options[:userid] and options[:date]
|
|
73
|
-
raw = b.
|
|
75
|
+
raw = b.metrics_for_day(options[:date])
|
|
74
76
|
elsif options[:token] and options[:date]
|
|
75
|
-
raw = b.
|
|
77
|
+
raw = b.activities_for_day(options[:token], options[:date])
|
|
76
78
|
else
|
|
77
79
|
raw = $stdin.read
|
|
78
80
|
end
|
data/lib/basis-band.rb
CHANGED
|
@@ -14,34 +14,58 @@ class BasisBand
|
|
|
14
14
|
@cache_dir = dir
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
def
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
end
|
|
22
|
-
r
|
|
17
|
+
def metrics_for_day(date)
|
|
18
|
+
with_cache(metrics_cache_filename(date)) { |filename|
|
|
19
|
+
fetch_metrics_value(date, filename)
|
|
20
|
+
}
|
|
23
21
|
end
|
|
24
22
|
|
|
25
|
-
def
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
def activities_for_day(token, date)
|
|
24
|
+
with_cache(activities_cache_filename(date)) { |filename|
|
|
25
|
+
fetch_activities_value(token, date, filename)
|
|
26
|
+
}
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def metrics_cache_filename(date)
|
|
30
|
+
File.join(@cache_dir, date + "_metrics.json")
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def activities_cache_filename(date)
|
|
34
|
+
File.join(@cache_dir, date + "_activities.json")
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def metrics_cache_files()
|
|
38
|
+
Dir[File.join(@cache_dir, "*_metrics.json")]
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def activities_cache_files()
|
|
42
|
+
Dir[File.join(@cache_dir, "*_activities.json")]
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def metrics_for_all
|
|
46
|
+
metrics = metrics_cache_files.collect { |f|
|
|
47
|
+
date = File.basename(f, "_metrics.json")
|
|
48
|
+
[d, cached_value(f)]
|
|
49
|
+
}
|
|
50
|
+
Hash[metrics]
|
|
31
51
|
end
|
|
32
52
|
|
|
33
|
-
def
|
|
34
|
-
|
|
53
|
+
def activities_for_all
|
|
54
|
+
activities = activities_cache_files.collect { |f|
|
|
55
|
+
date = File.basename(f, "_activities.json")
|
|
56
|
+
[d, cached_value(f)]
|
|
57
|
+
}
|
|
58
|
+
Hash[activities]
|
|
35
59
|
end
|
|
36
60
|
|
|
37
|
-
def
|
|
38
|
-
|
|
61
|
+
def with_cache(filename)
|
|
62
|
+
cached_value(filename) || yield(filename)
|
|
39
63
|
end
|
|
40
64
|
|
|
41
|
-
def
|
|
65
|
+
def cached_value(filename)
|
|
42
66
|
raw = nil
|
|
43
67
|
begin
|
|
44
|
-
File.open(
|
|
68
|
+
File.open(filename, "r") { |f|
|
|
45
69
|
raw = f.read
|
|
46
70
|
}
|
|
47
71
|
rescue
|
|
@@ -50,20 +74,27 @@ class BasisBand
|
|
|
50
74
|
raw
|
|
51
75
|
end
|
|
52
76
|
|
|
53
|
-
def
|
|
77
|
+
def fetch_result_w_cache(filename)
|
|
54
78
|
f = ApiFetch.new()
|
|
55
|
-
|
|
56
|
-
if
|
|
57
|
-
File.open(
|
|
58
|
-
f.write(
|
|
79
|
+
r = yield f
|
|
80
|
+
if r
|
|
81
|
+
File.open(filename, "w") { |f|
|
|
82
|
+
f.write(r)
|
|
59
83
|
}
|
|
60
84
|
end
|
|
61
|
-
|
|
85
|
+
r
|
|
62
86
|
end
|
|
63
87
|
|
|
64
|
-
def
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
88
|
+
def fetch_metrics_value(date, filename)
|
|
89
|
+
fetch_result_w_cache(filename) { |fetch|
|
|
90
|
+
fetch.get_day_metrics(@userid, date)
|
|
91
|
+
}
|
|
68
92
|
end
|
|
93
|
+
|
|
94
|
+
def fetch_activities_value(token, date, filename)
|
|
95
|
+
fetch_result_w_cache(filename) { |fetch|
|
|
96
|
+
fetch.get_day_activities(token, date)
|
|
97
|
+
}
|
|
98
|
+
end
|
|
99
|
+
|
|
69
100
|
end
|
data/lib/basis-band/api-fetch.rb
CHANGED
|
@@ -54,12 +54,12 @@ class ApiFetch
|
|
|
54
54
|
http.request(request).body
|
|
55
55
|
end
|
|
56
56
|
|
|
57
|
-
def
|
|
57
|
+
def get_day_metrics(userid, date, summary = true, body_states = true, skip_metrics = [])
|
|
58
58
|
res = https_fetch(url(userid, date, summary, body_states, skip_metrics))
|
|
59
59
|
res
|
|
60
60
|
end
|
|
61
61
|
|
|
62
|
-
def
|
|
62
|
+
def get_day_activities(token, date)
|
|
63
63
|
res = https_fetch_v2(activities_url(date), token)
|
|
64
64
|
res
|
|
65
65
|
end
|
data/lib/basis-band/version.rb
CHANGED
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.
|
|
4
|
+
version: 0.2.0
|
|
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-
|
|
12
|
+
date: 2013-11-08 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: json
|