basis-band 0.0.1 → 0.0.2
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 +31 -16
- data/bin/basis-band +10 -0
- data/lib/basis-band.rb +1 -0
- data/lib/basis-band/api-auth.rb +38 -0
- data/lib/basis-band/version.rb +1 -1
- metadata +2 -1
data/README.md
CHANGED
|
@@ -1,30 +1,40 @@
|
|
|
1
1
|
# Basis API Access Gem
|
|
2
2
|
|
|
3
|
-
This is extremely alpha quality, based on the existing PHP example at
|
|
4
|
-
[https://github.com/btroia/basis-data-export](https://github.com/btroia/basis-data-export).
|
|
5
|
-
That example includes instructions for finding your userid.
|
|
6
|
-
|
|
7
3
|
Includes a command line tool that can be used to either capture the raw JSON
|
|
8
4
|
responses from app.mybasis.com, or to convert the metrics from the API
|
|
9
|
-
responses into CSV.
|
|
10
|
-
|
|
5
|
+
responses into CSV.
|
|
6
|
+
|
|
7
|
+
First off you need to find your userid. The command line tool now provides an
|
|
8
|
+
option to output your userid given a username and password on the command line.
|
|
9
|
+
Just pass the username and password joined with a colon (:) using the -l
|
|
10
|
+
option and you'll get your userid back as output. Assuming your username is
|
|
11
|
+
'mikerowehl@gmail.com' and your password is 'pppppp' the command would look
|
|
12
|
+
like this:
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
> miker $ basis-band -l mikerowehl@gmail.com:pppppp
|
|
16
|
+
1234567890abcdef12345678
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
In this example the userid returned is '1234567890abcdef12345678'. In the rest
|
|
20
|
+
of the examples the userid is abbreviated to 'xxxxx'.
|
|
11
21
|
|
|
12
22
|
If you pass -u and -d options the raw text will be fetched from the API and
|
|
13
23
|
output on standard output:
|
|
14
24
|
|
|
15
25
|
```
|
|
16
|
-
> miker $ basis-band -
|
|
26
|
+
> miker $ basis-band -u xxxxx -d 2013-10-14
|
|
17
27
|
{"metrics":{"skin_temp":{"min":77.0,"max":95.0,"sum":113642.0,"summary":{"max_skin_temp_per_minute":null...
|
|
18
28
|
```
|
|
19
29
|
|
|
20
30
|
If you want the metric data as CSV instead of raw JSON:
|
|
21
31
|
|
|
22
32
|
```
|
|
23
|
-
> miker $ basis-band -
|
|
24
|
-
t,skin_temp,heartrate,air_temp,calories,gsr,steps
|
|
25
|
-
2013/10/
|
|
26
|
-
2013/10/
|
|
27
|
-
2013/10/
|
|
33
|
+
> miker $ basis-band -u xxxxx -d 2013-10-14 -c
|
|
34
|
+
t,state,skin_temp,heartrate,air_temp,calories,gsr,steps
|
|
35
|
+
2013/10/01 00:00:00,inactive,83.8,58,80.6,1.3,0.000439,0
|
|
36
|
+
2013/10/01 00:01:00,inactive,83.8,62,80.6,1.4,0.000402,0
|
|
37
|
+
2013/10/01 00:02:00,inactive,83.8,64,80.6,1.4,0.000464,0
|
|
28
38
|
...
|
|
29
39
|
```
|
|
30
40
|
|
|
@@ -33,9 +43,14 @@ input and transform it to CSV:
|
|
|
33
43
|
|
|
34
44
|
```
|
|
35
45
|
> miker $ basis-band -c < cache/2013-10-14.json
|
|
36
|
-
t,skin_temp,heartrate,air_temp,calories,gsr,steps
|
|
37
|
-
2013/10/
|
|
38
|
-
2013/10/
|
|
39
|
-
2013/10/
|
|
46
|
+
t,state,skin_temp,heartrate,air_temp,calories,gsr,steps
|
|
47
|
+
2013/10/01 00:00:00,inactive,83.8,58,80.6,1.3,0.000439,0
|
|
48
|
+
2013/10/01 00:01:00,inactive,83.8,62,80.6,1.4,0.000402,0
|
|
49
|
+
2013/10/01 00:02:00,inactive,83.8,64,80.6,1.4,0.000464,0
|
|
40
50
|
...
|
|
41
51
|
```
|
|
52
|
+
|
|
53
|
+
For additional information see the PHP example at
|
|
54
|
+
[https://github.com/btroia/basis-data-export](https://github.com/btroia/basis-data-export).
|
|
55
|
+
That example includes instructions for finding your userid.
|
|
56
|
+
|
data/bin/basis-band
CHANGED
|
@@ -26,8 +26,18 @@ OptionParser.new do |opts|
|
|
|
26
26
|
opts.on("-c", "--[no-]csv", "Output CSV format") do |c|
|
|
27
27
|
options[:csv] = c
|
|
28
28
|
end
|
|
29
|
+
opts.on("-l", "--login [username:password]", "Login and print user id") do |l|
|
|
30
|
+
options[:login] = l
|
|
31
|
+
end
|
|
29
32
|
end.parse!
|
|
30
33
|
|
|
34
|
+
if options[:login]
|
|
35
|
+
(u,p) = options[:login].split(":", 2)
|
|
36
|
+
a = ApiAuth.new
|
|
37
|
+
puts a.login(u, p)
|
|
38
|
+
exit
|
|
39
|
+
end
|
|
40
|
+
|
|
31
41
|
if options[:userid] and options[:date]
|
|
32
42
|
b = BasisBand.new(options[:userid])
|
|
33
43
|
raw = b.data_for_day(options[:date])
|
data/lib/basis-band.rb
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require 'uri'
|
|
2
|
+
require 'net/https'
|
|
3
|
+
require 'json'
|
|
4
|
+
|
|
5
|
+
class ApiAuth
|
|
6
|
+
attr_accessor :userid
|
|
7
|
+
|
|
8
|
+
def login(username, password)
|
|
9
|
+
token = auth_request(username, password)
|
|
10
|
+
get_user_id(token)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def auth_request(username, password)
|
|
14
|
+
u = URI.parse('https://app.mybasis.com/login')
|
|
15
|
+
http = Net::HTTP.new(u.host, u.port)
|
|
16
|
+
http.use_ssl = true
|
|
17
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
|
18
|
+
request = Net::HTTP::Post.new(u.request_uri)
|
|
19
|
+
request.set_form_data({'next' => 'https://app.mybasis.com',
|
|
20
|
+
'submit' => 'Login',
|
|
21
|
+
'username' => username,
|
|
22
|
+
'password' => password})
|
|
23
|
+
response = http.request(request)
|
|
24
|
+
tok_match = response['set-cookie'].match /access_token=([0-9a-f]+);/
|
|
25
|
+
tok_match[1]
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def get_user_id(access_token)
|
|
29
|
+
u = URI.parse('https://app.mybasis.com/api/v1/user/me.json')
|
|
30
|
+
http = Net::HTTP.new(u.host, u.port)
|
|
31
|
+
http.use_ssl = true
|
|
32
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
|
33
|
+
request = Net::HTTP::Get.new(u.request_uri)
|
|
34
|
+
request.add_field('X-Basis-Authorization', "OAuth %s" % access_token)
|
|
35
|
+
json = JSON.parse(http.request(request).body)
|
|
36
|
+
@userid = json['id']
|
|
37
|
+
end
|
|
38
|
+
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.0.
|
|
4
|
+
version: 0.0.2
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -35,6 +35,7 @@ executables:
|
|
|
35
35
|
extensions: []
|
|
36
36
|
extra_rdoc_files: []
|
|
37
37
|
files:
|
|
38
|
+
- lib/basis-band/api-auth.rb
|
|
38
39
|
- lib/basis-band/api-fetch.rb
|
|
39
40
|
- lib/basis-band/api-response-model.rb
|
|
40
41
|
- lib/basis-band/version.rb
|