-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfuel.rb
45 lines (34 loc) · 794 Bytes
/
fuel.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require 'httparty'
class FuelBand
include HTTParty
#debug_output $stdout
# use SSL
base_uri 'https://api.nike.com/v1.0/'
format :json
HEADERS = {
'appid' => 'fuelband',
'Accept' => 'application/json',
'Content-Type' => 'application/json'
}
def initialize
@end = Time.now
@start = @end - 86400 # 1 days
end
# get fuel summary
def summary
self.class.get('/me/activities/summary/%s' % @start.strftime("%d%m%y"), query: params, headers: HEADERS)
end
def stats
summary['daily'].first['summary']
end
private
def params
config.merge(
'endDate' => @end.strftime("%d%m%y"),
'fidelity' => 24 * 60 # no. of buckets to load
)
end
def config
YAML::load_file(File.dirname(__FILE__) + '/config.yml')
end
end