omniauth-fitbit 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/Gemfile +14 -0
- data/LICENSE.md +20 -0
- data/README.md +38 -0
- data/Rakefile +2 -0
- data/example/Gemfile +6 -0
- data/example/example.rb +18 -0
- data/lib/omniauth/strategies/fitbit.rb +49 -0
- data/lib/omniauth-fitbit/version.rb +5 -0
- data/lib/omniauth-fitbit.rb +2 -0
- data/omniauth-fitbit.gemspec +21 -0
- data/spec/omniauth/strategies/fitbit_spec.rb +93 -0
- data/spec/spec_helper.rb +14 -0
- metadata +93 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 TK Gospodinov
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# OmniAuth Fitbit Strategy
|
2
|
+
|
3
|
+
This gem is an OmniAuth 1.0+ Strategy for the [Fitbit API](https://wiki.fitbit.com/display/API/OAuth+Authentication+in+the+Fitbit+API).
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Add the strategy to your `Gemfile`:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'omniauth-fitbit'
|
11
|
+
```
|
12
|
+
|
13
|
+
Then integrate the strategy into your middleware:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
use OmniAuth::Builder do
|
17
|
+
provider :fitbit, 'consumer_key', 'consumer_secret'
|
18
|
+
end
|
19
|
+
```
|
20
|
+
|
21
|
+
In Rails, create a new file under config/initializers called omniauth.rb to plug the strategy into your middleware stack.
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
25
|
+
provider :constantcontact, 'consumer_key', 'consumer_secret'
|
26
|
+
end
|
27
|
+
```
|
28
|
+
|
29
|
+
To register your application with Fitbit and obtain a consumer key and secret, go to the [Fitbit application registration](https://dev.fitbit.com/apps/new).
|
30
|
+
|
31
|
+
For additional information about OmniAuth, visit [OmniAuth wiki](https://github.com/intridea/omniauth/wiki).
|
32
|
+
|
33
|
+
For a short tutorial on how to use OmniAuth in your Rails application, visit [this tutsplus.com tutorial](http://net.tutsplus.com/tutorials/ruby/how-to-use-omniauth-to-authenticate-your-users/).
|
34
|
+
|
35
|
+
|
36
|
+
## Copyright
|
37
|
+
|
38
|
+
Copyright (c) 2012 TK Gospodinov. See [LICENSE](https://github.com/tkgospodinov/omniauth-fitbit/blob/master/LICENSE.md) for details.
|
data/Rakefile
ADDED
data/example/Gemfile
ADDED
data/example/example.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
require 'omniauth-fitbit'
|
3
|
+
|
4
|
+
use Rack::Session::Cookie
|
5
|
+
use OmniAuth::Builder do
|
6
|
+
provider :fitbit, '<consumer_key>', '<consumer_secret>'
|
7
|
+
end
|
8
|
+
|
9
|
+
get '/' do
|
10
|
+
<<-HTML
|
11
|
+
<a href='/auth/fitbit'>Sign in with Fitbit</a>
|
12
|
+
HTML
|
13
|
+
end
|
14
|
+
|
15
|
+
get '/auth/fitbit/callback' do
|
16
|
+
# Do whatever you want with the data
|
17
|
+
MultiJson.encode(request.env['omniauth.auth'])
|
18
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'omniauth'
|
2
|
+
require 'omniauth/strategies/oauth'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
class Fitbit < OmniAuth::Strategies::OAuth
|
7
|
+
|
8
|
+
option :name, "fitbit"
|
9
|
+
|
10
|
+
option :client_options, {
|
11
|
+
:site => 'http://api.fitbit.com',
|
12
|
+
:request_token_path => '/oauth/request_token',
|
13
|
+
:access_token_path => '/oauth/access_token',
|
14
|
+
:authorize_path => '/oauth/authorize'
|
15
|
+
}
|
16
|
+
|
17
|
+
uid do
|
18
|
+
access_token.params['encoded_user_id']
|
19
|
+
end
|
20
|
+
|
21
|
+
info do
|
22
|
+
{
|
23
|
+
:full_name => raw_info['user']['fullName'],
|
24
|
+
:display_name => raw_info['user']['displayName'],
|
25
|
+
:nickname => raw_info['user']['nickname'],
|
26
|
+
:gender => raw_info['user']['gender'],
|
27
|
+
:about_me => raw_info['user']['aboutMe'],
|
28
|
+
:city => raw_info['user']['city'],
|
29
|
+
:state => raw_info['user']['state'],
|
30
|
+
:country => raw_info['user']['country'],
|
31
|
+
:dob => Date.strptime(raw_info['user']['dateOfBirth'], '%Y-%m-%d'),
|
32
|
+
:member_since => Date.strptime(raw_info['user']['memberSince'], '%Y-%m-%d'),
|
33
|
+
:locale => raw_info['user']['locale'],
|
34
|
+
:timezone => raw_info['user']['timezone']
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
extra do
|
39
|
+
{
|
40
|
+
:raw_info => raw_info
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
def raw_info
|
45
|
+
@raw_info ||= MultiJson.load(access_token.get('http://api.fitbit.com/1/user/-/profile.json').body)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "omniauth-fitbit/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "omniauth-fitbit"
|
7
|
+
s.version = OmniAuth::Fitbit::VERSION
|
8
|
+
s.authors = ["TK Gospodinov"]
|
9
|
+
s.email = ["tk@gospodinov.net"]
|
10
|
+
s.homepage = "http://github.com/tkgospodinov/omniauth-fitbit"
|
11
|
+
s.summary = %q{OmniAuth strategy for Fitbit}
|
12
|
+
s.description = %q{OmniAuth strategy for Fitbit}
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split($\)
|
15
|
+
s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
|
19
|
+
s.add_runtime_dependency 'omniauth-oauth', '~> 1.0'
|
20
|
+
s.add_runtime_dependency 'multi_xml'
|
21
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "OmniAuth::Strategies::Fitbit" do
|
4
|
+
subject do
|
5
|
+
OmniAuth::Strategies::Fitbit.new(nil, @options || {})
|
6
|
+
end
|
7
|
+
|
8
|
+
context 'client options' do
|
9
|
+
it 'has correct OAuth endpoint' do
|
10
|
+
subject.options.client_options.site.should eq('http://api.fitbit.com')
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'has correct request token url' do
|
14
|
+
subject.options.client_options.request_token_path.should eq('/oauth/request_token')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'has correct access token url' do
|
18
|
+
subject.options.client_options.access_token_path.should eq('/oauth/access_token')
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'has correct authorize url' do
|
22
|
+
subject.options.client_options.authorize_path.should eq('/oauth/authorize')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'uid' do
|
27
|
+
before :each do
|
28
|
+
access_token = double('access_token')
|
29
|
+
access_token.stub('params') { { 'encoded_user_id' => '123ABC' } }
|
30
|
+
subject.stub(:access_token) { access_token }
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'returns the correct id from raw_info' do
|
34
|
+
subject.uid.should eq('123ABC')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'info' do
|
39
|
+
before :each do
|
40
|
+
subject.stub(:raw_info) {
|
41
|
+
{
|
42
|
+
"user" =>
|
43
|
+
{
|
44
|
+
"fullName" => "John Doe",
|
45
|
+
"displayName" => "JD",
|
46
|
+
"nickname" => "Johnnie",
|
47
|
+
"gender" => "MALE",
|
48
|
+
"aboutMe" => "I live in Kansas City, MO",
|
49
|
+
"city" => "Kansas City",
|
50
|
+
"state" => "MO",
|
51
|
+
"country" => "US",
|
52
|
+
"dateOfBirth" => "1980-01-01",
|
53
|
+
"memberSince" => "2010-01-01",
|
54
|
+
"locale" => "en_US",
|
55
|
+
"timezone" => "America/Chicago"
|
56
|
+
}
|
57
|
+
}
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'returns the correct full name from raw_info' do
|
62
|
+
subject.info[:full_name].should eq("John Doe")
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'returns the correct display name from raw_info' do
|
66
|
+
subject.info[:display_name].should eq("JD")
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'returns the correct nickname from raw_info' do
|
70
|
+
subject.info[:nickname].should eq("Johnnie")
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'returns the correct gender from raw_info' do
|
74
|
+
subject.info[:gender].should eq("MALE")
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'returns the correct gender from raw_info' do
|
78
|
+
subject.info[:about_me].should eq("I live in Kansas City, MO")
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'returns the correct gender from raw_info' do
|
82
|
+
subject.info[:city].should eq("Kansas City")
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'returns the correct gender from raw_info' do
|
86
|
+
subject.info[:state].should eq("MO")
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'returns the correct gender from raw_info' do
|
90
|
+
subject.info[:country].should eq("US")
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('..', __FILE__)
|
2
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
3
|
+
|
4
|
+
require 'rspec'
|
5
|
+
require 'rack/test'
|
6
|
+
require 'webmock/rspec'
|
7
|
+
require 'omniauth'
|
8
|
+
require 'omniauth-fitbit'
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.include WebMock::API
|
12
|
+
config.include Rack::Test::Methods
|
13
|
+
config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-fitbit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- TK Gospodinov
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-31 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: omniauth-oauth
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: multi_xml
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: OmniAuth strategy for Fitbit
|
47
|
+
email:
|
48
|
+
- tk@gospodinov.net
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.md
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- example/Gemfile
|
59
|
+
- example/example.rb
|
60
|
+
- lib/omniauth-fitbit.rb
|
61
|
+
- lib/omniauth-fitbit/version.rb
|
62
|
+
- lib/omniauth/strategies/fitbit.rb
|
63
|
+
- omniauth-fitbit.gemspec
|
64
|
+
- spec/omniauth/strategies/fitbit_spec.rb
|
65
|
+
- spec/spec_helper.rb
|
66
|
+
homepage: http://github.com/tkgospodinov/omniauth-fitbit
|
67
|
+
licenses: []
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 1.8.24
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: OmniAuth strategy for Fitbit
|
90
|
+
test_files:
|
91
|
+
- spec/omniauth/strategies/fitbit_spec.rb
|
92
|
+
- spec/spec_helper.rb
|
93
|
+
has_rdoc:
|