Class: Twenty3AndMe::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/twenty3andme/client.rb

Constant Summary collapse

VERSION =
'/1'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#refresh_tokenObject

Returns the value of attribute refresh_token.



11
12
13
# File 'lib/twenty3andme/client.rb', line 11

def refresh_token
  @refresh_token
end

#tokenObject

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)
  options = { :headers => {"Authorization" => "Bearer #{@token}"} }
  fullpath = URI.escape(VERSION + path)
  resp = self.class.get(fullpath, options).parsed_response
  if resp.class == Hash
    raise APIRequestError, resp['error_description'] if resp['error']
  end
  resp
end

#haplogroupsObject



47
48
49
# File 'lib/twenty3andme/client.rb', line 47

def haplogroups
  get('/haplogroups')
end

#namesObject



43
44
45
# File 'lib/twenty3andme/client.rb', line 43

def names
  get('/names')
end

#relativesObject



60
61
62
# File 'lib/twenty3andme/client.rb', line 60

def relatives
  get("/relatives")
end

#request_refresh_tokenObject

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

Raises:



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

#userObject

Requests



39
40
41
# File 'lib/twenty3andme/client.rb', line 39

def user
  get('/user')
end