fitgem_oauth2 2.0.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,45 +1,45 @@
1
- module FitgemOauth2
2
- class Client
3
-
4
- # ==================================
5
- # Devices
6
- # ==================================
7
-
8
- # return list of Fitbit devices linked to the account
9
- def devices
10
- get_call("user/#{user_id}/devices.json")
11
- end
12
-
13
- # ==================================
14
- # Alarams
15
- # ==================================
16
-
17
- # returns list of alarams for the tracker ID
18
- # @param tracker_id ID for the tracker for which alarams need to be retrieved
19
- def alarms(tracker_id)
20
- get_call("user/#{user_id}/devices/tracker/#{tracker_id}/alarms.json")
21
- end
22
-
23
- # adds an alaram
24
- # @param tracker_id ID of the tracker to which the alaram needs to be added
25
- # @param params POST parameters for adding the alarm
26
- def add_alarm(tracker_id, params)
27
- post_call("user/#{user_id}/devices/tracker/#{tracker_id}/alarms.json", params)
28
- end
29
-
30
- # update an existing alarm
31
- # @param tracker_id ID of the tracker to which alaram needs to be added.
32
- # @param alarm_id ID of the alarm that needs to be updated
33
- # @param params POST parameters for updating the alarm
34
- def update_alarm(tracker_id, alarm_id, params)
35
- post_call("user/#{user_id}/devices/tracker/#{tracker_id}/alarms/#{alarm_id}.json", params)
36
- end
37
-
38
- # removes an existing alaram
39
- # @param tracker_id ID of the tracker from which alaram needs to be removed
40
- # @params alarm_id ID of the alaram that needs to be removed
41
- def remove_alarm(tracker_id, alarm_id)
42
- delete_call("user/#{user_id}/devices/tracker/#{tracker_id}/alarms/#{alarm_id}.json")
43
- end
44
- end
45
- end
1
+ module FitgemOauth2
2
+ class Client
3
+
4
+ # ==================================
5
+ # Devices
6
+ # ==================================
7
+
8
+ # return list of Fitbit devices linked to the account
9
+ def devices
10
+ get_call("user/#{user_id}/devices.json")
11
+ end
12
+
13
+ # ==================================
14
+ # Alarams
15
+ # ==================================
16
+
17
+ # returns list of alarams for the tracker ID
18
+ # @param tracker_id ID for the tracker for which alarams need to be retrieved
19
+ def alarms(tracker_id)
20
+ get_call("user/#{user_id}/devices/tracker/#{tracker_id}/alarms.json")
21
+ end
22
+
23
+ # adds an alaram
24
+ # @param tracker_id ID of the tracker to which the alaram needs to be added
25
+ # @param params POST parameters for adding the alarm
26
+ def add_alarm(tracker_id, params)
27
+ post_call("user/#{user_id}/devices/tracker/#{tracker_id}/alarms.json", params)
28
+ end
29
+
30
+ # update an existing alarm
31
+ # @param tracker_id ID of the tracker to which alaram needs to be added.
32
+ # @param alarm_id ID of the alarm that needs to be updated
33
+ # @param params POST parameters for updating the alarm
34
+ def update_alarm(tracker_id, alarm_id, params)
35
+ post_call("user/#{user_id}/devices/tracker/#{tracker_id}/alarms/#{alarm_id}.json", params)
36
+ end
37
+
38
+ # removes an existing alaram
39
+ # @param tracker_id ID of the tracker from which alaram needs to be removed
40
+ # @params alarm_id ID of the alaram that needs to be removed
41
+ def remove_alarm(tracker_id, alarm_id)
42
+ delete_call("user/#{user_id}/devices/tracker/#{tracker_id}/alarms/#{alarm_id}.json")
43
+ end
44
+ end
45
+ end
@@ -1,30 +1,30 @@
1
- module FitgemOauth2
2
- class InvalidDateArgument < ArgumentError
3
- end
4
-
5
- class InvalidTimeArgument < ArgumentError
6
-
7
- end
8
-
9
- class InvalidArgumentError < ArgumentError
10
- end
11
-
12
- # HTTP errors
13
- class BadRequestError < StandardError
14
- end
15
-
16
- class UnauthorizedError < StandardError
17
- end
18
-
19
- class ForbiddenError < StandardError
20
- end
21
-
22
- class NotFoundError < StandardError
23
- end
24
-
25
- class ApiLimitError < StandardError
26
- end
27
-
28
- class ServerError < StandardError
29
- end
30
- end
1
+ module FitgemOauth2
2
+ class InvalidDateArgument < ArgumentError
3
+ end
4
+
5
+ class InvalidTimeArgument < ArgumentError
6
+
7
+ end
8
+
9
+ class InvalidArgumentError < ArgumentError
10
+ end
11
+
12
+ # HTTP errors
13
+ class BadRequestError < StandardError
14
+ end
15
+
16
+ class UnauthorizedError < StandardError
17
+ end
18
+
19
+ class ForbiddenError < StandardError
20
+ end
21
+
22
+ class NotFoundError < StandardError
23
+ end
24
+
25
+ class ApiLimitError < StandardError
26
+ end
27
+
28
+ class ServerError < StandardError
29
+ end
30
+ end
@@ -1,27 +1,27 @@
1
- require 'fitgem_oauth2/food/collection.rb'
2
- require 'fitgem_oauth2/food/series.rb'
3
- require 'fitgem_oauth2/food/metadata.rb'
4
-
5
- module FitgemOauth2
6
- class Client
7
-
8
- FOOD_SERIES_RESOURCES = %w[caloriesIn water].freeze
9
- FOOD_SERIES_PERIODS = %w[1d 7d 30d 1w 1m 3m 6m 1y max].freeze
10
-
11
- private
12
-
13
- def validate_food_series_period(period)
14
- unless FOOD_SERIES_PERIODS.include?(period)
15
- raise FitgemOauth2::InvalidArgumentError, "Invalid period: #{period}. Specify a valid period from #{FOOD_SERIES_PERIODS}"
16
- end
17
- end
18
-
19
- def food_series_url(user_id, start_date, end_date_or_period)
20
- ['user', user_id, 'foods/log/caloriesIn', 'date', start_date, end_date_or_period].join('/') + '.json'
21
- end
22
-
23
- def water_series_url(user_id, start_date, end_date_or_period)
24
- ['user', user_id, 'foods/log/water', 'date', start_date, end_date_or_period].join('/') + '.json'
25
- end
26
- end
27
- end
1
+ require 'fitgem_oauth2/food/collection.rb'
2
+ require 'fitgem_oauth2/food/series.rb'
3
+ require 'fitgem_oauth2/food/metadata.rb'
4
+
5
+ module FitgemOauth2
6
+ class Client
7
+
8
+ FOOD_SERIES_RESOURCES = %w[caloriesIn water].freeze
9
+ FOOD_SERIES_PERIODS = %w[1d 7d 30d 1w 1m 3m 6m 1y max].freeze
10
+
11
+ private
12
+
13
+ def validate_food_series_period(period)
14
+ unless FOOD_SERIES_PERIODS.include?(period)
15
+ raise FitgemOauth2::InvalidArgumentError, "Invalid period: #{period}. Specify a valid period from #{FOOD_SERIES_PERIODS}"
16
+ end
17
+ end
18
+
19
+ def food_series_url(user_id, start_date, end_date_or_period)
20
+ ['user', user_id, 'foods/log/caloriesIn', 'date', start_date, end_date_or_period].join('/') + '.json'
21
+ end
22
+
23
+ def water_series_url(user_id, start_date, end_date_or_period)
24
+ ['user', user_id, 'foods/log/water', 'date', start_date, end_date_or_period].join('/') + '.json'
25
+ end
26
+ end
27
+ end
@@ -1,51 +1,51 @@
1
- module FitgemOauth2
2
- class Client
3
- def food_goals
4
- get_call("user/#{user_id}/foods/log/goal.json")
5
- end
6
-
7
- def food_logs(date)
8
- get_call("user/#{user_id}/foods/log/date/#{format_date(date)}.json")
9
- end
10
-
11
- def water_logs(date)
12
- get_call("user/#{user_id}/foods/log/water/date/#{format_date(date)}.json")
13
- end
14
-
15
- def water_goal
16
- get_call("user/#{user_id}/foods/log/water/goal.json")
17
- end
18
-
19
- def log_food(params)
20
- post_call("user/#{user_id}/foods/log.json", params)
21
- end
22
-
23
- def update_food_log(food_log_id, params)
24
- post_call("user/#{user_id}/foods/log/#{food_log_id}.json", params)
25
- end
26
-
27
- def log_water(params)
28
- post_call("user/#{user_id}/foods/log/water.json", params)
29
- end
30
-
31
- def update_food_goal(params)
32
- post_call("user/#{user_id}/foods/log/goal.json", params)
33
- end
34
-
35
- def update_water_goal(params)
36
- post_call("user/#{user_id}/foods/log/water/goal.json", params)
37
- end
38
-
39
- def delete_food_log(food_log_id)
40
- delete_call("user/#{user_id}/foods/log/#{food_log_id}.json")
41
- end
42
-
43
- def update_water_log(water_log_id, params)
44
- post_call("user/#{user_id}/foods/log/water/#{water_log_id}.json", params)
45
- end
46
-
47
- def delete_water_log(water_log_id)
48
- delete_call("user/#{user_id}/foods/log/water/#{water_log_id}.json")
49
- end
50
- end
51
- end
1
+ module FitgemOauth2
2
+ class Client
3
+ def food_goals
4
+ get_call("user/#{user_id}/foods/log/goal.json")
5
+ end
6
+
7
+ def food_logs(date)
8
+ get_call("user/#{user_id}/foods/log/date/#{format_date(date)}.json")
9
+ end
10
+
11
+ def water_logs(date)
12
+ get_call("user/#{user_id}/foods/log/water/date/#{format_date(date)}.json")
13
+ end
14
+
15
+ def water_goal
16
+ get_call("user/#{user_id}/foods/log/water/goal.json")
17
+ end
18
+
19
+ def log_food(params)
20
+ post_call("user/#{user_id}/foods/log.json", params)
21
+ end
22
+
23
+ def update_food_log(food_log_id, params)
24
+ post_call("user/#{user_id}/foods/log/#{food_log_id}.json", params)
25
+ end
26
+
27
+ def log_water(params)
28
+ post_call("user/#{user_id}/foods/log/water.json", params)
29
+ end
30
+
31
+ def update_food_goal(params)
32
+ post_call("user/#{user_id}/foods/log/goal.json", params)
33
+ end
34
+
35
+ def update_water_goal(params)
36
+ post_call("user/#{user_id}/foods/log/water/goal.json", params)
37
+ end
38
+
39
+ def delete_food_log(food_log_id)
40
+ delete_call("user/#{user_id}/foods/log/#{food_log_id}.json")
41
+ end
42
+
43
+ def update_water_log(water_log_id, params)
44
+ post_call("user/#{user_id}/foods/log/water/#{water_log_id}.json", params)
45
+ end
46
+
47
+ def delete_water_log(water_log_id)
48
+ delete_call("user/#{user_id}/foods/log/water/#{water_log_id}.json")
49
+ end
50
+ end
51
+ end
@@ -1,63 +1,63 @@
1
- module FitgemOauth2
2
- class Client
3
- def add_favorite_food(food_id)
4
- post_call("user/#{user_id}/foods/log/favorite/#{food_id}.json")
5
- end
6
-
7
- def delete_favorite_food(food_id)
8
- delete_call("user/#{user_id}/foods/log/favorite/#{food_id}.json")
9
- end
10
-
11
- def recent_foods
12
- get_call("user/#{user_id}/foods/recent.json")
13
- end
14
-
15
- def favorite_foods
16
- get_call("user/#{user_id}/foods/log/favorite.json")
17
- end
18
-
19
- def frequent_foods
20
- get_call("user/#{user_id}/foods/log/frequent.json")
21
- end
22
-
23
- def meals
24
- get_call("user/#{user_id}/meals.json")
25
- end
26
-
27
- def create_meal(params)
28
- post_call("user/#{user_id}/meals.json", params)
29
- end
30
-
31
- def meal(meal_id)
32
- get_call("user/#{user_id}/meals/#{meal_id}.json")
33
- end
34
-
35
- def update_meal(meal_id, params)
36
- post_call("user/#{user_id}/meals/#{meal_id}.json", params)
37
- end
38
-
39
- def delete_meal(meal_id)
40
- delete_call("user/#{user_id}/meals/#{meal_id}.json")
41
- end
42
-
43
- def create_food(params)
44
- post_call("user/#{user_id}/foods.json", params)
45
- end
46
-
47
- def delete_food(food_id)
48
- delete_call("user/#{user_id}/foods/#{food_id}.json")
49
- end
50
-
51
- def food(id)
52
- get_call("foods/#{id}.json")
53
- end
54
-
55
- def food_units
56
- get_call('foods/units.json')
57
- end
58
-
59
- def search_foods(params)
60
- post_call('foods/search.json', params)
61
- end
62
- end
63
- end
1
+ module FitgemOauth2
2
+ class Client
3
+ def add_favorite_food(food_id)
4
+ post_call("user/#{user_id}/foods/log/favorite/#{food_id}.json")
5
+ end
6
+
7
+ def delete_favorite_food(food_id)
8
+ delete_call("user/#{user_id}/foods/log/favorite/#{food_id}.json")
9
+ end
10
+
11
+ def recent_foods
12
+ get_call("user/#{user_id}/foods/recent.json")
13
+ end
14
+
15
+ def favorite_foods
16
+ get_call("user/#{user_id}/foods/log/favorite.json")
17
+ end
18
+
19
+ def frequent_foods
20
+ get_call("user/#{user_id}/foods/log/frequent.json")
21
+ end
22
+
23
+ def meals
24
+ get_call("user/#{user_id}/meals.json")
25
+ end
26
+
27
+ def create_meal(params)
28
+ post_call("user/#{user_id}/meals.json", params)
29
+ end
30
+
31
+ def meal(meal_id)
32
+ get_call("user/#{user_id}/meals/#{meal_id}.json")
33
+ end
34
+
35
+ def update_meal(meal_id, params)
36
+ post_call("user/#{user_id}/meals/#{meal_id}.json", params)
37
+ end
38
+
39
+ def delete_meal(meal_id)
40
+ delete_call("user/#{user_id}/meals/#{meal_id}.json")
41
+ end
42
+
43
+ def create_food(params)
44
+ post_call("user/#{user_id}/foods.json", params)
45
+ end
46
+
47
+ def delete_food(food_id)
48
+ delete_call("user/#{user_id}/foods/#{food_id}.json")
49
+ end
50
+
51
+ def food(id)
52
+ get_call("foods/#{id}.json")
53
+ end
54
+
55
+ def food_units
56
+ get_call('foods/units.json')
57
+ end
58
+
59
+ def search_foods(params)
60
+ post_call('foods/search.json', params)
61
+ end
62
+ end
63
+ end
@@ -1,55 +1,55 @@
1
- module FitgemOauth2
2
- class Client
3
- def food_series_for_date_range(start_date, end_date)
4
- validate_start_date(start_date)
5
- validate_end_date(end_date)
6
- get_call(food_series_url(user_id, format_date(start_date), format_date(end_date)))
7
- end
8
-
9
- def food_series_for_period(start_date, period)
10
- validate_start_date(start_date)
11
- validate_food_series_period(period)
12
- get_call(food_series_url(user_id, format_date(start_date), period))
13
- end
14
-
15
- def water_series_for_date_range(start_date, end_date)
16
- validate_start_date(start_date)
17
- validate_end_date(end_date)
18
- get_call(water_series_url(user_id, format_date(start_date), format_date(end_date)))
19
- end
20
-
21
- def water_series_for_period(start_date, period)
22
- validate_start_date(start_date)
23
- validate_food_series_period(period)
24
- get_call(water_series_url(user_id, format_date(start_date), period))
25
- end
26
-
27
- def food_series(resource: nil, start_date: nil, end_date: nil, period: nil)
28
- warn '[DEPRECATED] use `food_series_for_date_range`, `food_series_for_period`, `water_series_for_date_range`, or `water_series_for_period` instead.'
29
- unless FOOD_SERIES_RESOURCES.include?(resource)
30
- raise FitgemOauth2::InvalidArgumentError, "Invalid resource: #{resource}. Specify a valid resource from #{FOOD_SERIES_RESOURCES}"
31
- end
32
-
33
- if end_date && period
34
- raise FitgemOauth2::InvalidArgumentError, 'Provide only one of end_date and period.'
35
- end
36
-
37
- if !end_date && !period
38
- raise FitgemOauth2::InvalidArgumentError, 'Provide at least one of end_date and period.'
39
- end
40
-
41
- url = ['user', user_id, 'foods/log', resource, 'date', start_date].join('/')
42
-
43
- if period
44
- unless FOOD_SERIES_PERIODS.include?(period)
45
- raise FitgemOauth2::InvalidArgumentError, "Invalid period: #{period}. Specify a valid period from #{FOOD_SERIES_PERIODS}"
46
- end
47
- end
48
-
49
- second = period || format_date(end_date)
50
- url = [url, second].join('/')
51
-
52
- get_call(url + '.json')
53
- end
54
- end
55
- end
1
+ module FitgemOauth2
2
+ class Client
3
+ def food_series_for_date_range(start_date, end_date)
4
+ validate_start_date(start_date)
5
+ validate_end_date(end_date)
6
+ get_call(food_series_url(user_id, format_date(start_date), format_date(end_date)))
7
+ end
8
+
9
+ def food_series_for_period(start_date, period)
10
+ validate_start_date(start_date)
11
+ validate_food_series_period(period)
12
+ get_call(food_series_url(user_id, format_date(start_date), period))
13
+ end
14
+
15
+ def water_series_for_date_range(start_date, end_date)
16
+ validate_start_date(start_date)
17
+ validate_end_date(end_date)
18
+ get_call(water_series_url(user_id, format_date(start_date), format_date(end_date)))
19
+ end
20
+
21
+ def water_series_for_period(start_date, period)
22
+ validate_start_date(start_date)
23
+ validate_food_series_period(period)
24
+ get_call(water_series_url(user_id, format_date(start_date), period))
25
+ end
26
+
27
+ def food_series(resource: nil, start_date: nil, end_date: nil, period: nil)
28
+ warn '[DEPRECATED] use `food_series_for_date_range`, `food_series_for_period`, `water_series_for_date_range`, or `water_series_for_period` instead.'
29
+ unless FOOD_SERIES_RESOURCES.include?(resource)
30
+ raise FitgemOauth2::InvalidArgumentError, "Invalid resource: #{resource}. Specify a valid resource from #{FOOD_SERIES_RESOURCES}"
31
+ end
32
+
33
+ if end_date && period
34
+ raise FitgemOauth2::InvalidArgumentError, 'Provide only one of end_date and period.'
35
+ end
36
+
37
+ if !end_date && !period
38
+ raise FitgemOauth2::InvalidArgumentError, 'Provide at least one of end_date and period.'
39
+ end
40
+
41
+ url = ['user', user_id, 'foods/log', resource, 'date', start_date].join('/')
42
+
43
+ if period
44
+ unless FOOD_SERIES_PERIODS.include?(period)
45
+ raise FitgemOauth2::InvalidArgumentError, "Invalid period: #{period}. Specify a valid period from #{FOOD_SERIES_PERIODS}"
46
+ end
47
+ end
48
+
49
+ second = period || format_date(end_date)
50
+ url = [url, second].join('/')
51
+
52
+ get_call(url + '.json')
53
+ end
54
+ end
55
+ end