oura 0.1.0 → 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 +4 -4
- data/.rubocop.yml +3 -0
- data/CHANGELOG.md +6 -0
- data/README.md +29 -4
- data/lib/oura.rb +2 -0
- data/lib/oura/client.rb +52 -0
- data/lib/oura/constants.rb +14 -0
- data/lib/oura/version.rb +1 -1
- data/oura.gemspec +1 -0
- metadata +17 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1cf18722f90faf6d2b0d1acce65578d0dbb30010b6f988ff653c49aa71966c68
|
4
|
+
data.tar.gz: 2b77f9ee865df714c3873ddca410034cc2c7dfea4fe40d962ac44b858c2bfa7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 722dd141536d78da2ca46dbcc4a9eab3621dbc78d679fce15f96c15568cb9c4e51020c652978f43801c9e93462fea3e81cf76c51426cb0255c53cf78ab439081
|
7
|
+
data.tar.gz: 562ef9f29cfa19282696c4f12583542043d6533589edcc93cb8529a12bf6de5ac16e4f56e69bcbdbb4c98b0f02f71a120681ff2d4d235645038ac19fbac03a31
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -25,17 +25,42 @@ Or install it yourself as:
|
|
25
25
|
|
26
26
|
## Usage
|
27
27
|
|
28
|
-
|
28
|
+
### in develop-mode
|
29
|
+
|
30
|
+
```irb
|
31
|
+
$ DEVELOPMENT=true bundle console
|
32
|
+
$ client = Oura::Client.new(access_token: your_token)
|
33
|
+
$ # <input your code>
|
34
|
+
$ response = client.user_info # or sleep_period, activity, readiness
|
35
|
+
$ response.body
|
36
|
+
$ => "{\"weight\": 50, \"age\": 22, \"gender\": \"male\", \"email\": \"oura@example.com\", \"user_id\": \"XXXXXXXX\", \"height\": 170, \"date\": \"2019-02-03\"}"
|
37
|
+
```
|
38
|
+
|
39
|
+
### not in develop-mode
|
40
|
+
|
41
|
+
```bash
|
42
|
+
$ bundle console
|
43
|
+
$ > client = Oura::Client.new(access_token: <your token>)
|
44
|
+
$ > client.user_info # or sleep_period, activity, readiness
|
45
|
+
```
|
29
46
|
|
30
47
|
## Development
|
31
48
|
|
32
|
-
After checking out the repo, run `bin/setup` to install dependencies.
|
49
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
33
50
|
|
34
|
-
|
51
|
+
Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
52
|
+
|
53
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
54
|
+
|
55
|
+
To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
35
56
|
|
36
57
|
## Contributing
|
37
58
|
|
38
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
59
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/paveg/oura.
|
60
|
+
|
61
|
+
This project is intended to be a safe, welcoming space for collaboration,
|
62
|
+
|
63
|
+
and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
39
64
|
|
40
65
|
## License
|
41
66
|
|
data/lib/oura.rb
CHANGED
data/lib/oura/client.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'oauth2'
|
4
|
+
module Oura
|
5
|
+
# Oura::Client is client class.
|
6
|
+
class Client
|
7
|
+
attr_reader :access_token, :oauth_client
|
8
|
+
|
9
|
+
def initialize(access_token: nil)
|
10
|
+
@oauth_client = OAuth2::Client.new(
|
11
|
+
ENV['OURA_CLIENT_ID'],
|
12
|
+
ENV['OURA_CLIENT_SECRET'],
|
13
|
+
Oura::Constants::OAUTH_OPTIONS
|
14
|
+
)
|
15
|
+
|
16
|
+
@access_token = if ENV['DEVELOPMENT']
|
17
|
+
puts @oauth_client.auth_code.authorize_url(redirect_uri: ::Oura::Constants::CALLBACK_URL)
|
18
|
+
puts 'Please, input your secret'
|
19
|
+
code = gets.chomp
|
20
|
+
token(code)
|
21
|
+
else
|
22
|
+
raise if access_token.nil?
|
23
|
+
|
24
|
+
OAuth2::AccessToken.new(@oauth_client, access_token)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def token(code)
|
29
|
+
@oauth_client.auth_code.get_token(
|
30
|
+
code,
|
31
|
+
redirect_uri: ::Oura::Constants::CALLBACK_URL,
|
32
|
+
headers: { 'Authorization' => "Bearer #{ENV['AUTHORIZE_HEADER_CODE']}" }
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
def user_info
|
37
|
+
@access_token.get('/v1/userinfo')
|
38
|
+
end
|
39
|
+
|
40
|
+
def sleep_period(start_date:, end_date:)
|
41
|
+
@access_token.get('/v1/sleep', params: { start: start_date.to_s, end: end_date.to_s })
|
42
|
+
end
|
43
|
+
|
44
|
+
def activity(start_date:, end_date:)
|
45
|
+
@access_token.get('/v1/activity', params: { start: start_date.to_s, end: end_date.to_s })
|
46
|
+
end
|
47
|
+
|
48
|
+
def readiness(start_date:, end_date:)
|
49
|
+
@access_token.get('/v1/readiness', params: { start: start_date.to_s, end: end_date.to_s })
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Oura
|
4
|
+
module Constants
|
5
|
+
API_ENDPOINT = 'https://api.ouraring.com'
|
6
|
+
OAUTH_ENDPOINT = 'https://cloud.ouraring.com'
|
7
|
+
CALLBACK_URL = ENV['CALLBACK_URL'] || 'http://localhost:8080/oauth2/callback'
|
8
|
+
OAUTH_OPTIONS = {
|
9
|
+
authorize_url: "#{OAUTH_ENDPOINT}/oauth/authorize",
|
10
|
+
token_url: "#{API_ENDPOINT}/oauth/token",
|
11
|
+
site: API_ENDPOINT
|
12
|
+
}.freeze
|
13
|
+
end
|
14
|
+
end
|
data/lib/oura/version.rb
CHANGED
data/oura.gemspec
CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
25
|
spec.require_paths = ['lib']
|
26
26
|
|
27
|
+
spec.add_dependency 'oauth2'
|
27
28
|
spec.add_development_dependency 'bundler', '~> 1.17'
|
28
29
|
spec.add_development_dependency 'codecov'
|
29
30
|
spec.add_development_dependency 'danger'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oura
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryota Ikezawa
|
@@ -10,6 +10,20 @@ bindir: exe
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2019-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: oauth2
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -228,6 +242,8 @@ files:
|
|
228
242
|
- bin/console
|
229
243
|
- bin/setup
|
230
244
|
- lib/oura.rb
|
245
|
+
- lib/oura/client.rb
|
246
|
+
- lib/oura/constants.rb
|
231
247
|
- lib/oura/version.rb
|
232
248
|
- oura.gemspec
|
233
249
|
homepage: https://github.com/paveg/oura
|