oura 0.1.1 → 0.1.2

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: 1cf18722f90faf6d2b0d1acce65578d0dbb30010b6f988ff653c49aa71966c68
4
- data.tar.gz: 2b77f9ee865df714c3873ddca410034cc2c7dfea4fe40d962ac44b858c2bfa7a
3
+ metadata.gz: 2845af3c9e89fbd8e210bbeb5445c34dc7e925564ce9b9ab170010a7b1e2db72
4
+ data.tar.gz: 1828efd8469eee2115025fb3a34beb60517167bc617a9e28862336cb1017fa04
5
5
  SHA512:
6
- metadata.gz: 722dd141536d78da2ca46dbcc4a9eab3621dbc78d679fce15f96c15568cb9c4e51020c652978f43801c9e93462fea3e81cf76c51426cb0255c53cf78ab439081
7
- data.tar.gz: 562ef9f29cfa19282696c4f12583542043d6533589edcc93cb8529a12bf6de5ac16e4f56e69bcbdbb4c98b0f02f71a120681ff2d4d235645038ac19fbac03a31
6
+ metadata.gz: 218f859ab28ecb3576267bcb5cebb896fe4f1d8ca8e7f91b32beb31142b1bdef16191510e1a9698ae50c25d11bdf424dea541e0a061651db7ac827e6428f6d3e
7
+ data.tar.gz: f37c6d6bc9275bcdb86e8dc00986c35c2ebfce1957f13c171ccf8dc406e2ca163630e4ba318faf35dc122aac07ca57795142c977c0744cd055198c46d2af3da7
@@ -19,3 +19,6 @@ Metrics/LineLength:
19
19
 
20
20
  Metrics/MethodLength:
21
21
  Max: 15
22
+
23
+ RSpec/MultipleExpectations:
24
+ Enabled: false
@@ -1,6 +1,10 @@
1
1
  Change Log
2
2
  ===
3
3
 
4
+ ## v0.1.2
5
+
6
+ - Capsulize ( Add apis module )
7
+
4
8
  ## v0.1.1
5
9
 
6
10
  - development mode
data/README.md CHANGED
@@ -29,7 +29,7 @@ Or install it yourself as:
29
29
 
30
30
  ```irb
31
31
  $ DEVELOPMENT=true bundle console
32
- $ client = Oura::Client.new(access_token: your_token)
32
+ $ client = ::Oura::Client.new(access_token: your_token)
33
33
  $ # <input your code>
34
34
  $ response = client.user_info # or sleep_period, activity, readiness
35
35
  $ response.body
@@ -38,12 +38,27 @@ $ => "{\"weight\": 50, \"age\": 22, \"gender\": \"male\", \"email\": \"oura@exam
38
38
 
39
39
  ### not in develop-mode
40
40
 
41
+ #### Set Environment
42
+
43
+ |Environment|Explanation|
44
+ |:---:|:---:|
45
+ | `OURA_CLIENT_ID` | client id |
46
+ | `OURA_CLEINT_SECRET` | client secret |
47
+ | `AUTHORIZE_HEADER_CODE` | authrize header code |
48
+ | `OURA_CALLBACK_URI` | callback uri |
49
+
50
+
41
51
  ```bash
42
52
  $ bundle console
43
- $ > client = Oura::Client.new(access_token: <your token>)
53
+ $ > client = ::Oura::Client.new(access_token: <your token>)
44
54
  $ > client.user_info # or sleep_period, activity, readiness
