fitbark 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +6 -0
  5. data/.travis.yml +7 -0
  6. data/CODE_OF_CONDUCT.md +74 -0
  7. data/Gemfile +4 -0
  8. data/Gemfile.lock +80 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +194 -0
  11. data/Rakefile +6 -0
  12. data/bin/console +14 -0
  13. data/bin/setup +8 -0
  14. data/fitbark.gemspec +37 -0
  15. data/lib/fitbark.rb +45 -0
  16. data/lib/fitbark/auth.rb +125 -0
  17. data/lib/fitbark/client.rb +54 -0
  18. data/lib/fitbark/constants.rb +17 -0
  19. data/lib/fitbark/data/activity_daily.rb +52 -0
  20. data/lib/fitbark/data/activity_hourly.rb +46 -0
  21. data/lib/fitbark/data/activity_level.rb +28 -0
  22. data/lib/fitbark/data/breed.rb +12 -0
  23. data/lib/fitbark/data/daily_goal.rb +25 -0
  24. data/lib/fitbark/data/dog_info.rb +118 -0
  25. data/lib/fitbark/data/dog_relation.rb +27 -0
  26. data/lib/fitbark/data/medical_condition.rb +12 -0
  27. data/lib/fitbark/data/picture.rb +21 -0
  28. data/lib/fitbark/data/shared.rb +36 -0
  29. data/lib/fitbark/data/similar_dogs_stat.rb +22 -0
  30. data/lib/fitbark/data/token.rb +35 -0
  31. data/lib/fitbark/data/token_info.rb +29 -0
  32. data/lib/fitbark/data/user_info.rb +27 -0
  33. data/lib/fitbark/data/user_preview.rb +25 -0
  34. data/lib/fitbark/data/user_relation.rb +26 -0
  35. data/lib/fitbark/errors.rb +33 -0
  36. data/lib/fitbark/handler/v2/activity_series.rb +90 -0
  37. data/lib/fitbark/handler/v2/activity_total.rb +65 -0
  38. data/lib/fitbark/handler/v2/base.rb +54 -0
  39. data/lib/fitbark/handler/v2/daily_goals.rb +37 -0
  40. data/lib/fitbark/handler/v2/dog_info.rb +39 -0
  41. data/lib/fitbark/handler/v2/dog_picture.rb +39 -0
  42. data/lib/fitbark/handler/v2/dog_relations.rb +37 -0
  43. data/lib/fitbark/handler/v2/friend_dogs.rb +39 -0
  44. data/lib/fitbark/handler/v2/own_dogs.rb +38 -0
  45. data/lib/fitbark/handler/v2/set_daily_goal.rb +68 -0
  46. data/lib/fitbark/handler/v2/similar_dogs_stats.rb +37 -0
  47. data/lib/fitbark/handler/v2/time_breakdown.rb +63 -0
  48. data/lib/fitbark/handler/v2/user_info.rb +35 -0
  49. data/lib/fitbark/handler/v2/user_picture.rb +39 -0
  50. data/lib/fitbark/handler/v2/user_relations.rb +37 -0
  51. data/lib/fitbark/version.rb +4 -0
  52. metadata +234 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9c27e175fffa5ad6d65dcf672027dcb981b6c56b187dc1f57fdc9f94e1cacc6d
