twenty3andme 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/twenty3andme/callback_listener.rb +1 -1
- data/lib/twenty3andme/client.rb +7 -1
- data/spec/callback_listener_spec.rb +8 -6
- data/spec/twenty3andme_spec.rb +29 -2
- data/twenty3andme.gemspec +2 -2
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/lib/twenty3andme/client.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
module Twenty3AndMe
|
2
|
+
class TokenRequestError < StandardError ; end
|
3
|
+
class APIRequestError < StandardError ; end
|
4
|
+
|
2
5
|
class Client
|
3
6
|
include HTTParty
|
4
7
|
base_uri 'api.23andme.com'
|
@@ -10,13 +13,16 @@ module Twenty3AndMe
|
|
10
13
|
def get(path)
|
11
14
|
options = { :headers => {"Authorization" => "Bearer #{@token}"} }
|
12
15
|
fullpath = URI.escape(VERSION + path)
|
13
|
-
self.class.get(fullpath, options).parsed_response
|
16
|
+
resp = self.class.get(fullpath, options).parsed_response
|
17
|
+
raise APIRequestError, resp['error_description'] if resp['error']
|
18
|
+
resp
|
14
19
|
end
|
15
20
|
|
16
21
|
def request_token(client_id, client_secret, code, redirect_uri, scope)
|
17
22
|
scope_uri = Array(scope).join(" ")
|
18
23
|
req_body = {:client_id => client_id, :client_secret => client_secret, :grant_type => 'authorization_code', :code => code, :redirect_uri => redirect_uri, :scope => scope_uri}
|
19
24
|
resp = self.class.post("https://api.23andme.com:443/token", :body => req_body)
|
25
|
+
raise TokenRequestError, resp['error_description'] if resp['error']
|
20
26
|
|
21
27
|
@token = resp['access_token']
|
22
28
|
@refresh_token = resp['refresh_token']
|
@@ -6,13 +6,15 @@ describe Twenty3AndMe::CallbackListener do
|
|
6
6
|
def app
|
7
7
|
Twenty3AndMe::CallbackListener
|
8
8
|
end
|
9
|
+
|
10
|
+
before do
|
11
|
+
end
|
12
|
+
|
9
13
|
|
10
|
-
describe
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
last_response.status.should == 200
|
15
|
-
end
|
14
|
+
describe "GET /?code=adc996063679f1a400aa0e13c54094dc" do
|
15
|
+
it "returns the provided code from 23andme" do
|
16
|
+
get "/?code=adc996063679f1a400aa0e13c54094dc"
|
17
|
+
last_response.status.should == 200
|
16
18
|
end
|
17
19
|
end
|
18
20
|
end
|
data/spec/twenty3andme_spec.rb
CHANGED
@@ -3,11 +3,38 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
3
3
|
describe "Twenty3andme" do
|
4
4
|
|
5
5
|
context "API Client" do
|
6
|
-
|
6
|
+
|
7
|
+
before :all do
|
8
|
+
code = "fillmein"
|
9
|
+
@client = Twenty3AndMe::Client.new
|
10
|
+
@client.request_token(ENV['CLIENT_ID'], ENV['CLIENT_SECRET'], code, ENV['REDIRECT_URI'], ENV['SCOPE'].split(','))
|
11
|
+
end
|
12
|
+
|
13
|
+
it "has a token recieved by 23andme" do
|
14
|
+
@client.token.should_not be_nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it "makes the /user request " do
|
18
|
+
@client.user
|
19
|
+
end
|
20
|
+
|
21
|
+
it "makes the /names request " do
|
22
|
+
@client.names
|
7
23
|
end
|
8
24
|
|
9
|
-
|
25
|
+
it "makes the /haplogroups request " do
|
26
|
+
@client.haplogroups
|
10
27
|
end
|
28
|
+
|
29
|
+
it "makes the /relatives request " do
|
30
|
+
@client.relatives
|
31
|
+
end
|
32
|
+
|
33
|
+
it "requests a genotype" do
|
34
|
+
@client.genotype('rs3094315')
|
35
|
+
end
|
36
|
+
|
37
|
+
|
11
38
|
end
|
12
39
|
|
13
40
|
end
|
data/twenty3andme.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "twenty3andme"
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ian Morgan"]
|
12
|
-
s.date = "2013-01-
|
12
|
+
s.date = "2013-01-09"
|
13
13
|
s.description = "Ruby API client and Rails engine for creating applications that integrate with data from the personal genetic testing service 23AndMe"
|
14
14
|
s.email = "ian@ruby-code.com"
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twenty3andme
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: grape
|
@@ -182,7 +182,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
182
182
|
version: '0'
|
183
183
|
segments:
|
184
184
|
- 0
|
185
|
-
hash:
|
185
|
+
hash: 2400844370785792384
|
186
186
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
187
187
|
none: false
|
188
188
|
requirements:
|