fitgem 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Guardfile +15 -0
- data/fitgem.gemspec +4 -0
- data/lib/fitgem/body_measurements.rb +20 -0
- data/lib/fitgem/client.rb +5 -5
- data/lib/fitgem/helpers.rb +11 -4
- data/lib/fitgem.rb +1 -1
- data/spec/fitgem_spec.rb +28 -18
- metadata +48 -3
- data/lib/fitgem/weight.rb +0 -13
data/Guardfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'rspec', :version => 2 do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
|
9
|
+
# Rails example
|
10
|
+
watch(%r{^spec/.+_spec\.rb$})
|
11
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
12
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
13
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
14
|
+
watch('spec/spec_helper.rb') { "spec" }
|
15
|
+
end
|
data/fitgem.gemspec
CHANGED
@@ -17,6 +17,10 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.rubyforge_project = "fitgem"
|
18
18
|
s.add_dependency "oauth"
|
19
19
|
s.add_development_dependency "rspec"
|
20
|
+
s.add_development_dependency "guard"
|
21
|
+
s.add_development_dependency "guard-rspec"
|
22
|
+
s.add_development_dependency "rb-fsevent"
|
23
|
+
s.add_development_dependency "growl"
|
20
24
|
|
21
25
|
s.files = `git ls-files`.split("\n")
|
22
26
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Fitgem
|
2
|
+
class Client
|
3
|
+
|
4
|
+
# ==========================================
|
5
|
+
# Body Measurements Update Methods
|
6
|
+
# ==========================================
|
7
|
+
def body_measurements_on_date(date)
|
8
|
+
get("/user/#{@user_id}/body/date/#{format_date(date)}.json")
|
9
|
+
end
|
10
|
+
|
11
|
+
# ==========================================
|
12
|
+
# Body Measurements Update Methods
|
13
|
+
# ==========================================
|
14
|
+
|
15
|
+
def log_weight(weight, date, options={})
|
16
|
+
post("/user/#{@user_id}/body/weight.json", options.merge(:weight => weight, :date => format_date(date)))
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
data/lib/fitgem/client.rb
CHANGED
@@ -4,7 +4,7 @@ require 'fitgem/users'
|
|
4
4
|
require 'fitgem/activities'
|
5
5
|
require 'fitgem/units'
|
6
6
|
require 'fitgem/foods'
|
7
|
-
require 'fitgem/
|
7
|
+
require 'fitgem/body_measurements'
|
8
8
|
require 'fitgem/time_range'
|
9
9
|
require 'fitgem/devices'
|
10
10
|
require 'fitgem/notifications'
|
@@ -13,11 +13,11 @@ require 'uri'
|
|
13
13
|
|
14
14
|
module Fitgem
|
15
15
|
class Client
|
16
|
-
|
16
|
+
|
17
17
|
attr_accessor :api_version
|
18
18
|
attr_accessor :api_unit_system
|
19
19
|
attr_accessor :user_id
|
20
|
-
|
20
|
+
|
21
21
|
def initialize(options = {})
|
22
22
|
@consumer_key = options[:consumer_key]
|
23
23
|
@consumer_secret = options[:consumer_secret]
|
@@ -38,7 +38,7 @@ module Fitgem
|
|
38
38
|
@secret = @access_token.secret
|
39
39
|
@access_token
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
def reconnect(token, secret)
|
43
43
|
@token = token
|
44
44
|
@secret = secret
|
@@ -63,7 +63,7 @@ module Fitgem
|
|
63
63
|
{ :site => 'http://api.fitbit.com', :request_endpoint => @proxy }
|
64
64
|
)
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
def access_token
|
68
68
|
@access_token ||= OAuth::AccessToken.new(consumer, @token, @secret)
|
69
69
|
end
|
data/lib/fitgem/helpers.rb
CHANGED
@@ -1,16 +1,23 @@
|
|
1
1
|
module Fitgem
|
2
2
|
class Client
|
3
|
-
|
3
|
+
|
4
4
|
# Should return date as YYYY-MM-DD
|
5
5
|
def format_date(date)
|
6
6
|
if date.is_a? String
|
7
|
-
|
7
|
+
case date
|
8
|
+
when 'today'
|
9
|
+
return Date.today.strftime("%Y-%m-%d")
|
10
|
+
when 'yesterday'
|
11
|
+
return (Date.today-1).strftime("%Y-%m-%d")
|
12
|
+
else
|
13
|
+
return date
|
14
|
+
end
|
8
15
|
elsif Date === date || Time === date || DateTime === date
|
9
16
|
return date.strftime("%Y-%m-%d")
|
10
17
|
else
|
11
|
-
raise Fitgem::InvalidArgumentError, "Date used must be a date/time object or a string in the format YYYY
|
18
|
+
raise Fitgem::InvalidArgumentError, "Date used must be a date/time object or a string in the format YYYY-MM-DD; current argument is a #{date.class}"
|
12
19
|
end
|
13
20
|
end
|
14
|
-
|
21
|
+
|
15
22
|
end
|
16
23
|
end
|
data/lib/fitgem.rb
CHANGED
data/spec/fitgem_spec.rb
CHANGED
@@ -1,73 +1,83 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Fitgem do
|
4
|
-
|
4
|
+
|
5
5
|
before do
|
6
6
|
@client = Fitgem::Client.new
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
describe "global settings" do
|
10
10
|
it 'should expose the api_version' do
|
11
11
|
@client.api_version.should == "1"
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
it 'should all clients to set a new api version' do
|
15
15
|
@client.api_version = "2"
|
16
16
|
@client.api_version.should == "2"
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
it 'should default to the US unit system' do
|
20
20
|
@client.api_unit_system.should == Fitgem::ApiUnitSystem.US
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
it 'should allow the unit system to be set to other types' do
|
24
24
|
@client.api_unit_system = Fitgem::ApiUnitSystem.UK
|
25
25
|
@client.api_unit_system.should == Fitgem::ApiUnitSystem.UK
|
26
26
|
@client.api_unit_system = Fitgem::ApiUnitSystem.METRIC
|
27
|
-
@client.api_unit_system.should == Fitgem::ApiUnitSystem.METRIC
|
27
|
+
@client.api_unit_system.should == Fitgem::ApiUnitSystem.METRIC
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
it 'should default to a user id of \'-\', the currently-logged in user' do
|
31
31
|
@client.user_id.should == '-'
|
32
32
|
end
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
describe "data retrieval by time range" do
|
36
|
-
|
36
|
+
|
37
37
|
it 'should format the correct URI fragment based on a base date and end date' do
|
38
38
|
frag = @client.construct_date_range_fragment({:base_date => '2011-03-07', :end_date => '2011-03-14'})
|
39
39
|
frag.should == 'date/2011-03-07/2011-03-14'
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
it 'should format the correct URI fragment based on a base date and period' do
|
43
43
|
frag = @client.construct_date_range_fragment({:base_date => '2011-03-07', :period => '7d'})
|
44
44
|
frag.should == 'date/2011-03-07/7d'
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
it 'should raise an error unless there is a base date AND either a period or an end date' do
|
48
48
|
lambda {
|
49
49
|
@client.construct_date_range_fragment({:base_date => '2011-03-07'})
|
50
50
|
}.should raise_error(Fitgem::InvalidTimeRange)
|
51
|
-
|
51
|
+
|
52
52
|
lambda {
|
53
53
|
@client.construct_date_range_fragment({:period => '1y'})
|
54
54
|
}.should raise_error(Fitgem::InvalidTimeRange)
|
55
|
-
|
55
|
+
|
56
56
|
lambda {
|
57
57
|
@client.construct_date_range_fragment({:end_date => '2011-03-07', :period => '7d'})
|
58
58
|
}.should raise_error(Fitgem::InvalidTimeRange)
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
describe "format_date" do
|
64
|
-
it
|
64
|
+
it "accepts DateTime objects" do
|
65
65
|
date = DateTime.strptime('2011-03-19','%Y-%m-%d')
|
66
66
|
@client.format_date(date).should == '2011-03-19'
|
67
67
|
end
|
68
|
-
|
69
|
-
it
|
68
|
+
|
69
|
+
it "accepts strings in YYYY-MM-DD format" do
|
70
70
|
@client.format_date('2011-03-19').should == '2011-03-19'
|
71
71
|
end
|
72
|
+
|
73
|
+
it "accepts the string 'today' to denote the current date" do
|
74
|
+
today = Date.today.strftime("%Y-%m-%d")
|
75
|
+
@client.format_date('today').should == today
|
76
|
+
end
|
77
|
+
|
78
|
+
it "accepts the string 'yesterday' to denote the day previous to today" do
|
79
|
+
yesterday = (Date.today-1).strftime("%Y-%m-%d")
|
80
|
+
@client.format_date('yesterday').should == yesterday
|
81
|
+
end
|
72
82
|
end
|
73
83
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: fitgem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.2.
|
5
|
+
version: 0.2.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Zachery Moneypenny
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-07-01 00:00:00 -05:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -35,6 +35,50 @@ dependencies:
|
|
35
35
|
version: "0"
|
36
36
|
type: :development
|
37
37
|
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: guard
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: guard-rspec
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
type: :development
|
59
|
+
version_requirements: *id004
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: rb-fsevent
|
62
|
+
prerelease: false
|
63
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
type: :development
|
70
|
+
version_requirements: *id005
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: growl
|
73
|
+
prerelease: false
|
74
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: "0"
|
80
|
+
type: :development
|
81
|
+
version_requirements: *id006
|
38
82
|
description: A client library to send and retrieve workout/weight data from fitbit.com
|
39
83
|
email:
|
40
84
|
- fitgem@whazzmaster.com
|
@@ -48,12 +92,14 @@ files:
|
|
48
92
|
- .gitignore
|
49
93
|
- .rvmrc
|
50
94
|
- Gemfile
|
95
|
+
- Guardfile
|
51
96
|
- LICENSE
|
52
97
|
- README.md
|
53
98
|
- Rakefile
|
54
99
|
- fitgem.gemspec
|
55
100
|
- lib/fitgem.rb
|
56
101
|
- lib/fitgem/activities.rb
|
102
|
+
- lib/fitgem/body_measurements.rb
|
57
103
|
- lib/fitgem/client.rb
|
58
104
|
- lib/fitgem/devices.rb
|
59
105
|
- lib/fitgem/errors.rb
|
@@ -63,7 +109,6 @@ files:
|
|
63
109
|
- lib/fitgem/time_range.rb
|
64
110
|
- lib/fitgem/units.rb
|
65
111
|
- lib/fitgem/users.rb
|
66
|
-
- lib/fitgem/weight.rb
|
67
112
|
- spec/fitgem_spec.rb
|
68
113
|
- spec/spec_helper.rb
|
69
114
|
has_rdoc: true
|
data/lib/fitgem/weight.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
module Fitgem
|
2
|
-
class Client
|
3
|
-
|
4
|
-
# ==========================================
|
5
|
-
# Weight Update Methods
|
6
|
-
# ==========================================
|
7
|
-
|
8
|
-
def log_weight(weight, date, options={})
|
9
|
-
post("/user/#{@user_id}/body/weight.json", options.merge(:weight => weight, :date => format_date(date)))
|
10
|
-
end
|
11
|
-
|
12
|
-
end
|
13
|
-
end
|