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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4e2ce70792c020cdd3cccf7c3d16f1d358af5bdb161642b79babc4ffd1aaa150
4
- data.tar.gz: a24a451ca25028907fd064b4843cbe9b8eacc97e2d9d5bbe427145371df9d855
3
+ metadata.gz: 1cf18722f90faf6d2b0d1acce65578d0dbb30010b6f988ff653c49aa71966c68
4
+ data.tar.gz: 2b77f9ee865df714c3873ddca410034cc2c7dfea4fe40d962ac44b858c2bfa7a
5
5
  SHA512:
6
- metadata.gz: 945ab3d6f7def1872f0ba438acd1c784f13fb2ae11877b5899875147b605bee0df42c1a5e74f7e2ada141017628ac236dc14178e632d7ba6d7566c4fe77c7b63
7
- data.tar.gz: 12fa4035cc165143126f7eddda47b8f5910562e9d9f1273747a35a0b54e992d3ad21478ff372130d807149835a95e07707d4a802b1bc25d16a8a806706bb11d4
6
+ metadata.gz: 722dd141536d78da2ca46dbcc4a9eab3621dbc78d679fce15f96c15568cb9c4e51020c652978f43801c9e93462fea3e81cf76c51426cb0255c53cf78ab439081
7
+ data.tar.gz: 562ef9f29cfa19282696c4f12583542043d6533589edcc93cb8529a12bf6de5ac16e4f56e69bcbdbb4c98b0f02f71a120681ff2d4d235645038ac19fbac03a31
@@ -16,3 +16,6 @@ Metrics/LineLength:
16
16
  Max: 120
17
17
  Exclude:
18
18
  - 'spec/**/*'
19
+
20
+ Metrics/MethodLength:
21
+ Max: 15
@@ -0,0 +1,6 @@
1
+ Change Log
2
+ ===
3
+
4
+ ## v0.1.1
5
+
6
+ - development mode
data/README.md CHANGED
@@ -25,17 +25,42 @@ Or install it yourself as:
25
25
 
26
26
  ## Usage
27
27
 
28
- TODO: Write usage instructions here
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. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
49
+ After checking out the repo, run `bin/setup` to install dependencies.
33
50
 
34
- To install this gem onto your local machine, run `bundle exec rake install`. 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).
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/[USERNAME]/oura. 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.
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
 
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'oura/version'
4
+ require 'oura/constants'
5
+ require 'oura/client'
4
6
 
5
7
  module Oura
6
8
  class Error < StandardError; end
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Oura
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
@@ -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.0
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