jawbone 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2013 by Andy Brett
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,6 @@
1
+ Ruby wrapper for the [Jawbone UP API](https://jawbone.com/up/developer/).
2
+
3
+ Once you've set up your app and have a token for your user:
4
+
5
+ client = Jawbone::Client.new "your_token"
6
+
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ desc "Run specs"
5
+ RSpec::Core::RakeTask.new
6
+
7
+ desc 'Default: run specs.'
8
+ task :default => :spec
@@ -0,0 +1,163 @@
1
+ require 'httparty'
2
+
3
+ module Jawbone
4
+
5
+ class Client
6
+
7
+ attr_accessor :token
8
+
9
+ API_VERSION = "1.0"
10
+
11
+ include HTTParty
12
+
13
+ def initialize(token)
14
+ @token = token
15
+ end
16
+
17
+ def user
18
+ response = self.class.get "https://jawbone.com/nudge/api/users/@me",
19
+ { :headers => { "Authorization" => "Bearer #{token}" } }
20
+ response.parsed_response
21
+ end
22
+
23
+ def friends
24
+ response = self.class.get "https://jawbone.com/nudge/api/users/@me/friends",
25
+ { :headers => { "Authorization" => "Bearer #{token}" } }
26
+ response.parsed_response
27
+ end
28
+
29
+ def trends
30
+ response = self.class.get "https://jawbone.com/nudge/api/users/@me/trends",
31
+ { :headers => { "Authorization" => "Bearer #{token}" } }
32
+ response.parsed_response
33
+ end
34
+
35
+ def moves
36
+ response = self.class.get "https://jawbone.com/nudge/api/users/@me/moves",
37
+ { :headers => { "Authorization" => "Bearer #{token}" } }
38
+ response.parsed_response
39
+ end
40
+
41
+ def move(move_id)
42
+ response = self.class.get "https://jawbone.com/nudge/api/users/@me/moves/#{move_id}",
43
+ { :headers => { "Authorization" => "Bearer #{token}" } }
44
+ response.parsed_response
45
+ end
46
+
47
+ def move_graph(move_id)
48
+ response = self.class.get "https://jawbone.com/nudge/api/users/@me/moves/#{move_id}/image",
49
+ { :headers => { "Authorization" => "Bearer #{token}" } }
50
+ response.parsed_response
51
+ end
52
+
53
+ def move_intensity(move_id)
54
+ response = self.class.get "https://jawbone.com/nudge/api/users/@me/moves/#{move_id}/snapshot",
55
+ { :headers => { "Authorization" => "Bearer #{token}" } }
56
+ response.parsed_response
57
+ end
58
+
59
+ def workouts
60
+ response = self.class.get "https://jawbone.com/nudge/api/users/@me/workouts",
61
+ { :headers => { "Authorization" => "Bearer #{token}" } }
62
+ response.parsed_response
63
+ end
64
+
65
+ def workout(workout_id)
66
+ response = self.class.get "https://jawbone.com/nudge/api/users/@me/workouts/#{workout_id}",
67
+ { :headers => { "Authorization" => "Bearer #{token}" } }
68
+ response.parsed_response
69
+ end
70
+
71
+ def workout_graph(workout_id)
72
+ response = self.class.get "https://jawbone.com/nudge/api/users/@me/workouts/#{workout_id}/image",
73
+ { :headers => { "Authorization" => "Bearer #{token}" } }
74
+ response.parsed_response
75
+ end
76
+
77
+ def workout_intensity(workout_id)
78
+ response = self.class.get "https://jawbone.com/nudge/api/users/@me/workouts/#{workout_id}/snapshot",
79
+ { :headers => { "Authorization" => "Bearer #{token}" } }
80
+ response.parsed_response
81
+ end
82
+
83
+ def sleeps
84
+ response = self.class.get "https://jawbone.com/nudge/api/users/@me/sleeps",
85
+ { :headers => { "Authorization" => "Bearer #{token}" } }
86
+ response.parsed_response
87
+ end
88
+
89
+ def sleep(sleep_id)
90
+ response = self.class.get "https://jawbone.com/nudge/api/users/@me/sleeps/#{sleep_id}",
91
+ { :headers => { "Authorization" => "Bearer #{token}" } }
92
+ response.parsed_response
93
+ end
94
+
95
+ def sleep_graph(sleep_id)
96
+ response = self.class.get "https://jawbone.com/nudge/api/users/@me/sleeps/#{sleep_id}/image",
97
+ { :headers => { "Authorization" => "Bearer #{token}" } }
98
+ response.parsed_response
99
+ end
100
+
101
+ def sleep_intensity(sleep_id)
102
+ response = self.class.get "https://jawbone.com/nudge/api/users/@me/sleeps/#{sleep_id}/snapshot",
103
+ { :headers => { "Authorization" => "Bearer #{token}" } }
104
+ response.parsed_response
105
+ end
106
+
107
+ def meals
108
+ response = self.class.get "https://jawbone.com/nudge/api/users/@me/meals",
109
+ { :headers => { "Authorization" => "Bearer #{token}" } }
110
+ response.parsed_response
111
+ end
112
+
113
+ def meal(meal_id)
114
+ response = self.class.get "https://jawbone.com/nudge/api/users/@me/meals/#{meal_id}",
115
+ { :headers => { "Authorization" => "Bearer #{token}" } }
116
+ response.parsed_response
117
+ end
118
+
119
+ def body_events
120
+ response = self.class.get "https://jawbone.com/nudge/api/users/@me/body_events",
121
+ { :headers => { "Authorization" => "Bearer #{token}" } }
122
+ response.parsed_response
123
+ end
124
+
125
+ def body_event(event_id)
126
+ response = self.class.get "https://jawbone.com/nudge/api/users/@me/body_event/#{event_id}",
127
+ { :headers => { "Authorization" => "Bearer #{token}" } }
128
+ response.parsed_response
129
+ end
130
+
131
+ def cardiac_events
132
+ response = self.class.get "https://jawbone.com/nudge/api/users/@me/cardiac_events",
133
+ { :headers => { "Authorization" => "Bearer #{token}" } }
134
+ response.parsed_response
135
+ end
136
+
137
+ def cardiac_event(event_id)
138
+ response = self.class.get "https://jawbone.com/nudge/api/users/@me/cardiac_event/#{event_id}",
139
+ { :headers => { "Authorization" => "Bearer #{token}" } }
140
+ response.parsed_response
141
+ end
142
+
143
+ def generic_events
144
+ response = self.class.get "https://jawbone.com/nudge/api/users/@me/generic_events",
145
+ { :headers => { "Authorization" => "Bearer #{token}" } }
146
+ response.parsed_response
147
+ end
148
+
149
+ def mood
150
+ response = self.class.get "https://jawbone.com/nudge/api/users/@me/mood",
151
+ { :headers => { "Authorization" => "Bearer #{token}" } }
152
+ response.parsed_response
153
+ end
154
+
155
+ def mood_event(event_id)
156
+ response = self.class.get "https://jawbone.com/nudge/api/users/@me/mood/#{event_id}",
157
+ { :headers => { "Authorization" => "Bearer #{token}" } }
158
+ response.parsed_response
159
+ end
160
+
161
+ end
162
+
163
+ end
@@ -1,6 +1,4 @@
1
- require File.join(File.dirname(__FILE__), 'session')
2
- require File.join(File.dirname(__FILE__), 'sleep')
3
- require File.join(File.dirname(__FILE__), 'daily_summary')
1
+ require File.join(File.dirname(__FILE__), 'client')
4
2
 
5
3
  module Jawbone
6
4
 
@@ -0,0 +1,3 @@
1
+ module Jawbone
2
+ VERSION = "0.3.0"
3
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jawbone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,22 +9,27 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-03 00:00:00.000000000 Z
12
+ date: 2013-09-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
16
- requirement: &70197358086280 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 0.8.1
21
+ version: 0.11.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70197358086280
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.11.0
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: json
27
- requirement: &70197358079380 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *70197358079380
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: rake
38
- requirement: &70197358078660 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: '0'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *70197358078660
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: rspec
49
- requirement: &70197358078120 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: '0'
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *70197358078120
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: simplecov
60
- requirement: &70197358077460 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ! '>='
@@ -65,10 +85,15 @@ dependencies:
65
85
  version: '0'
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *70197358077460
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
69
94
  - !ruby/object:Gem::Dependency
70
95
  name: yard
71
- requirement: &70197358077040 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
72
97
  none: false
73
98
  requirements:
74
99
  - - ! '>='
@@ -76,24 +101,28 @@ dependencies:
76
101
  version: '0'
77
102
  type: :development
78
103
  prerelease: false
79
- version_requirements: *70197358077040
80
- description: A Ruby wrapper for the unofficial Jawbone UP API.
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: A Ruby wrapper for the Jawbone UP API.
81
111
  email:
82
112
  - andy@andybrett.com
83
113
  executables: []
84
114
  extensions: []
85
115
  extra_rdoc_files: []
86
116
  files:
117
+ - LICENSE.md
118
+ - README.md
119
+ - Rakefile
120
+ - lib/client.rb
87
121
  - lib/jawbone.rb
88
- - lib/session.rb
89
- - lib/sleep.rb
90
- - lib/daily_summary.rb
91
- - spec/sleep_spec.rb
122
+ - lib/version.rb
92
123
  homepage: https://github.com/andrewpbrett/jawbone-up-api
93
124
  licenses: []
94
- post_install_message: ! "********************************************************************************\n\n
95
- \ This is an **Unoffical** API - use at your own risk. See \n http://eric-blue.com/projects/up-api/
96
- for more info and full documentation. \n\n********************************************************************************\n"
125
+ post_install_message:
97
126
  rdoc_options: []
98
127
  require_paths:
99
128
  - lib
@@ -111,9 +140,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
140
  version: '0'
112
141
  requirements: []
113
142
  rubyforge_project:
114
- rubygems_version: 1.8.13
143
+ rubygems_version: 1.8.25
115
144
  signing_key:
116
145
  specification_version: 3
117
146
  summary: Jawbone UP API wrapper
118
- test_files:
119
- - spec/sleep_spec.rb
147
+ test_files: []
@@ -1,34 +0,0 @@
1
- module Jawbone
2
-
3
- class DailySummary
4
-
5
- attr_accessor :data
6
-
7
- def initialize(data)
8
- @data = data
9
- end
10
-
11
- def steps
12
- @data["move_steps"]
13
- end
14
-
15
- def kilometers
16
- @data["move_kilometers"]
17
- end
18
-
19
- def workout?
20
- !@data["move_summary"]["workouts"].empty?
21
- end
22
-
23
- def sleep_total
24
- @data["sleep_summary"]["total"]
25
- end
26
-
27
- def sleep_quality
28
- return nil if @data["sleep_summary"]["sleeps"].empty?
29
- sleeps = @data["sleep_summary"]["sleeps"].map { |s| [s["details"]["duration"], s["details"]["quality"]]}
30
- sleeps.sort_by { |s| s[0] }.first[1]
31
- end
32
- end
33
-
34
- end
@@ -1,60 +0,0 @@
1
- require 'httparty'
2
-
3
- module Jawbone
4
-
5
- class Session
6
-
7
- attr_accessor :token
8
-
9
- include HTTParty
10
-
11
- def self.new_from_token token
12
- Jawbone::Session.new nil, nil, token
13
- end
14
-
15
- def initialize email, password, token = nil
16
- if token
17
- @token = token
18
- else
19
- response = self.class.post "https://jawbone.com/user/signin/login", { query:
20
- { service: "nudge", email: email, pwd: password } }
21
- @token = response["token"]
22
- end
23
- end
24
-
25
- def feed
26
- response = self.class.get "https://jawbone.com/nudge/api/users/@me/social", { query:
27
- { after: "null", limit: 100, _token: @token } }
28
- response["data"]["feed"]
29
- end
30
-
31
- def sleeps(feed = feed)
32
- feed.select { |e| e["type"] == "sleep" }
33
- end
34
-
35
- def full_sleeps
36
- local_sleeps = sleeps
37
- local_sleeps.each do |sleep|
38
- response = self.class.get "https://jawbone.com/nudge/api/sleeps/#{sleep["xid"]}/snapshot", { query: { _token: @token } }
39
- data = response["data"]
40
- sleep[:full_data] = data
41
- end
42
- end
43
-
44
- def average_time_to_sleep
45
- times = full_sleeps.map { |s| Sleep.new(s).time_to_sleep }
46
- times.inject{ |sum, el| sum + el }.to_f / times.size # times.average
47
- end
48
-
49
- # requires date to be in yyyy-mm-dd format
50
- def daily_summary date
51
- # assumes Pacific Time
52
- response = self.class.get "https://jawbone.com/nudge/api/users/@me/healthCredits", { query:
53
- { _token: @token, check_levels: 1, eat_goal: 0, sleep_goal: 0, move_goal: 0,
54
- timezone: "-28800", date: date } }
55
- response["data"]
56
- end
57
-
58
- end
59
-
60
- end
@@ -1,56 +0,0 @@
1
- module Jawbone
2
-
3
- class Sleep
4
- attr_accessor :data
5
-
6
- # expects a hash
7
- def initialize(data)
8
- @data = data
9
- end
10
-
11
- # note that these methods are also available in the sleep summary API call
12
- [:awake, :deep, :light].each do |type|
13
- define_method "#{type}_sleep" do
14
- totals[type]
15
- end
16
- end
17
-
18
- def quality
19
- @data["quality"]
20
- end
21
-
22
- def duration
23
- @data["duration"]
24
- end
25
-
26
- def time_to_sleep
27
- @data[:full_data][1][0] - @data[:full_data][0][0]
28
- end
29
-
30
- def cycle_changes
31
- @data[:full_data].size
32
- end
33
-
34
- private
35
-
36
- def totals
37
- # State codes: 1 = awake, 2 = light, 3 = deep
38
- light, deep, awake = 0, 0, 0
39
- state = 1
40
- @data[:full_data].each_with_index do |set, i|
41
- next if i == @data[:full_data].size - 1 # skip the last element
42
-
43
- bucket_size = @data[:full_data][i + 1][0] - set[0]
44
-
45
- case set[1]
46
- when 1 then awake += bucket_size
47
- when 2 then light += bucket_size
48
- when 3 then deep += bucket_size
49
- end
50
- end
51
-
52
- { light: light, deep: deep, awake: awake }
53
- end
54
-
55
- end
56
- end
@@ -1,39 +0,0 @@
1
- Dir[File.dirname(__FILE__) + '/../lib/*.rb'].each { |file| require file }
2
-
3
- describe Sleep do
4
-
5
- let(:sleep) { Sleep.new({ :full_data => [[1325314448, 1], [1325315468, 3], [1325317748, 2], [1325318948, 3], [1325321948, 2], [1325323148, 3], [1325324048, 2], [1325325848, 3], [1325326748, 2], [1325328848, 3], [1325329448, 2], [1325332148, 3], [1325333348, 2], [1325334848, 3], [1325337848, 2], [1325339348, 3], [1325339948, 2], [1325342048, 3], [1325342888, 1]]}) }
6
-
7
- describe "#deep_sleep" do
8
-
9
- it "returns the right amount of deep sleep" do
10
- sleep.deep_sleep.should == 13320
11
- end
12
-
13
- end
14
-
15
- describe "#light_sleep" do
16
-
17
- it "returns the right amount of light sleep" do
18
- sleep.light_sleep.should == 14100
19
- end
20
-
21
- end
22
-
23
- describe "#awake_sleep" do
24
-
25
- it "returns the right amount of awake sleep" do
26
- sleep.awake_sleep.should == 1020
27
- end
28
-
29
- end
30
-
31
- describe "#time_to_sleep" do
32
-
33
- it "returns the right amount of time it took to fall asleep" do
34
- sleep.time_to_sleep.should == 1020
35
- end
36
-
37
- end
38
-
39
- end