fitgem_oauth2 1.0.6 → 1.1.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.
- checksums.yaml +4 -4
- data/lib/fitgem_oauth2/activity.rb +10 -2
- data/lib/fitgem_oauth2/client.rb +19 -1
- data/lib/fitgem_oauth2/sleep.rb +18 -4
- data/lib/fitgem_oauth2/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c416d838d7d7c317ab66ac5eb9997a8bd7fab6b9
|
4
|
+
data.tar.gz: ec9445743a11afa6d4e593a914e3a58ec0763a19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1176e66831bdba9d9f812b77c3f15dd684f6a3074f5f3e99eea02ff532d85a3d2083c12fe735c47b7906ed37c9e69c165bfb81f2f1c91115f32161cbca51c02
|
7
|
+
data.tar.gz: 120483a98d665ededc548c593e71ef733c373ad28fb4e871f543e187bc37ea91d5a9cffc126f9cb27c0a072bb642b2e97f21272441386996f775a58b6b77a55c
|
@@ -109,8 +109,16 @@ module FitgemOauth2
|
|
109
109
|
end
|
110
110
|
|
111
111
|
# retrieves activity list for the user
|
112
|
-
def activity_list
|
113
|
-
|
112
|
+
def activity_list(date, sort, limit)
|
113
|
+
date_param = format_date(date)
|
114
|
+
if sort == "asc"
|
115
|
+
date_param = "afterDate=#{date_param}"
|
116
|
+
elsif sort == "desc"
|
117
|
+
date_param = "beforeDate=#{date_param}"
|
118
|
+
else
|
119
|
+
raise FitgemOauth2::InvalidArgumentError, "sort can either be asc or desc"
|
120
|
+
end
|
121
|
+
get_call("user/#{user_id}/activities/list.json?offset=0&limit=#{limit}&sort=#{sort}&#{date_param}")
|
114
122
|
end
|
115
123
|
|
116
124
|
# retrieves activity list in the tcx format
|
data/lib/fitgem_oauth2/client.rb
CHANGED
@@ -57,12 +57,27 @@ module FitgemOauth2
|
|
57
57
|
parse_response(response)
|
58
58
|
end
|
59
59
|
|
60
|
+
# This method is a helper method (like get_call) for 1.2 version of the API_VERSION
|
61
|
+
# This method is needed because Fitbit API supports both versions as of current
|
62
|
+
# date (Nov 5, 2017)
|
63
|
+
def get_call_1_2(url)
|
64
|
+
url = "1.2/#{url}"
|
65
|
+
response = connection.get(url) {|request| set_headers(request)}
|
66
|
+
parse_response(response)
|
67
|
+
end
|
68
|
+
|
60
69
|
def post_call(url, params = {})
|
61
70
|
url = "#{API_VERSION}/#{url}"
|
62
71
|
response = connection.post(url, params) { |request| set_headers(request) }
|
63
72
|
parse_response(response)
|
64
73
|
end
|
65
74
|
|
75
|
+
def post_call_1_2(url, params = {})
|
76
|
+
url = "1.2/#{url}"
|
77
|
+
response = connection.post(url, params) { |request| set_headers(request) }
|
78
|
+
parse_response(response)
|
79
|
+
end
|
80
|
+
|
66
81
|
def delete_call(url)
|
67
82
|
url = "#{API_VERSION}/#{url}"
|
68
83
|
response = connection.delete(url) { |request| set_headers(request) }
|
@@ -85,7 +100,10 @@ module FitgemOauth2
|
|
85
100
|
200 => lambda {
|
86
101
|
body = JSON.parse(response.body)
|
87
102
|
body = {body: body} if body.is_a?(Array)
|
88
|
-
|
103
|
+
headers = response.headers.to_hash.keep_if { |k,v|
|
104
|
+
headers_to_keep.include? k
|
105
|
+
}
|
106
|
+
body.merge!(headers)
|
89
107
|
},
|
90
108
|
201 => lambda { },
|
91
109
|
204 => lambda { },
|
data/lib/fitgem_oauth2/sleep.rb
CHANGED
@@ -8,7 +8,23 @@ module FitgemOauth2
|
|
8
8
|
# retrieve sleep logs for a date
|
9
9
|
# @param date date for which sleep logs needs to be accessed
|
10
10
|
def sleep_logs(date)
|
11
|
-
|
11
|
+
get_call_1_2("user/#{user_id}/sleep/date/#{format_date(date)}.json")
|
12
|
+
end
|
13
|
+
|
14
|
+
def sleep_logs_by_date_range(start_date, end_date)
|
15
|
+
get_call_1_2("user/#{user_id}/sleep/date/#{format_date(start_date)}/#{format_date(end_date)}.json")
|
16
|
+
end
|
17
|
+
|
18
|
+
def sleep_logs_list(date, sort, limit)
|
19
|
+
date_param = format_date(date)
|
20
|
+
if sort == "asc"
|
21
|
+
date_param = "afterDate=#{date_param}"
|
22
|
+
elsif sort == "desc"
|
23
|
+
date_param = "beforeDate=#{date_param}"
|
24
|
+
else
|
25
|
+
raise FitgemOauth2::InvalidArgumentError, "sort can either be asc or desc"
|
26
|
+
end
|
27
|
+
get_call_1_2("user/#{user_id}/sleep/list.json?#{date_param}&offset=0&sort=#{sort}&limit=#{limit}")
|
12
28
|
end
|
13
29
|
|
14
30
|
# retrieve sleep goal for the user
|
@@ -54,7 +70,7 @@ module FitgemOauth2
|
|
54
70
|
# log sleep
|
55
71
|
# @param params POST params for creating sleep log
|
56
72
|
def log_sleep(params)
|
57
|
-
|
73
|
+
post_call_1_2("user/#{user_id}/sleep.json", params)
|
58
74
|
end
|
59
75
|
|
60
76
|
# deleted sleep log
|
@@ -62,7 +78,5 @@ module FitgemOauth2
|
|
62
78
|
def delete_logged_sleep(log_id)
|
63
79
|
delete_call("user/#{user_id}/sleep/#{log_id}.json")
|
64
80
|
end
|
65
|
-
|
66
81
|
end
|
67
|
-
|
68
82
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fitgem_oauth2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ankit Gupta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|