fitbark 0.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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +6 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +80 -0
- data/LICENSE.txt +21 -0
- data/README.md +194 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/fitbark.gemspec +37 -0
- data/lib/fitbark.rb +45 -0
- data/lib/fitbark/auth.rb +125 -0
- data/lib/fitbark/client.rb +54 -0
- data/lib/fitbark/constants.rb +17 -0
- data/lib/fitbark/data/activity_daily.rb +52 -0
- data/lib/fitbark/data/activity_hourly.rb +46 -0
- data/lib/fitbark/data/activity_level.rb +28 -0
- data/lib/fitbark/data/breed.rb +12 -0
- data/lib/fitbark/data/daily_goal.rb +25 -0
- data/lib/fitbark/data/dog_info.rb +118 -0
- data/lib/fitbark/data/dog_relation.rb +27 -0
- data/lib/fitbark/data/medical_condition.rb +12 -0
- data/lib/fitbark/data/picture.rb +21 -0
- data/lib/fitbark/data/shared.rb +36 -0
- data/lib/fitbark/data/similar_dogs_stat.rb +22 -0
- data/lib/fitbark/data/token.rb +35 -0
- data/lib/fitbark/data/token_info.rb +29 -0
- data/lib/fitbark/data/user_info.rb +27 -0
- data/lib/fitbark/data/user_preview.rb +25 -0
- data/lib/fitbark/data/user_relation.rb +26 -0
- data/lib/fitbark/errors.rb +33 -0
- data/lib/fitbark/handler/v2/activity_series.rb +90 -0
- data/lib/fitbark/handler/v2/activity_total.rb +65 -0
- data/lib/fitbark/handler/v2/base.rb +54 -0
- data/lib/fitbark/handler/v2/daily_goals.rb +37 -0
- data/lib/fitbark/handler/v2/dog_info.rb +39 -0
- data/lib/fitbark/handler/v2/dog_picture.rb +39 -0
- data/lib/fitbark/handler/v2/dog_relations.rb +37 -0
- data/lib/fitbark/handler/v2/friend_dogs.rb +39 -0
- data/lib/fitbark/handler/v2/own_dogs.rb +38 -0
- data/lib/fitbark/handler/v2/set_daily_goal.rb +68 -0
- data/lib/fitbark/handler/v2/similar_dogs_stats.rb +37 -0
- data/lib/fitbark/handler/v2/time_breakdown.rb +63 -0
- data/lib/fitbark/handler/v2/user_info.rb +35 -0
- data/lib/fitbark/handler/v2/user_picture.rb +39 -0
- data/lib/fitbark/handler/v2/user_relations.rb +37 -0
- data/lib/fitbark/version.rb +4 -0
- metadata +234 -0
@@ -0,0 +1,65 @@
|
|
1
|
+
module Fitbark
|
2
|
+
module Handler
|
3
|
+
module V2
|
4
|
+
# = \#activity_total
|
5
|
+
# Fitbark::Handler::V2::ActivityTotal define method *activity_total*
|
6
|
+
# inside Client object
|
7
|
+
#
|
8
|
+
# === params (key/value):
|
9
|
+
#
|
10
|
+
# - *dog_slug*: slug ID relative to dog (String)
|
11
|
+
# - *from*: data start date (Date)
|
12
|
+
# - *to*: data end date (Date)
|
13
|
+
#
|
14
|
+
# example usage:
|
15
|
+
# client = Client.new(token: 'a5b3f8...')
|
16
|
+
# client.activity_total(dog_slug: 'v4s1...', from: 3.days.ago, to: Date.today)
|
17
|
+
#
|
18
|
+
# === response:
|
19
|
+
# return an Integer object.
|
20
|
+
class ActivityTotal
|
21
|
+
include Fitbark::Handler::V2::Base
|
22
|
+
|
23
|
+
# :nodoc:
|
24
|
+
def initialize(token:, opts: {})
|
25
|
+
super
|
26
|
+
validate_input
|
27
|
+
end
|
28
|
+
|
29
|
+
# https://app.fitbark.com/api/v2/activity_totals
|
30
|
+
def response
|
31
|
+
json_response['activity_value'].to_i
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def raw_response
|
37
|
+
connection(verb: :post, fragment: 'activity_totals',
|
38
|
+
params: build_params(opts[:dog_slug], opts[:from],
|
39
|
+
opts[:to])).body
|
40
|
+
end
|
41
|
+
|
42
|
+
def build_params(slug, from, to)
|
43
|
+
{
|
44
|
+
"dog": {
|
45
|
+
"slug": slug,
|
46
|
+
"from": from,
|
47
|
+
"to": to
|
48
|
+
}
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
def validate_input
|
53
|
+
unless opts[:from].instance_of?(Date)
|
54
|
+
raise Fitbark::Errors::FormatError
|
55
|
+
.new(message: "Wrong or missing date for param 'from'")
|
56
|
+
end
|
57
|
+
unless opts[:to].instance_of?(Date)
|
58
|
+
raise Fitbark::Errors::FormatError
|
59
|
+
.new(message: "Wrong or missing date for param 'to'")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Fitbark
|
2
|
+
module Handler
|
3
|
+
module V2
|
4
|
+
# provide base behaviour for all handler classes.
|
5
|
+
module Base
|
6
|
+
include Fitbark::Constants
|
7
|
+
|
8
|
+
# :nodoc:
|
9
|
+
def initialize(token:, opts: {})
|
10
|
+
@token = token
|
11
|
+
@opts = opts
|
12
|
+
@uri = Addressable::URI.new(host: API_HOST, scheme: API_SCHEME,
|
13
|
+
path: API_SUBHOST)
|
14
|
+
end
|
15
|
+
|
16
|
+
attr_reader :uri
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
attr_reader :token, :opts
|
21
|
+
|
22
|
+
def connection(verb: :get, fragment:, params: {})
|
23
|
+
conn = Faraday.new(url: uri.to_s).public_send(verb) do |req|
|
24
|
+
req.url fragment
|
25
|
+
req.params = params
|
26
|
+
req.headers = {
|
27
|
+
'Content-Type' => 'application/json',
|
28
|
+
'Authorization' => "Bearer #{token}"
|
29
|
+
}
|
30
|
+
end
|
31
|
+
check_errors(conn)
|
32
|
+
conn
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def json_response
|
38
|
+
Oj.load(raw_response)
|
39
|
+
rescue Oj::ParseError => e
|
40
|
+
raise(DataError.new(message: e.message))
|
41
|
+
end
|
42
|
+
|
43
|
+
def check_errors(conn)
|
44
|
+
unless conn.success?
|
45
|
+
raise(Fitbark::Errors::ConnectionError
|
46
|
+
.new(message: "#{conn.reason_phrase} #{conn.body}",
|
47
|
+
code: conn.status))
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
# ^ Base
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Fitbark
|
2
|
+
module Handler
|
3
|
+
module V2
|
4
|
+
# = \#daily_goals
|
5
|
+
# Fitbark::Handler::V2::DailyGoals define method *daily_goals*
|
6
|
+
# inside Client object
|
7
|
+
#
|
8
|
+
# === params (key/value):
|
9
|
+
#
|
10
|
+
# - *dog_slug*: slug ID relative to dog (String)
|
11
|
+
#
|
12
|
+
# example usage:
|
13
|
+
# client = Client.new(token: 'a5b3f8...')
|
14
|
+
# client.daily_goals(dog_slug: 'v4s1...')
|
15
|
+
#
|
16
|
+
# === response:
|
17
|
+
# An array of Fitbark::Data::DailyGoal objects.
|
18
|
+
class DailyGoals
|
19
|
+
include Fitbark::Handler::V2::Base
|
20
|
+
|
21
|
+
# :nodoc:
|
22
|
+
# https://app.fitbark.com/api/v2/daily_goal/{dog_slug}
|
23
|
+
def response
|
24
|
+
json_response['daily_goals'].map do |dg|
|
25
|
+
Fitbark::Data::DailyGoal.new(dg)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def raw_response
|
32
|
+
connection(fragment: "daily_goal/#{opts[:dog_slug]}").body
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Fitbark
|
2
|
+
module Handler
|
3
|
+
module V2
|
4
|
+
# = \#dog_info
|
5
|
+
# Fitbark::Handler::V2::DogInfo define method *dog_info*
|
6
|
+
# inside Client object
|
7
|
+
#
|
8
|
+
# === params (key/value):
|
9
|
+
#
|
10
|
+
# - *dog_slug*: slug ID relative to dog (String)
|
11
|
+
#
|
12
|
+
# example usage:
|
13
|
+
# client = Client.new(token: 'a5b3f8...')
|
14
|
+
# client.dog_info(dog_slug: 'v4s1...')
|
15
|
+
#
|
16
|
+
# === response:
|
17
|
+
# return a Fitbark::Data::DogInfo object.
|
18
|
+
class DogInfo
|
19
|
+
include Fitbark::Handler::V2::Base
|
20
|
+
|
21
|
+
# :nodoc:
|
22
|
+
# https://app.fitbark.com/api/v2/dog/{dog_slug}
|
23
|
+
def response
|
24
|
+
Fitbark::Data::DogInfo.new(json_response['dog'])
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def json_response
|
30
|
+
Oj.load(raw_response)
|
31
|
+
end
|
32
|
+
|
33
|
+
def raw_response
|
34
|
+
connection(fragment: "dog/#{opts[:dog_slug]}").body
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Fitbark
|
2
|
+
module Handler
|
3
|
+
module V2
|
4
|
+
# = \#dog_picture
|
5
|
+
# Fitbark::Handler::V2::DogPicture define method *dog_picture*
|
6
|
+
# inside Client object
|
7
|
+
#
|
8
|
+
# === params (key/value):
|
9
|
+
#
|
10
|
+
# - *dog_slug*: slug ID relative to dog (String)
|
11
|
+
#
|
12
|
+
# example usage:
|
13
|
+
# client = Client.new(token: 'a5b3f8...')
|
14
|
+
# client.dog_picture(dog_slug: 'v4s1...')
|
15
|
+
#
|
16
|
+
# === response:
|
17
|
+
# return a Fitbark::Data::Picture object.
|
18
|
+
class DogPicture
|
19
|
+
include Fitbark::Handler::V2::Base
|
20
|
+
|
21
|
+
# :nodoc:
|
22
|
+
# https://app.fitbark.com/api/v2/picture/dog/{dog_slug}
|
23
|
+
def response
|
24
|
+
Fitbark::Data::Picture.new(json_response['image'])
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def json_response
|
30
|
+
Oj.load(raw_response)
|
31
|
+
end
|
32
|
+
|
33
|
+
def raw_response
|
34
|
+
connection(fragment: "picture/dog/#{opts[:dog_slug]}").body
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Fitbark
|
2
|
+
module Handler
|
3
|
+
module V2
|
4
|
+
# = \#dog_relations
|
5
|
+
# Fitbark::Handler::V2::DogRelations define method *dog_relations*
|
6
|
+
# inside Client object
|
7
|
+
#
|
8
|
+
# === params (key/value):
|
9
|
+
#
|
10
|
+
# - no params required
|
11
|
+
#
|
12
|
+
# example usage:
|
13
|
+
# client = Client.new(token: 'a5b3f8...')
|
14
|
+
# client.dog_relations
|
15
|
+
#
|
16
|
+
# === response:
|
17
|
+
# An array of Fitbark::Data::UserRelation objects.
|
18
|
+
class DogRelations
|
19
|
+
include Fitbark::Handler::V2::Base
|
20
|
+
|
21
|
+
# :nodoc:
|
22
|
+
# https://app.fitbark.com/api/v2/dog_relations
|
23
|
+
def response
|
24
|
+
json_response['dog_relations'].map do |rel|
|
25
|
+
Fitbark::Data::UserRelation.new(rel)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def raw_response
|
32
|
+
connection(fragment: 'dog_relations').body
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Fitbark
|
2
|
+
module Handler
|
3
|
+
module V2
|
4
|
+
# = \#friend_dogs
|
5
|
+
# Fitbark::Handler::V2::FriendDogs defines method *friend_dogs*
|
6
|
+
# inside Client object, it retrieve all dogs having friendship
|
7
|
+
# relation with logged user
|
8
|
+
#
|
9
|
+
# === params (key/value):
|
10
|
+
#
|
11
|
+
# - no params required
|
12
|
+
#
|
13
|
+
# example usage:
|
14
|
+
# client = Client.new(token: 'a5b3f8...')
|
15
|
+
# client.friend_dogs
|
16
|
+
#
|
17
|
+
# === response:
|
18
|
+
# An array of Fitbark::Data::DogInfo objects.
|
19
|
+
class FriendDogs
|
20
|
+
include Fitbark::Handler::V2::Base
|
21
|
+
|
22
|
+
# :nodoc:
|
23
|
+
# https://app.fitbark.com/api/v2/dog_relations
|
24
|
+
def response
|
25
|
+
json_response['dog_relations'].
|
26
|
+
select{|h| h['status'].upcase == 'FRIEND'}.map do |rel|
|
27
|
+
Fitbark::Data::DogInfo.new(rel['dog'])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def raw_response
|
34
|
+
connection(fragment: 'dog_relations').body
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Fitbark
|
2
|
+
module Handler
|
3
|
+
module V2
|
4
|
+
# = \#own_dogs
|
5
|
+
# Fitbark::Handler::V2::OwnDogs defines method *own_dogs*
|
6
|
+
# inside Client object, it retrieve all dogs owned by logged user
|
7
|
+
#
|
8
|
+
# === params (key/value):
|
9
|
+
#
|
10
|
+
# - no params required
|
11
|
+
#
|
12
|
+
# example usage:
|
13
|
+
# client = Client.new(token: 'a5b3f8...')
|
14
|
+
# client.own_dogs
|
15
|
+
#
|
16
|
+
# === response:
|
17
|
+
# An array of Fitbark::Data::DogInfo objects.
|
18
|
+
class OwnDogs
|
19
|
+
include Fitbark::Handler::V2::Base
|
20
|
+
|
21
|
+
# :nodoc:
|
22
|
+
# https://app.fitbark.com/api/v2/dog_relations
|
23
|
+
def response
|
24
|
+
json_response['dog_relations'].
|
25
|
+
select{|h| h['status'].upcase == 'OWNER'}.map do |rel|
|
26
|
+
Fitbark::Data::DogInfo.new(rel['dog'])
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def raw_response
|
33
|
+
connection(fragment: 'dog_relations').body
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Fitbark
|
2
|
+
module Handler
|
3
|
+
module V2
|
4
|
+
# = \#set_daily_goal
|
5
|
+
# Fitbark::Handler::V2::SetDailyGoal define method *set_daily_goal*
|
6
|
+
# inside Client object
|
7
|
+
#
|
8
|
+
# === params (key/value):
|
9
|
+
#
|
10
|
+
# - *dog_slug*: slug ID relative to dog (String)
|
11
|
+
# - *goal_points*: goal points to set (Integer)
|
12
|
+
# - *set_on*: date from the goal will start to set (Date)
|
13
|
+
#
|
14
|
+
# example usage:
|
15
|
+
# client = Client.new(token: 'a5b3f8...')
|
16
|
+
# client.set_daily_goal(dog_slug: 'v4s1...', set_on: 1.month.from_now, goal_points: 11000)
|
17
|
+
#
|
18
|
+
# === response:
|
19
|
+
# An array of Fitbark::Data::DailyGoal objects.
|
20
|
+
class SetDailyGoal
|
21
|
+
include Fitbark::Handler::V2::Base
|
22
|
+
|
23
|
+
# :nodoc:
|
24
|
+
def initialize(token:, opts: {})
|
25
|
+
super
|
26
|
+
validate_input
|
27
|
+
end
|
28
|
+
|
29
|
+
# https://app.fitbark.com/api/v2/daily_goal/{dog_slug}
|
30
|
+
def response
|
31
|
+
json_response['daily_goals'].map do |dg|
|
32
|
+
Fitbark::Data::DailyGoal.new(dg)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def raw_response
|
39
|
+
connection(verb: :put, fragment: "daily_goal/#{opts[:dog_slug]}",
|
40
|
+
params: build_params(opts[:goal_points],
|
41
|
+
opts[:set_on])).body
|
42
|
+
end
|
43
|
+
|
44
|
+
def build_params(goal_points, set_on)
|
45
|
+
{
|
46
|
+
"daily_goal": goal_points.to_s,
|
47
|
+
"date": set_on.to_s
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
def validate_input
|
52
|
+
unless opts[:goal_points].instance_of?(Integer)
|
53
|
+
raise Fitbark::Errors::FormatError
|
54
|
+
.new(message: "Wrong or missing integer for param 'goal_points'")
|
55
|
+
end
|
56
|
+
unless opts[:set_on].instance_of?(Date)
|
57
|
+
raise Fitbark::Errors::FormatError
|
58
|
+
.new(message: "Wrong or missing date for param 'set_on'")
|
59
|
+
end
|
60
|
+
if opts[:set_on] < Date.today
|
61
|
+
raise Fitbark::Errors::FormatError
|
62
|
+
.new(message: "Param 'set_on' must be equal or greater than today date")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Fitbark
|
2
|
+
module Handler
|
3
|
+
module V2
|
4
|
+
# = \#similar_dogs_stats
|
5
|
+
# Fitbark::Handler::V2::SimilarDogsStats define method *similar_dogs_stats*
|
6
|
+
# inside Client object
|
7
|
+
#
|
8
|
+
# === params (key/value):
|
9
|
+
#
|
10
|
+
# - *dog_slug*: slug ID relative to dog's activities (String)
|
11
|
+
#
|
12
|
+
# example usage:
|
13
|
+
# client = Client.new(token: 'a5b3f8...')
|
14
|
+
# client.similar_dogs_stats(dog_slug: 'v4s1...')
|
15
|
+
#
|
16
|
+
# === response:
|
17
|
+
# return a Fitbark::Data::SimilarDogsStat object.
|
18
|
+
class SimilarDogsStats
|
19
|
+
include Fitbark::Handler::V2::Base
|
20
|
+
|
21
|
+
# :nodoc:
|
22
|
+
# https://app.fitbark.com/api/v2/similar_dogs_stats
|
23
|
+
def response
|
24
|
+
Fitbark::Data::SimilarDogsStat
|
25
|
+
.new(json_response['similar_dogs_stats'])
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def raw_response
|
31
|
+
connection(verb: :post, fragment: 'similar_dogs_stats',
|
32
|
+
params: { 'slug' => opts[:dog_slug] }).body
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|