Class: Twenty3AndMe::Client
- Inherits:
-
Object
- Object
- Twenty3AndMe::Client
- Includes:
- HTTParty
- Defined in:
- lib/twenty3andme/client.rb
Constant Summary collapse
- VERSION =
'/1'
Instance Attribute Summary collapse
-
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
- #ancestry(threshold) ⇒ Object
- #genomes(profile_id) ⇒ Object
- #genotypes(locations) ⇒ Object
- #get(path) ⇒ Object
- #haplogroups ⇒ Object
- #names ⇒ Object
- #relatives ⇒ Object
-
#request_refresh_token ⇒ Object
TODO.
- #request_token(client_id, client_secret, code, redirect_uri, scope) ⇒ Object
-
#user ⇒ Object
Requests.
Instance Attribute Details
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
11 12 13 |
# File 'lib/twenty3andme/client.rb', line 11 def refresh_token @refresh_token end |
#token ⇒ Object
Returns the value of attribute token.
10 11 12 |
# File 'lib/twenty3andme/client.rb', line 10 def token @token end |
Instance Method Details
#ancestry(threshold) ⇒ Object
54 55 56 |
# File 'lib/twenty3andme/client.rb', line 54 def ancestry(threshold) get("/ancestry/?threshold=#{threshold.to_f}") end |
#genomes(profile_id) ⇒ Object
62 63 64 |
# File 'lib/twenty3andme/client.rb', line 62 def genomes(profile_id) get("/genomes/#{profile_id}") end |
#genotypes(locations) ⇒ Object
49 50 51 52 |
# File 'lib/twenty3andme/client.rb', line 49 def genotypes(locations) locations_uri = Array(locations).join(" ") get("/genotypes/?locations=#{locations_uri}") end |
#get(path) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/twenty3andme/client.rb', line 13 def get(path) = { :headers => {"Authorization" => "Bearer #{@token}"} } fullpath = URI.escape(VERSION + path) resp = self.class.get(fullpath, ).parsed_response raise APIRequestError, resp['error_description'] if resp['error'] resp end |
#haplogroups ⇒ Object
45 46 47 |
# File 'lib/twenty3andme/client.rb', line 45 def haplogroups get('/haplogroups') end |
#names ⇒ Object
41 42 43 |
# File 'lib/twenty3andme/client.rb', line 41 def names get('/names') end |
#relatives ⇒ Object
58 59 60 |
# File 'lib/twenty3andme/client.rb', line 58 def relatives get("/relatives") end |
#request_refresh_token ⇒ Object
TODO
32 33 |
# File 'lib/twenty3andme/client.rb', line 32 def request_refresh_token() end |
#request_token(client_id, client_secret, code, redirect_uri, scope) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/twenty3andme/client.rb', line 21 def request_token(client_id, client_secret, code, redirect_uri, scope) scope_uri = Array(scope).join(" ") req_body = {:client_id => client_id, :client_secret => client_secret, :grant_type => 'authorization_code', :code => code, :redirect_uri => redirect_uri, :scope => scope_uri} resp = self.class.post("https://api.23andme.com:443/token", :body => req_body) raise TokenRequestError, resp['error_description'] if resp['error'] @token = resp['access_token'] @refresh_token = resp['refresh_token'] end |
#user ⇒ Object
Requests
37 38 39 |
# File 'lib/twenty3andme/client.rb', line 37 def user get('/user') end |