fitbyte 0.2.5 → 0.2.6
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/CHANGELOG.md +9 -0
- data/README.md +20 -0
- data/lib/fitbyte/activities.rb +117 -0
- data/lib/fitbyte/client.rb +14 -2
- data/lib/fitbyte/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: d593e9552bee3c7dc1319f3f9ba196e7d4064b29
|
4
|
+
data.tar.gz: 87c7a205b3131164a185c2d7423ec8695f40fce5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6b484d18dc864cbc1485e7b53f88f42008051f3f763fe41b60170305506564cd3c554ceed1d663d546fb7a8aabd19a063b2de9dab544e56fc2001d5095b4023
|
7
|
+
data.tar.gz: 992028f7008f2fac652494b120b6bf6aef90c5c96c50056df7b71535bc410b768e3e9c814b4d091b79b4262fe501ca9f0022c6036c2dba932eaccf4325d24730
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
0.2.6
|
2
|
+
-----
|
3
|
+
- Expand API endpoint support for the following actions:
|
4
|
+
- Add activity to favorites
|
5
|
+
- Retrieve list of activity log entries
|
6
|
+
- Create/update daily/weekly goals
|
7
|
+
- Delete activity
|
8
|
+
- Remove activity from favorites
|
9
|
+
|
1
10
|
0.2.5
|
2
11
|
-----
|
3
12
|
- Responses now return FitStruct objects (inherit from OpenStruct).
|
data/README.md
CHANGED
@@ -59,6 +59,26 @@ client.food_logs Date.today, raw: true
|
|
59
59
|
# => { :foods => [{ :isFavorite => true, :logDate => "2015-06-26", :logId => 1820, :loggedFood => { :accessLevel => "PUBLIC", :amount => 132.57, :brand => "", :calories => 752, ...}] }
|
60
60
|
```
|
61
61
|
|
62
|
+
### Options
|
63
|
+
|
64
|
+
When initializing a `Fitbyte::Client` instance, you're given access to a handful of options:
|
65
|
+
|
66
|
+
- `:api_version` - API version to be used when making requests (default: "1")
|
67
|
+
|
68
|
+
---
|
69
|
+
- `:unit_system` - The measurement unit system to use for response values (default: "en_US" | available: "en_US", "en_GB", and "any" for metric)
|
70
|
+
|
71
|
+
---
|
72
|
+
- `:locale` - The locale to use for response values (default: "en_US" | available: "en_US", "fr_FR", "de_DE", "es_ES", "en_GB", "en_AU", "en_NZ" and "ja_JP")
|
73
|
+
|
74
|
+
---
|
75
|
+
- `:scope` - A space-delimited list of the permissions you are requesting (default: "activity nutrition profile settings sleep social weight" | available: "activity", "heartrate", "location", "nutrition", "profile", "settings" "sleep", "social" and "weight")
|
76
|
+
|
77
|
+
---
|
78
|
+
- `:raw_response` - Setting this option to `true` returns response values on subsequent calls as parsed JSON; by default, response values use FitStruct objects, for convenient method-like attribute access (default: false | available: true, false)
|
79
|
+
|
80
|
+
---
|
81
|
+
|
62
82
|
## License
|
63
83
|
|
64
84
|
This gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/lib/fitbyte/activities.rb
CHANGED
@@ -1,31 +1,148 @@
|
|
1
1
|
module Fitbyte
|
2
2
|
class Client
|
3
|
+
# GET Activities
|
4
|
+
# ==============
|
5
|
+
|
6
|
+
# Retrieves a summary and list of a user's activities and activity log entries for a given day
|
7
|
+
# in the format requested using units in the unit system which corresponds to the Accept-Language header provided.
|
8
|
+
|
3
9
|
def daily_activity_summary(date=Date.today, opts={})
|
4
10
|
get("user/#{@user_id}/activities/date/#{format_date(date)}.json", opts)
|
5
11
|
end
|
6
12
|
|
13
|
+
# Retrieves a list of a user's frequent activities in the format requested using units
|
14
|
+
# in the unit system which corresponds to the Accept-Language header provided.
|
15
|
+
|
7
16
|
def frequent_activities(opts={})
|
8
17
|
get("user/#{@user_id}/activities/frequent.json", opts)
|
9
18
|
end
|
10
19
|
|
20
|
+
def recent_activities(opts={})
|
21
|
+
get("user/#{@user_id}/activities/recent.json", opts)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Returns a list of a user's favorite activities.
|
25
|
+
|
11
26
|
def favorite_activities(opts={})
|
12
27
|
get("user/#{@user_id}/activities/favorite.json", opts)
|
13
28
|
end
|
14
29
|
|
30
|
+
# Gets a tree of all valid Fitbit public activities from
|
31
|
+
# the activities catalog as well as private custom activities the user created.
|
32
|
+
|
15
33
|
def all_activities(opts={})
|
16
34
|
get("activities.json", opts)
|
17
35
|
end
|
18
36
|
|
37
|
+
# Retrieves a list of a user's activity log entries before or after a given day with
|
38
|
+
# offset and limit using units in the unit system which corresponds to the Accept-Language header provided.
|
39
|
+
|
40
|
+
# ==== Parameters
|
41
|
+
# * +:beforeDate+ - the date; formatted in yyyy-MM-ddTHH:mm:ss
|
42
|
+
# * +:afterDate+ - the date; formatted in yyyy-MM-ddTHH:mm:ss
|
43
|
+
# * +:sort+ - the sort order of entries by date (asc or desc)
|
44
|
+
# * +:offset+ - the offset number of entries
|
45
|
+
# * +:limit+ - the max of the number of entries returned (max: 100)
|
46
|
+
|
47
|
+
def activity_logs_list(opts={})
|
48
|
+
get("user/#{@user_id}/activities/list.json", opts)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Returns the details of a specific activity in the Fitbit activities database in the format requested.
|
52
|
+
# If activity has levels, also returns a list of activity level details.
|
53
|
+
|
54
|
+
def activity(activity_id)
|
55
|
+
get("activities/#{activity_id}.json")
|
56
|
+
end
|
57
|
+
|
58
|
+
# Retrieves the user's activity statistics in the format requested using units
|
59
|
+
# in the unit system which corresponds to the Accept-Language header provided.
|
60
|
+
# Activity statistics includes Lifetime and Best achievement values from the
|
61
|
+
# My Achievements tile on the website dashboard.
|
62
|
+
|
19
63
|
def lifetime_stats(opts={})
|
20
64
|
get("user/#{@user_id}/activities.json", opts)
|
21
65
|
end
|
22
66
|
|
67
|
+
# Retrieves a user's current daily activity goals.
|
68
|
+
|
23
69
|
def daily_goals(opts={})
|
24
70
|
get("user/#{@user_id}/activities/goals/daily.json", opts)
|
25
71
|
end
|
26
72
|
|
73
|
+
# Retrieves a user's current weekly activity goals.
|
74
|
+
|
27
75
|
def weekly_goals(opts={})
|
28
76
|
get("user/#{@user_id}/activities/goals/weekly.json", opts)
|
29
77
|
end
|
78
|
+
|
79
|
+
# POST Activities
|
80
|
+
# ===============
|
81
|
+
|
82
|
+
# Creates log entry for an activity or user's private custom activity using units
|
83
|
+
# in the unit system which corresponds to the Accept-Language header provided.
|
84
|
+
|
85
|
+
# ==== POST Parameters
|
86
|
+
# * +:activityId+ - activity id
|
87
|
+
# * +:activityName+ - custom activity name. Either activity ID or activityName must be provided
|
88
|
+
# * +:manualCalories+ - calories burned, specified manually. Required with activityName, otherwise optional
|
89
|
+
# * +:startTime+ - activity start time; formatted in HH:mm:ss
|
90
|
+
# * +:durationMillis+ - duration in milliseconds
|
91
|
+
# * +:date+ - log entry date; formatted in yyyy-MM-dd
|
92
|
+
# * +:distance+ - distance; required for logging directory activity; formatted in X.XX
|
93
|
+
# * +:distanceUnit+ - distance measurement unit
|
94
|
+
|
95
|
+
def log_activity(opts)
|
96
|
+
post("user/#{@user_id}/activities.json", opts)
|
97
|
+
end
|
98
|
+
|
99
|
+
# Adds the activity with the given ID to user's list of favorite activities.
|
100
|
+
|
101
|
+
def add_favorite_activity(activity_id)
|
102
|
+
post("user/#{@user_id}/activities/favorite/#{activity_id}.json")
|
103
|
+
end
|
104
|
+
|
105
|
+
# Creates or updates a user's daily activity goals and returns a response using units
|
106
|
+
# in the unit system which corresponds to the Accept-Language header provided.
|
107
|
+
|
108
|
+
# ==== POST Parameters
|
109
|
+
# * +:caloriesOut+ - calories output goal value; integer
|
110
|
+
# * +:activeMinutes+ - active minutes goal value; integer
|
111
|
+
# * +:floors+ - floor goal value; integer
|
112
|
+
# * +:distance+ - distance goal value; X.XX or integer
|
113
|
+
# * +:steps+ - steps goal value; integer
|
114
|
+
|
115
|
+
def create_or_update_daily_goals(opts={})
|
116
|
+
post("user/#{@user_id}/activities/goals/daily.json", opts)
|
117
|
+
end
|
118
|
+
|
119
|
+
# Creates or updates a user's weekly activity goals and returns a response using units
|
120
|
+
# in the unit system which corresponds to the Accept-Language header provided.
|
121
|
+
|
122
|
+
# ==== POST Parameters
|
123
|
+
# * +:caloriesOut+ - calories output goal value; integer
|
124
|
+
# * +:activeMinutes+ - active minutes goal value; integer
|
125
|
+
# * +:floors+ - floor goal value; integer
|
126
|
+
# * +:distance+ - distance goal value; X.XX or integer
|
127
|
+
# * +:steps+ - steps goal value; integer
|
128
|
+
|
129
|
+
def create_or_update_weekly_goals(opts={})
|
130
|
+
post("user/#{@user_id}/activities/goals/weekly.json", opts)
|
131
|
+
end
|
132
|
+
|
133
|
+
# DELETE Activities
|
134
|
+
# =================
|
135
|
+
|
136
|
+
# Deletes a user's activity log entry with the given ID.
|
137
|
+
|
138
|
+
def delete_activity(activity_log_id)
|
139
|
+
delete("user/#{@user_id}/activities/#{activity_log_id}.json")
|
140
|
+
end
|
141
|
+
|
142
|
+
# Removes the activity with the given ID from a user's list of favorite activities.
|
143
|
+
|
144
|
+
def delete_favorite_activity(activity_id)
|
145
|
+
delete("user/#{@user_id}/activities/favorite/#{activity_id}.json")
|
146
|
+
end
|
30
147
|
end
|
31
148
|
end
|
data/lib/fitbyte/client.rb
CHANGED
@@ -71,8 +71,20 @@ module Fitbyte
|
|
71
71
|
|
72
72
|
def get(path, opts={})
|
73
73
|
raw = opts[:raw].nil? ? @raw_response : opts[:raw]
|
74
|
-
|
75
|
-
|
74
|
+
response = token.get(("#{@api_version}/" + path), headers: request_headers).response
|
75
|
+
MultiJson.load(response.body, symbolize_keys: true, object_class: (FitStruct unless raw)) unless response.status == 204
|
76
|
+
end
|
77
|
+
|
78
|
+
def post(path, opts={})
|
79
|
+
raw = opts[:raw].nil? ? @raw_response : opts[:raw]
|
80
|
+
response = token.post(("#{@api_version}/" + path), body: opts, headers: request_headers).response
|
81
|
+
MultiJson.load(response.body, symbolize_keys: true, object_class: (FitStruct unless raw)) unless response.status == 204
|
82
|
+
end
|
83
|
+
|
84
|
+
def delete(path, opts={})
|
85
|
+
raw = opts[:raw].nil? ? @raw_response : opts[:raw]
|
86
|
+
response = token.delete(("#{@api_version}/" + path), headers: request_headers).response
|
87
|
+
MultiJson.load(response.body, symbolize_keys: true, object_class: (FitStruct unless raw)) unless response.status == 204
|
76
88
|
end
|
77
89
|
|
78
90
|
def defaults
|
data/lib/fitbyte/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fitbyte
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zoran Pesic
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oauth2
|