basis-band 0.2.0 → 0.3.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.
@@ -14,12 +14,12 @@ def samples_to_csv(samples)
14
14
  lines
15
15
  end
16
16
 
17
- options = {}
17
+ options = {:type => 'metrics'}
18
18
  options_file = File.expand_path('.basis-band', ENV['HOME'])
19
19
  if File.exist?(options_file)
20
20
  o = YAML::load_file options_file
21
21
  if not o.nil?
22
- options = YAML::load_file options_file
22
+ options.merge!(o)
23
23
  end
24
24
  end
25
25
 
@@ -37,29 +37,18 @@ OptionParser.new do |opts|
37
37
  opts.on("-C", "--cachedir DIR", "Directory to use to cache results") do |c|
38
38
  options[:cachedir] = c
39
39
  end
40
- opts.on("-l", "--login username:password", "Login and print user id") do |l|
41
- options[:login] = l
42
- end
43
40
  opts.on("-s", "--summary", "Summarize all the data from the cache") do |s|
44
41
  options[:summary] = s
45
42
  end
46
43
  opts.on("-t", "--token TOKEN", "Token for v2 API access") do |t|
47
44
  options[:token] = t
48
45
  end
46
+ opts.on("-T", "--type TYPE", "'metrics' or 'activities' (default 'metrics')") do |t|
47
+ options[:type] = t
48
+ end
49
49
  end.parse!
50
50
 
51
- if options[:login]
52
- (u,p) = options[:login].split(":", 2)
53
- token, id = ApiAuth.new.login(u, p)
54
- puts "ID for V1 api: #{id}"
55
- puts "token for V2 api: #{token}"
56
- exit
57
- end
58
-
59
- b = BasisBand.new(options[:userid])
60
- if options[:cachedir]
61
- b.set_cache_dir(options[:cachedir])
62
- end
51
+ b = BasisBand.new(options[:cachedir])
63
52
 
64
53
  if options[:summary]
65
54
  all = b.data_for_all
@@ -71,9 +60,9 @@ if options[:summary]
71
60
  exit
72
61
  end
73
62
 
74
- if options[:userid] and options[:date]
75
- raw = b.metrics_for_day(options[:date])
76
- elsif options[:token] and options[:date]
63
+ if options[:type] == 'metrics'
64
+ raw = b.metrics_for_day(options[:userid], options[:date])
65
+ elsif options[:type] == 'activities'
77
66
  raw = b.activities_for_day(options[:token], options[:date])
78
67
  else
79
68
  raw = $stdin.read
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'basis-band'
4
+ require 'optparse'
5
+
6
+ options = {}
7
+
8
+ OptionParser.new do |opts|
9
+ opts.banner = "basis-band gem v#{BasisBandMeta::VERSION}\nUsage: basis-band-login [options]"
10
+ opts.on("-e", "--email EMAIL", "Mandatory login for mybasis.com") do |e|
11
+ options[:email] = e
12
+ end
13
+ opts.on("-p", "--password PASS", "Mandatory password for mybasis.com") do |p|
14
+ options[:password] = p
15
+ end
16
+ end.parse!
17
+
18
+ token, id = ApiAuth.new.login(options[:email], options[:password])
19
+ puts "ID for V1 api: #{id}"
20
+ puts "token for V2 api: #{token}"
21
+
@@ -6,17 +6,16 @@ require 'basis-band/api-response-model'
6
6
  class BasisBand
7
7
  @cache_dir = nil
8
8
 
9
- def initialize(userid)
10
- @userid = userid
11
- end
9
+ attr_accessor :api
12
10
 
13
- def set_cache_dir(dir)
14
- @cache_dir = dir
11
+ def initialize(cache_dir)
12
+ @cache_dir = cache_dir
13
+ @api = ApiFetch.new()
15
14
  end
16
15
 
17
- def metrics_for_day(date)
16
+ def metrics_for_day(userid, date)
18
17
  with_cache(metrics_cache_filename(date)) { |filename|
19
- fetch_metrics_value(date, filename)
18
+ fetch_metrics_value(userid, date, filename)
20
19
  }
21
20
  end
22
21
 
@@ -75,8 +74,7 @@ class BasisBand
75
74
  end
76
75
 
77
76
  def fetch_result_w_cache(filename)
78
- f = ApiFetch.new()
79
- r = yield f
77
+ r = yield
80
78
  if r
81
79
  File.open(filename, "w") { |f|
82
80
  f.write(r)
@@ -85,15 +83,15 @@ class BasisBand
85
83
  r
86
84
  end
87
85
 
88
- def fetch_metrics_value(date, filename)
89
- fetch_result_w_cache(filename) { |fetch|
90
- fetch.get_day_metrics(@userid, date)
86
+ def fetch_metrics_value(userid, date, filename)
87
+ fetch_result_w_cache(filename) {
88
+ @api.get_day_metrics(userid, date)
91
89
  }
92
90
  end
93
91
 
94
92
  def fetch_activities_value(token, date, filename)
95
- fetch_result_w_cache(filename) { |fetch|
96
- fetch.get_day_activities(token, date)
93
+ fetch_result_w_cache(filename) {
94
+ @api.get_day_activities(token, date)
97
95
  }
98
96
  end
99
97
 
@@ -1,3 +1,3 @@
1
1
  module BasisBandMeta
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
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.2.0
4
+ version: 0.3.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-08 00:00:00.000000000 Z
12
+ date: 2013-11-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -32,6 +32,7 @@ description: A library and collection of tools for exporting monitoring data fro
32
32
  email: mikerowehl@gmail.com
33
33
  executables:
34
34
  - basis-band
35
+ - basis-band-login
35
36
  extensions: []
36
37
  extra_rdoc_files: []
37
38
  files:
@@ -41,6 +42,7 @@ files:
41
42
  - lib/basis-band/version.rb
42
43
  - lib/basis-band.rb
43
44
  - bin/basis-band
45
+ - bin/basis-band-login
44
46
  - README.md
45
47
  - test/test_api-fetch.rb
46
48
  - test/test_api-response-model.rb