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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2845af3c9e89fbd8e210bbeb5445c34dc7e925564ce9b9ab170010a7b1e2db72
4
- data.tar.gz: 1828efd8469eee2115025fb3a34beb60517167bc617a9e28862336cb1017fa04
3
+ metadata.gz: 7919509104715a2159f26ce292e6348cc421b35c344b526e14a9e493648d38f9
4
+ data.tar.gz: 89ff63d40bcb760185905bfc5f91e079e9c27e232f3778a4b74b365900449624
5
5
  SHA512:
6
- metadata.gz: 218f859ab28ecb3576267bcb5cebb896fe4f1d8ca8e7f91b32beb31142b1bdef16191510e1a9698ae50c25d11bdf424dea541e0a061651db7ac827e6428f6d3e
7
- data.tar.gz: f37c6d6bc9275bcdb86e8dc00986c35c2ebfce1957f13c171ccf8dc406e2ca163630e4ba318faf35dc122aac07ca57795142c977c0744cd055198c46d2af3da7
6
+ metadata.gz: 7dcb0169c2e24abe90ff5d835214f6b7b67953e14fe62453ad2acd1171d50766ab4c05559f6ff9d42ec7afb4dff08f8b7ea1aacdad9482d09fc8e172067e7861
7
+ data.tar.gz: 47d5cb53a272acba517a0390c5147b0c06536b148b733945a147368786017546eaa10b4e18e62201f97449081cbacce9a3665792e9fe2a2ca70498ac011b7b39
@@ -22,3 +22,9 @@ Metrics/MethodLength:
22
22
 
23
23
  RSpec/MultipleExpectations:
24
24
  Enabled: false
25
+
26
+ Style/DoubleNegation:
27
+ Enabled: false
28
+
29
+ RSpec/NamedSubject:
30
+ Enabled: false
@@ -1,6 +1,15 @@
1
1
  Change Log
2
2
  ===
3
3
 
4
+ ## v0.1.3
5
+
6
+ - Add Model
7
+
8
+ - Oura::Model::UserInformation
9
+ - Oura::Model::SleepPeriod
10
+ - Oura::Model::Activity
11
+ - Oura::Model::Readiness
12
+
4
13
  ## v0.1.2
5
14
 
6
15
  - Capsulize ( Add apis module )
data/README.md CHANGED
@@ -27,13 +27,12 @@ Or install it yourself as:
27
27
 
28
28
  ### in develop-mode
29
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\"}"
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
- ```bash
52
- $ bundle console
53
- $ > client = ::Oura::Client.new(access_token: <your token>)
54
- $ > client.user_info # or sleep_period, activity, readiness
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
@@ -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
@@ -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 [OAuth2::Response]
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
@@ -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 [OAuth2::Response]
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 [OAuth2::Response]
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 [OAuth2::Response]
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
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'oura/model/base'
4
+ module Oura
5
+ module Model
6
+ # Oura::Mode::Activity is Activity Model.
7
+ class Activity < ::Oura::Model::Base
8
+ attr_reader :activity
9
+ end
10
+ end
11
+ end
@@ -1,7 +1,60 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Oura
4
- class Base
5
- # TODO: Implementation
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,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'oura/model/base'
4
+ module Oura
5
+ module Model
6
+ # Oura::Mode::Readiness is Readiness Model.
7
+ class Readiness < ::Oura::Model::Base
8
+ attr_reader :readiness
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'oura/model/base'
4
+ module Oura
5
+ module Model
6
+ # Oura::Mode::SleepPeriod is SleepPeriod Model.
7
+ class SleepPeriod < ::Oura::Model::Base
8
+ attr_reader :sleep
9
+ end
10
+ end
11
+ 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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Oura
4
- VERSION = '0.1.2'
4
+ VERSION = '0.1.3'
5
5
  end
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.2
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-03 00:00:00.000000000 Z
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