4
+ data.tar.gz: e066e82e6c6cf061afc7f5f6b7b4645da02d20ba6cd2d8d08c890e25b612080f
5
+ SHA512:
6
+ metadata.gz: b63b828c17389cca5dd6bdd5da47f9a641eba5ba74827a2d66602a6f29ede945b7135ac0e9dbf9fd6df425d55e559a34a464a807c7c282be16b6ef0d6b14fe57
7
+ data.tar.gz: f6ec931813547be2a4cb8d192f6fce8b408af1071e99e80aee2615de9dc3947a5cec28c43d852b836f1476d1a40d125e817bb3b6606e77bce81c98836457ec42
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,6 @@
1
+ Metrics/BlockLength:
2
+ Max: 50
3
+ Exclude:
4
+ - 'fitbark.gemspec'
5
+ - 'lib/**/*.rb'
6
+ - 'spec/**/*.rb'
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.0
7
+ before_install: gem install bundler -v 2.0.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at natydev@localhost. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fitbark.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,80 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fitbark (0.1.0)
5
+ addressable (~> 2.6)
6
+ faraday (~> 0.15)
7
+ oj (~> 3.7)
8
+ strict_open_struct (~> 0.0.2)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ addressable (2.6.0)
14
+ public_suffix (>= 2.0.2, < 4.0)
15
+ ast (2.4.0)
16
+ concurrent-ruby (1.1.5)
17
+ crack (0.4.3)
18
+ safe_yaml (~> 1.0.0)
19
+ diff-lcs (1.3)
20
+ faker (1.9.3)
21
+ i18n (>= 0.7)
22
+ faraday (0.15.4)
23
+ multipart-post (>= 1.2, < 3)
24
+ hashdiff (0.3.8)
25
+ i18n (1.6.0)
26
+ concurrent-ruby (~> 1.0)
27
+ jaro_winkler (1.5.2)
28
+ multipart-post (2.0.0)
29
+ oj (3.7.12)
30
+ parallel (1.17.0)
31
+ parser (2.6.2.1)
32
+ ast (~> 2.4.0)
33
+ psych (3.1.0)
34
+ public_suffix (3.0.3)
35
+ rainbow (3.0.0)
36
+ rake (10.5.0)
37
+ rspec (3.8.0)
38
+ rspec-core (~> 3.8.0)
39
+ rspec-expectations (~> 3.8.0)
40
+ rspec-mocks (~> 3.8.0)
41
+ rspec-core (3.8.0)
42
+ rspec-support (~> 3.8.0)
43
+ rspec-expectations (3.8.2)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.8.0)
46
+ rspec-mocks (3.8.0)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.8.0)
49
+ rspec-support (3.8.0)
50
+ rubocop (0.67.2)
51
+ jaro_winkler (~> 1.5.1)
52
+ parallel (~> 1.10)
53
+ parser (>= 2.5, != 2.5.1.1)
54
+ psych (>= 3.1.0)
55
+ rainbow (>= 2.2.2, < 4.0)
56
+ ruby-progressbar (~> 1.7)
57
+ unicode-display_width (>= 1.4.0, < 1.6)
58
+ ruby-progressbar (1.10.0)
59
+ safe_yaml (1.0.5)
60
+ strict_open_struct (0.0.2.0)
61
+ unicode-display_width (1.5.0)
62
+ webmock (3.5.1)
63
+ addressable (>= 2.3.6)
64
+ crack (>= 0.3.2)
65
+ hashdiff
66
+
67
+ PLATFORMS
68
+ ruby
69
+
70
+ DEPENDENCIES
71
+ bundler (~> 2.0)
72
+ faker (~> 1.9)
73
+ fitbark!
74
+ rake (~> 10.0)
75
+ rspec (~> 3.0)
76
+ rubocop (~> 0.63)
77
+ webmock (~> 3.5)
78
+
79
+ BUNDLED WITH
80
+ 2.0.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 NatyDev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,194 @@
1
+ ![](https://inch-ci.org/github/natydev/fitbark.svg?branch=master&amp;style=flat)
2
+ [![Build Status](https://travis-ci.org/natydev/fitbark.png?branch=master)](https://travis-ci.org/natydev/fitbark)
3
+ [![Maintainability](https://api.codeclimate.com/v1/badges/20bcd9a6380363916f5e/maintainability)](https://codeclimate.com/github/natydev/fitbark/maintainability)
4
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/20bcd9a6380363916f5e/test_coverage)](https://codeclimate.com/github/natydev/fitbark/test_coverage)
5
+ [![Gem Version](https://badge.fury.io/rb/fitbark.svg)](https://badge.fury.io/rb/fitbark)
6
+
7
+
8
+ # FitBark
9
+
10
+ A Ruby interface to the FitBark® API.
11
+
12
+ * website: [https://www.fitbark.com](https://www.fitbark.com)
13
+ * API documentation: [https://www.fitbark.com/dev/](https://www.fitbark.com/dev/)
14
+
15
+ Using this **gem** you will **benefit** from the following **advantages** over the FitBark's source API (which unfortunately does not fully follow the REST good practices):
16
+
17
+ * Consistency in the nomenclature (ex: collections named as plural, single objects as singular, standardized key params in different methods/calls).
18
+ * Items as real specific objects.
19
+ * Attribute value received according to the right type (`String`, `Integer`, `Time`, `Date` ...).
20
+ * Attibutes aliases with ruby-friendly nomenclature (ex: `*_at` for time values, `*_on` for dates, `*?` for predicates, etc.)
21
+
22
+
23
+ ## Installation
24
+
25
+ Add this line to your application's Gemfile:
26
+
27
+ ```ruby
28
+ gem 'fitbark'
29
+ ```
30
+
31
+ And then execute:
32
+
33
+ $ bundle
34
+
35
+ Or install it yourself as:
36
+
37
+ $ gem install fitbark
38
+
39
+
40
+ ## Usage examples
41
+
42
+ First of all, to use this gem you need to register inside FitBark's website for a FitBark Developer Application.
43
+
44
+ Once you have the `client_id` and `client_secret` you can start to use FitBark's API.
45
+
46
+ ### Authentication
47
+
48
+ First step: in Terminal open `irb` or rails `console`, then generate an **authorization uri**:
49
+
50
+ ```ruby
51
+ require 'fitbark'
52
+
53
+ client_id = 'CLIENT-ID-PROVIDED-BY-FITBARK'
54
+ client_secret = 'CLIENT-SECRET-PROVIDED-BY-FITBARK'
55
+ redirect_uri = 'urn:ietf:wg:oauth:2.0:oob'
56
+
57
+ auth = Fitbark::Auth.new(client_id: client_id, redirect_uri: redirect_uri)
58
+ auth.authorization_uri
59
+ ```
60
+ Second step: open/redirect your browser to authorization uri, a prompt for a **user login** will appear, once the login is done an **authorization code** can be fetched from success redirection (in the uri or html).
61
+
62
+ Third step: retieve **access token**:
63
+
64
+ ```ruby
65
+ authorization_code = '27e5dd1307cddc7b5d8d72264ef1...'
66
+
67
+ auth = Fitbark::Auth.new(client_id: client_id, redirect_uri: redirect_uri,
68
+ code: authorization_code, client_secret: client_secret)
69
+ data_token = auth.fetch_access_token!
70
+ ```
71
+
72
+ #### Fitbark::Auth #fetch\_access\_token!
73
+
74
+ Returns an object kind `Fitbark::Data::Token` having this properties:
75
+
76
+ - **token**: the access token string.
77
+ - **type**: access token's typology.
78
+ - **expires_at**: a time based on the expires_in attribute.
79
+ - **scopes**: an array of scopes
80
+
81
+ ### Interface
82
+
83
+ With `Fitbark::Client` we interact with API endpoints calling the specific methods.
84
+ To use a client it must be initialized with a token:
85
+
86
+ ```ruby
87
+ client = Fitbark::Client.new(token: data_token.token)
88
+ ```
89
+
90
+ logged user informations:
91
+
92
+ ```ruby
93
+ user = client.user_info
94
+ # returns an object Fitbark::Data::UserInfo
95
+ ```
96
+
97
+ user's picture:
98
+
99
+ ```ruby
100
+ client.user_picture(user_slug: user.slug)
101
+ # returns an object Fitbark::Data::PictureInfo
102
+ ```
103
+
104
+ all dogs owned by logged user:
105
+
106
+ ```ruby
107
+ client.own_dogs
108
+ # returns an array of Fitbark::Data::DogInfo
109
+ ```
110
+
111
+ all dogs having friendship with logged user:
112
+
113
+ ```ruby
114
+ client.friend_dogs
115
+ # returns an array of Fitbark::Data::DogInfo
116
+ ```
117
+
118
+ choice a dog from my owned dogs:
119
+
120
+ ```ruby
121
+ my_dog = client.own_dogs.first
122
+ # returns an object Fitbark::Data::DogInfo
123
+ ```
124
+
125
+ retrieve a dog's picture:
126
+
127
+ ```ruby
128
+ client.dog_picture(dog_slug: my_dog.slug)
129
+ # returns an object Fitbark::Data::PictureInfo
130
+ ```
131
+
132
+ retrieve daily activity series (in a selected date range):
133
+
134
+ ```ruby
135
+ client.activity_series(dog_slug: my_dog.slug,
136
+ from: 7.days.ago, to: Date.today, resolution: :daily)
137
+ # returns an array of Fitbark::Data::ActivityDaily
138
+ ```
139
+
140
+ hourly activity series (in a selected date range):
141
+
142
+ ```ruby
143
+ client.activity_series(dog_slug: my_dog.slug,
144
+ from: 3.days.ago, to: Date.today, resolution: :hourly)
145
+ # returns an array of Fitbark::Data::ActivityHourly
146
+ ```
147
+
148
+ total activity points (in a selected date range):
149
+
150
+ ```ruby
151
+ client.activity_total(dog_slug: my_dog.slug, from: 20.days.ago, to: Date.today)
152
+ # returns an Integer
153
+ ```
154
+
155
+ statistics about similar dogs:
156
+
157
+ ```ruby
158
+ client.similar_dogs_stats(dog_slug: my_dog.slug)
159
+ # returns a Fitbark::Data::SimilarDogsStat object
160
+ ```
161
+
162
+ time breakdown:
163
+
164
+ ```ruby
165
+ client.time_breakdown(dog_slug: my_dog.slug, from: 20.days.ago, to: Date.today)
166
+ # returns a Fitbark::Data::ActivityLevel object
167
+ ```
168
+
169
+ For complete documentation about all client's methods and all attributes for returned data objects please read the following section.
170
+
171
+
172
+ ## Documentation
173
+
174
+ If you clone this repository in your local machine, complete documentation abount all classes and modules can be make in terminal with the command **rdoc** (from project's root directory).
175
+
176
+ $ rdoc
177
+
178
+
179
+ ## Tests
180
+
181
+ Run tests with **rspec** (from project's root directory) in Terminal:
182
+
183
+ $ bundle exec rspec
184
+
185
+
186
+
187
+ ## Contributing
188
+
189
+ Bug reports and pull requests are welcome on GitHub at https://github.com/natydev/fitbark. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
190
+
191
+
192
+ ## License
193
+
194
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'fitbark'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)