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
56 57 58 |
# File 'lib/twenty3andme/client.rb', line 56 def ancestry(threshold) get("/ancestry/?threshold=#{threshold.to_f}") end |
#genomes(profile_id) ⇒ Object
64 65 66 |
# File 'lib/twenty3andme/client.rb', line 64 def genomes(profile_id) get("/genomes/#{profile_id}") end |
#genotypes(locations) ⇒ Object
51 52 53 54 |
# File 'lib/twenty3andme/client.rb', line 51 def genotypes(locations) locations_uri = Array(locations).join(" ") get("/genotypes/?locations=#{locations_uri}") end |
#get(path) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# 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 if resp.class == Hash raise APIRequestError, resp['error_description'] if resp['error'] end resp end |
#haplogroups ⇒ Object
47 48 49 |
# File 'lib/twenty3andme/client.rb', line 47 def haplogroups get('/haplogroups') end |
#names ⇒ Object
43 44 45 |
# File 'lib/twenty3andme/client.rb', line 43 def names get('/names') end |
#relatives ⇒ Object
60 61 62 |
# File 'lib/twenty3andme/client.rb', line 60 def relatives get("/relatives") end |
#request_refresh_token ⇒ Object
TODO
34 35 |
# File 'lib/twenty3andme/client.rb', line 34 def request_refresh_token() end |
#request_token(client_id, client_secret, code, redirect_uri, scope) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/twenty3andme/client.rb', line 23 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
39 40 41 |
# File 'lib/twenty3andme/client.rb', line 39 def user get('/user') end |