oura 0.1.2 → 0.1.3
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 +6 -0
- data/CHANGELOG.md +9 -0
- data/README.md +23 -11
- data/lib/oura.rb +5 -0
- data/lib/oura/apis/activity.rb +6 -3
- data/lib/oura/apis/readiness.rb +6 -3
- data/lib/oura/apis/sleep_period.rb +6 -3
- data/lib/oura/apis/user_information.rb +6 -3
- data/lib/oura/model/activity.rb +11 -0
- data/lib/oura/model/base.rb +55 -2
- data/lib/oura/model/readiness.rb +11 -0
- data/lib/oura/model/sleep_period.rb +11 -0
- data/lib/oura/model/user_information.rb +12 -0
- data/lib/oura/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7919509104715a2159f26ce292e6348cc421b35c344b526e14a9e493648d38f9
|
4
|
+
data.tar.gz: 89ff63d40bcb760185905bfc5f91e079e9c27e232f3778a4b74b365900449624
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7dcb0169c2e24abe90ff5d835214f6b7b67953e14fe62453ad2acd1171d50766ab4c05559f6ff9d42ec7afb4dff08f8b7ea1aacdad9482d09fc8e172067e7861
|
7
|
+
data.tar.gz: 47d5cb53a272acba517a0390c5147b0c06536b148b733945a147368786017546eaa10b4e18e62201f97449081cbacce9a3665792e9fe2a2ca70498ac011b7b39
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -27,13 +27,12 @@ Or install it yourself as:
|
|
27
27
|
|
28
28
|
### in develop-mode
|
29
29
|
|
30
|
-
```
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
$ => "{\"weight\": 50, \"age\": 22, \"gender\": \"male\", \"email\": \"oura@example.com\", \"user_id\": \"XXXXXXXX\", \"height\": 170, \"date\": \"2019-02-03\"}"
|
30
|
+
```ruby
|
31
|
+
# DEVELOPMENT=true bundle console
|
32
|
+
client = ::Oura::Client.new(access_token: your_token)
|
33
|
+
# input your code
|
34
|
+
client.userinfo
|
35
|
+
=> #<Oura::Model::UserInformation:0x00007fc2492e59d8>
|
37
36
|
```
|
38
37
|
|
39
38
|
### not in develop-mode
|
@@ -48,10 +47,23 @@ $ => "{\"weight\": 50, \"age\": 22, \"gender\": \"male\", \"email\": \"oura@exam
|
|
48
47
|
| `OURA_CALLBACK_URI` | callback uri |
|
49
48
|
|
50
49
|
|
51
|
-
```
|
52
|
-
|
53
|
-
|
54
|
-
|
50
|
+
```ruby
|
51
|
+
# bundle console
|
52
|
+
client = ::Oura::Client.new(access_token: your_token)
|
53
|
+
client.userinfo
|
54
|
+
=> #<Oura::Model::UserInformation:0x00007fc2492e59d8
|
55
|
+
@attrs=
|
56
|
+
{:weight=>64,
|
57
|
+
:age=>27,
|
58
|
+
:gender=>"male",
|
59
|
+
:email=>"example@gmail.com",
|
60
|
+
:user_id=>"XXXXXX",
|
61
|
+
:height=>170,
|
62
|
+
:date=>"2019-02-03"}>
|
63
|
+
|
64
|
+
# client.sleep_period(start_date: 2.days.ago, end_date: Date.doday)
|
65
|
+
# client.activity(start_date: 2.days.ago, end_date: Date.doday)
|
66
|
+
# client.readiness(start_date: 2.days.ago, end_date: Date.doday)
|
55
67
|
```
|
56
68
|
|
57
69
|
## References
|
data/lib/oura.rb
CHANGED
@@ -5,6 +5,11 @@ require 'oura/constants'
|
|
5
5
|
require 'oura/client'
|
6
6
|
require 'active_support'
|
7
7
|
require 'active_support/core_ext'
|
8
|
+
require 'oura/model/base'
|
9
|
+
require 'oura/model/user_information'
|
10
|
+
require 'oura/model/activity'
|
11
|
+
require 'oura/model/sleep_period'
|
12
|
+
require 'oura/model/readiness'
|
8
13
|
|
9
14
|
module Oura
|
10
15
|
class Error < StandardError; end
|
data/lib/oura/apis/activity.rb
CHANGED
@@ -12,14 +12,17 @@ module Oura
|
|
12
12
|
|
13
13
|
# @param [Date] start_date
|
14
14
|
# @param [Date] end_date
|
15
|
-
# @example
|
15
|
+
# @example response body
|
16
16
|
# {
|
17
17
|
# "activity": [{"summary_date": "2016-10-11", ...}, {"summary_date": "2016-10-12", ...}, ...]
|
18
18
|
# }
|
19
|
-
# @return [
|
19
|
+
# @return [Oura::Model::Activity]
|
20
20
|
def activity(start_date:, end_date:)
|
21
21
|
sdate, edate = [start_date, end_date].map { |date| transform_date(date) }
|
22
|
-
get(REQUEST_PATH, params: { start: sdate, end: edate })
|
22
|
+
response_body = get(REQUEST_PATH, params: { start: sdate, end: edate }).body
|
23
|
+
symbolized_json = JSON.parse(response_body).deep_symbolize_keys
|
24
|
+
|
25
|
+
::Oura::Model::Activity.new(symbolized_json)
|
23
26
|
end
|
24
27
|
end
|
25
28
|
end
|
data/lib/oura/apis/readiness.rb
CHANGED
@@ -27,14 +27,17 @@ module Oura
|
|
27
27
|
|
28
28
|
# @param [Date] start_date
|
29
29
|
# @param [Date] end_date
|
30
|
-
# @example
|
30
|
+
# @example response body
|
31
31
|
# {
|
32
32
|
# "readiness": [{"summary_date": "2016-10-11", ...}, {"summary_date": "2016-10-12", ...}, ...]
|
33
33
|
# }
|
34
|
-
# @return [
|
34
|
+
# @return [Oura::Model::Readiness]
|
35
35
|
def readiness(start_date:, end_date:)
|
36
36
|
sdate, edate = [start_date, end_date].map { |date| transform_date(date) }
|
37
|
-
get(REQUEST_PATH, params: { start: sdate, end: edate })
|
37
|
+
response_body = get(REQUEST_PATH, params: { start: sdate, end: edate }).body
|
38
|
+
symbolized_json = JSON.parse(response_body).deep_symbolize_keys
|
39
|
+
|
40
|
+
::Oura::Model::Readiness.new(symbolized_json)
|
38
41
|
end
|
39
42
|
end
|
40
43
|
end
|
@@ -12,14 +12,17 @@ module Oura
|
|
12
12
|
|
13
13
|
# @param [Date] start_date
|
14
14
|
# @param [Date] end_date
|
15
|
-
# example response
|
15
|
+
# @example response body
|
16
16
|
# {
|
17
17
|
# "sleep": [{"summary_date": "2016-10-11", ...}, {"summary_date": "2016-10-12", ...}, ...]
|
18
18
|
# }
|
19
|
-
# @return [
|
19
|
+
# @return [Oura::Model::SleepPeriod]
|
20
20
|
def sleep_period(start_date:, end_date:)
|
21
21
|
sdate, edate = [start_date, end_date].map { |date| transform_date(date) }
|
22
|
-
get(REQUEST_PATH, params: { start: sdate, end: edate })
|
22
|
+
response_body = get(REQUEST_PATH, params: { start: sdate, end: edate }).body
|
23
|
+
symbolized_json = JSON.parse(response_body).deep_symbolize_keys
|
24
|
+
|
25
|
+
::Oura::Model::SleepPeriod.new(symbolized_json)
|
23
26
|
end
|
24
27
|
end
|
25
28
|
end
|
@@ -9,16 +9,19 @@ module Oura
|
|
9
9
|
include ::Oura::Api
|
10
10
|
|
11
11
|
REQUEST_PATH = '/v1/userinfo'
|
12
|
-
# @example
|
12
|
+
# @example response body
|
13
13
|
# {
|
14
14
|
# "age": 27,
|
15
15
|
# "weight": 80,
|
16
16
|
# "gender": "male",
|
17
17
|
# "email": "john.doe@the.domain"
|
18
18
|
# }
|
19
|
-
# @return [
|
19
|
+
# @return [Oura::Model::UserInformation]
|
20
20
|
def userinfo
|
21
|
-
get(REQUEST_PATH)
|
21
|
+
response_body = get(REQUEST_PATH).body
|
22
|
+
symbolized_json = JSON.parse(response_body).symbolize_keys
|
23
|
+
|
24
|
+
::Oura::Model::UserInformation.new(symbolized_json)
|
22
25
|
end
|
23
26
|
end
|
24
27
|
end
|
data/lib/oura/model/base.rb
CHANGED
@@ -1,7 +1,60 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Oura
|
4
|
-
|
5
|
-
#
|
4
|
+
module Model
|
5
|
+
# Oura::Mode::Base is base class for Model.
|
6
|
+
class Base
|
7
|
+
def self.attr_reader(*attrs)
|
8
|
+
mod = Module.new do
|
9
|
+
attrs.each do |attribute|
|
10
|
+
define_method attribute do
|
11
|
+
@attrs[attribute.to_sym]
|
12
|
+
end
|
13
|
+
define_method :"#{attribute}?" do
|
14
|
+
!!@attrs[attribute.to_sym]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
const_set(:Attributes, mod) unless defined? Attributes
|
19
|
+
include mod
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.object_from_response(response = {})
|
23
|
+
new(response[:body])
|
24
|
+
end
|
25
|
+
|
26
|
+
def initialize(attrs = {})
|
27
|
+
@attrs = attrs
|
28
|
+
end
|
29
|
+
|
30
|
+
def [](method)
|
31
|
+
send(method.to_sym)
|
32
|
+
rescue NoMethodError => e
|
33
|
+
puts e.inspect
|
34
|
+
end
|
35
|
+
|
36
|
+
attr_reader :attrs
|
37
|
+
alias to_hash attrs
|
38
|
+
|
39
|
+
def update(attrs)
|
40
|
+
@attrs.update(attrs)
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
protected
|
45
|
+
|
46
|
+
# @param attr [Symbol]
|
47
|
+
# @param other [Square::Base]
|
48
|
+
# @return [Boolean]
|
49
|
+
def attr_equal(attr, other)
|
50
|
+
self.class == other.class && !other.send(attr).nil? && send(attr) == other.send(attr)
|
51
|
+
end
|
52
|
+
|
53
|
+
# @param other [Square::Base]
|
54
|
+
# @return [Boolean]
|
55
|
+
def attrs_equal(other)
|
56
|
+
self.class == other.class && !other.attrs.empty? && attrs == other.attrs
|
57
|
+
end
|
58
|
+
end
|
6
59
|
end
|
7
60
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'oura/model/base'
|
4
|
+
|
5
|
+
module Oura
|
6
|
+
module Model
|
7
|
+
# Oura::Mode::UserInformation is UserInformation Model.
|
8
|
+
class UserInformation < ::Oura::Model::Base
|
9
|
+
attr_reader :gender, :weight, :height, :date, :user_id, :email, :age
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/oura/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryota Ikezawa
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oauth2
|
@@ -290,7 +290,11 @@ files:
|
|
290
290
|
- lib/oura/apis/user_information.rb
|
291
291
|
- lib/oura/client.rb
|
292
292
|
- lib/oura/constants.rb
|
293
|
+
- lib/oura/model/activity.rb
|
293
294
|
- lib/oura/model/base.rb
|
295
|
+
- lib/oura/model/readiness.rb
|
296
|
+
- lib/oura/model/sleep_period.rb
|
297
|
+
- lib/oura/model/user_information.rb
|
294
298
|
- lib/oura/utils/api.rb
|
295
299
|
- lib/oura/version.rb
|
296
300
|
- oura.gemspec
|