45
55
  ```
46
56
 
57
+ ## References
58
+
59
+ - [Official Site](https://ouraring.com/)
60
+ - [API Document](https://cloud.ouraring.com/docs/)
61
+
47
62
  ## Development
48
63
 
49
64
  After checking out the repo, run `bin/setup` to install dependencies.
@@ -3,6 +3,8 @@
3
3
  require 'oura/version'
4
4
  require 'oura/constants'
5
5
  require 'oura/client'
6
+ require 'active_support'
7
+ require 'active_support/core_ext'
6
8
 
7
9
  module Oura
8
10
  class Error < StandardError; end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'oura/utils/api'
4
+
5
+ module Oura
6
+ module Apis
7
+ # Activity summary contains daily activity summary values and detailed activity levels.
8
+ module Activity
9
+ include ::Oura::Api
10
+
11
+ REQUEST_PATH = '/v1/activity'
12
+
13
+ # @param [Date] start_date
14
+ # @param [Date] end_date
15
+ # @example
16
+ # {
17
+ # "activity": [{"summary_date": "2016-10-11", ...}, {"summary_date": "2016-10-12", ...}, ...]
18
+ # }
19
+ # @return [OAuth2::Response]
20
+ def activity(start_date:, end_date:)
21
+ sdate, edate = [start_date, end_date].map { |date| transform_date(date) }
22
+ get(REQUEST_PATH, params: { start: sdate, end: edate })
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'oura/utils/api'
4
+
5
+ module Oura
6
+ module Apis
7
+ # Readiness tells how ready you are for the day.
8
+ # example data
9
+ # {
10
+ # "readiness": {
11
+ # "summary_date": "2016-09-03",
12
+ # "period_id": 0,
13
+ # "score": 62,
14
+ # "score_previous_night": 5,
15
+ # "score_sleep_balance": 75,
16
+ # "score_previous_day": 61,
17
+ # "score_activity_balance": 77,
18
+ # "score_resting_hr": 98,
19
+ # "score_recovery_index": 45,
20
+ # "score_temperature": 86
21
+ # }
22
+ # }
23
+ module Readiness
24
+ include ::Oura::Api
25
+
26
+ REQUEST_PATH = '/v1/readiness'
27
+
28
+ # @param [Date] start_date
29
+ # @param [Date] end_date
30
+ # @example
31
+ # {
32
+ # "readiness": [{"summary_date": "2016-10-11", ...}, {"summary_date": "2016-10-12", ...}, ...]
33
+ # }
34
+ # @return [OAuth2::Response]
35
+ def readiness(start_date:, end_date:)
36
+ sdate, edate = [start_date, end_date].map { |date| transform_date(date) }
37
+ get(REQUEST_PATH, params: { start: sdate, end: edate })
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'oura/utils/api'
4
+
5
+ module Oura
6
+ module Apis
7
+ # SleepPeriod is a nearly continuous, longish period of time spent lying down in bed.
8
+ module SleepPeriod
9
+ include ::Oura::Api
10
+
11
+ REQUEST_PATH = '/v1/sleep'
12
+
13
+ # @param [Date] start_date
14
+ # @param [Date] end_date
15
+ # example response
16
+ # {
17
+ # "sleep": [{"summary_date": "2016-10-11", ...}, {"summary_date": "2016-10-12", ...}, ...]
18
+ # }
19
+ # @return [OAuth2::Response]
20
+ def sleep_period(start_date:, end_date:)
21
+ sdate, edate = [start_date, end_date].map { |date| transform_date(date) }
22
+ get(REQUEST_PATH, params: { start: sdate, end: edate })
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'oura/utils/api'
4
+
5
+ module Oura
6
+ module Apis
7
+ # UserInformation is user information.
8
+ module UserInformation
9
+ include ::Oura::Api
10
+
11
+ REQUEST_PATH = '/v1/userinfo'
12
+ # @example
13
+ # {
14
+ # "age": 27,
15
+ # "weight": 80,
16
+ # "gender": "male",
17
+ # "email": "john.doe@the.domain"
18
+ # }
19
+ # @return [OAuth2::Response]
20
+ def userinfo
21
+ get(REQUEST_PATH)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,20 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'oauth2'
4
+ require 'oura/apis/user_information'
5
+ require 'oura/apis/activity'
6
+ require 'oura/apis/sleep_period'
7
+ require 'oura/apis/readiness'
8
+
4
9
  module Oura
5
- # Oura::Client is client class.
10
+ # ::Oura::Client is client class.
6
11
  class Client
12
+ include ::Oura::Apis::UserInformation
13
+ include ::Oura::Apis::SleepPeriod
14
+ include ::Oura::Apis::Activity
15
+ include ::Oura::Apis::Readiness
16
+
7
17
  attr_reader :access_token, :oauth_client
8
18
 
19
+ # @param [String] access_token
20
+ # @return [Object<Oura::Client>]
9
21
  def initialize(access_token: nil)
10
22
  @oauth_client = OAuth2::Client.new(
11
- ENV['OURA_CLIENT_ID'],
12
- ENV['OURA_CLIENT_SECRET'],
13
- Oura::Constants::OAUTH_OPTIONS
23
+ ENV['OURA_CLIENT_ID'], ENV['OURA_CLIENT_SECRET'], ::Oura::Constants::OAUTH_OPTIONS
14
24
  )
15
-
16
25
  @access_token = if ENV['DEVELOPMENT']
17
- puts @oauth_client.auth_code.authorize_url(redirect_uri: ::Oura::Constants::CALLBACK_URL)
26
+ puts @oauth_client.auth_code.authorize_url(redirect_uri: ::Oura::Constants::CALLBACK_URI)
18
27
  puts 'Please, input your secret'
19
28
  code = gets.chomp
20
29
  token(code)
@@ -25,28 +34,16 @@ module Oura
25
34
  end
26
35
  end
27
36
 
37
+ private
38
+
39
+ # @param [String] code
40
+ # @return [OAuth2::AccessToken]
28
41
  def token(code)
29
42
  @oauth_client.auth_code.get_token(
30
43
  code,
31
- redirect_uri: ::Oura::Constants::CALLBACK_URL,
44
+ redirect_uri: ::Oura::Constants::CALLBACK_URI,
32
45
  headers: { 'Authorization' => "Bearer #{ENV['AUTHORIZE_HEADER_CODE']}" }
33
46
  )
34
47
  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
48
  end
52
49
  end
@@ -4,7 +4,7 @@ module Oura
4
4
  module Constants
5
5
  API_ENDPOINT = 'https://api.ouraring.com'
6
6
  OAUTH_ENDPOINT = 'https://cloud.ouraring.com'
7
- CALLBACK_URL = ENV['CALLBACK_URL'] || 'http://localhost:8080/oauth2/callback'
7
+ CALLBACK_URI = ENV['OURA_CALLBACK_URI'] || 'http://localhost:8080/oauth2/callback'
8
8
  OAUTH_OPTIONS = {
9
9
  authorize_url: "#{OAUTH_ENDPOINT}/oauth/authorize",
10
10
  token_url: "#{API_ENDPOINT}/oauth/token",
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Oura
4
+ class Base
5
+ # TODO: Implementation
6
+ end
7
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Oura
4
+ # ::Oura::Api is utility api module.
5
+ module Api
6
+ private
7
+
8
+ # @param [<String>] date
9
+ # @param [<Date>] date
10
+ # @return [String] date string
11
+ def transform_date(date)
12
+ return Date.parse(date).strftime('%Y-%m-%d') if date.is_a?(String)
13
+ return date.strftime('%Y-%m-%d') if date.is_a?(Date)
14
+
15
+ raise ArgumentError, 'invalid date'
16
+ end
17
+
18
+ # @param [String] path
19
+ # @param [Hash] params
20
+ # @return [OAuth2::Response]
21
+ def get(path, params = {})
22
+ @access_token.get(path, params)
23
+ end
24
+ end
25
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Oura
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
@@ -6,7 +6,7 @@ require 'oura/version'
6
6
 
7
7
  Gem::Specification.new do |spec|
8
8
  spec.name = 'oura'
9
- spec.version = Oura::VERSION
9
+ spec.version = ::Oura::VERSION
10
10
  spec.authors = ['Ryota Ikezawa']
11
11
  spec.email = ['pavegy@gmail.com']
12
12
 
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.require_paths = ['lib']
26
26
 
27
27
  spec.add_dependency 'oauth2'
28
+ spec.add_development_dependency 'activesupport'
28
29
  spec.add_development_dependency 'bundler', '~> 1.17'
29
30
  spec.add_development_dependency 'codecov'
30
31
  spec.add_development_dependency 'danger'
@@ -39,4 +40,6 @@ Gem::Specification.new do |spec|
39
40
  spec.add_development_dependency 'rubocop'
40
41
  spec.add_development_dependency 'rubocop-rspec'
41
42
  spec.add_development_dependency 'simplecov'
43
+ spec.add_development_dependency 'vcr'
44
+ spec.add_development_dependency 'webmock'
42
45
  end
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.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryota Ikezawa
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -220,6 +234,34 @@ dependencies:
220
234
  - - ">="
221
235
  - !ruby/object:Gem::Version
222
236
  version: '0'
237
+ - !ruby/object:Gem::Dependency
238
+ name: vcr
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - ">="
242
+ - !ruby/object:Gem::Version
243
+ version: '0'
244
+ type: :development
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - ">="
249
+ - !ruby/object:Gem::Version
250
+ version: '0'
251
+ - !ruby/object:Gem::Dependency
252
+ name: webmock
253
+ requirement: !ruby/object:Gem::Requirement
254
+ requirements:
255
+ - - ">="
256
+ - !ruby/object:Gem::Version
257
+ version: '0'
258
+ type: :development
259
+ prerelease: false
260
+ version_requirements: !ruby/object:Gem::Requirement
261
+ requirements:
262
+ - - ">="
263
+ - !ruby/object:Gem::Version
264
+ version: '0'
223
265
  description: unofficial API client of oura-cloud for ruby.
224
266
  email:
225
267
  - pavegy@gmail.com
@@ -242,8 +284,14 @@ files:
242
284
  - bin/console
243
285
  - bin/setup
244
286
  - lib/oura.rb
287
+ - lib/oura/apis/activity.rb
288
+ - lib/oura/apis/readiness.rb
289
+ - lib/oura/apis/sleep_period.rb
290
+ - lib/oura/apis/user_information.rb
245
291
  - lib/oura/client.rb
246
292
  - lib/oura/constants.rb
293
+ - lib/oura/model/base.rb
294
+ - lib/oura/utils/api.rb
247
295
  - lib/oura/version.rb
248
296
  - oura.gemspec
249
297
  homepage: https://github.com/paveg/oura