solvebio 1.6.1 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.bumpversion.cfg +6 -0
- data/.gitignore +5 -4
- data/.travis.yml +1 -1
- data/Gemfile +3 -0
- data/README.md +34 -34
- data/Rakefile +1 -18
- data/bin/solvebio.rb +14 -16
- data/installer +64 -0
- data/lib/solvebio.rb +50 -11
- data/lib/solvebio/acccount.rb +4 -0
- data/lib/solvebio/annotation.rb +11 -0
- data/lib/solvebio/api_operations.rb +147 -0
- data/lib/solvebio/api_resource.rb +32 -0
- data/lib/solvebio/cli.rb +75 -0
- data/lib/solvebio/cli/auth.rb +106 -0
- data/lib/solvebio/cli/credentials.rb +54 -0
- data/lib/{cli → solvebio/cli}/irb.rb +0 -23
- data/lib/solvebio/cli/irbrc.rb +48 -0
- data/lib/solvebio/cli/tutorial.rb +12 -0
- data/lib/solvebio/client.rb +149 -0
- data/lib/solvebio/dataset.rb +60 -0
- data/lib/solvebio/dataset_field.rb +12 -0
- data/lib/solvebio/depository.rb +38 -0
- data/lib/solvebio/depository_version.rb +40 -0
- data/lib/solvebio/errors.rb +64 -0
- data/lib/solvebio/filter.rb +315 -0
- data/lib/solvebio/list_object.rb +73 -0
- data/lib/solvebio/locale.rb +43 -0
- data/lib/solvebio/query.rb +341 -0
- data/lib/solvebio/sample.rb +54 -0
- data/lib/solvebio/singleton_api_resource.rb +25 -0
- data/lib/solvebio/solve_object.rb +164 -0
- data/lib/solvebio/tabulate.rb +589 -0
- data/lib/solvebio/user.rb +4 -0
- data/lib/solvebio/util.rb +59 -0
- data/lib/solvebio/version.rb +3 -0
- data/solvebio.gemspec +10 -18
- data/test/helper.rb +6 -2
- data/test/solvebio/data/.gitignore +1 -0
- data/test/solvebio/data/.netrc +6 -0
- data/test/{data → solvebio/data}/netrc-save +0 -0
- data/test/solvebio/data/sample.vcf.gz +0 -0
- data/test/solvebio/data/test_creds +3 -0
- data/test/solvebio/test_annotation.rb +45 -0
- data/test/solvebio/test_client.rb +29 -0
- data/test/solvebio/test_conversion.rb +14 -0
- data/test/solvebio/test_credentials.rb +67 -0
- data/test/solvebio/test_dataset.rb +52 -0
- data/test/solvebio/test_depository.rb +24 -0
- data/test/solvebio/test_depositoryversion.rb +22 -0
- data/test/solvebio/test_error.rb +31 -0
- data/test/solvebio/test_filter.rb +86 -0
- data/test/solvebio/test_query.rb +282 -0
- data/test/solvebio/test_query_batch.rb +38 -0
- data/test/solvebio/test_query_init.rb +30 -0
- data/test/solvebio/test_query_tabulate.rb +73 -0
- data/test/solvebio/test_ratelimit.rb +31 -0
- data/test/solvebio/test_resource.rb +29 -0
- data/test/solvebio/test_sample_access.rb +60 -0
- data/test/solvebio/test_sample_download.rb +20 -0
- data/test/solvebio/test_tabulate.rb +129 -0
- data/test/solvebio/test_util.rb +39 -0
- metadata +100 -85
- data/Makefile +0 -17
- data/demo/README.md +0 -14
- data/demo/cheatsheet.rb +0 -31
- data/demo/dataset/facets.rb +0 -13
- data/demo/dataset/field.rb +0 -13
- data/demo/depository/README.md +0 -24
- data/demo/depository/all.rb +0 -13
- data/demo/depository/retrieve.rb +0 -13
- data/demo/depository/versions-all.rb +0 -13
- data/demo/query/query-filter.rb +0 -30
- data/demo/query/query.rb +0 -13
- data/demo/query/range-filter.rb +0 -18
- data/demo/test-api.rb +0 -98
- data/lib/cli/auth.rb +0 -122
- data/lib/cli/help.rb +0 -13
- data/lib/cli/irbrc.rb +0 -54
- data/lib/cli/options.rb +0 -75
- data/lib/client.rb +0 -154
- data/lib/credentials.rb +0 -67
- data/lib/errors.rb +0 -81
- data/lib/filter.rb +0 -312
- data/lib/locale.rb +0 -47
- data/lib/main.rb +0 -46
- data/lib/query.rb +0 -414
- data/lib/resource/annotation.rb +0 -23
- data/lib/resource/apiresource.rb +0 -241
- data/lib/resource/dataset.rb +0 -91
- data/lib/resource/datasetfield.rb +0 -37
- data/lib/resource/depository.rb +0 -50
- data/lib/resource/depositoryversion.rb +0 -69
- data/lib/resource/main.rb +0 -123
- data/lib/resource/sample.rb +0 -75
- data/lib/resource/solveobject.rb +0 -122
- data/lib/resource/user.rb +0 -5
- data/lib/tabulate.rb +0 -706
- data/lib/util.rb +0 -29
- data/test/Makefile +0 -9
- data/test/data/sample.vcf.gz +0 -0
- data/test/test-annotation.rb +0 -46
- data/test/test-auth.rb +0 -58
- data/test/test-client.rb +0 -27
- data/test/test-conversion.rb +0 -13
- data/test/test-dataset.rb +0 -42
- data/test/test-depository.rb +0 -35
- data/test/test-error.rb +0 -36
- data/test/test-filter.rb +0 -70
- data/test/test-netrc.rb +0 -52
- data/test/test-query-batch.rb +0 -40
- data/test/test-query-init.rb +0 -29
- data/test/test-query-paging.rb +0 -102
- data/test/test-query.rb +0 -71
- data/test/test-resource.rb +0 -40
- data/test/test-sample-access.rb +0 -59
- data/test/test-sample-download.rb +0 -20
- data/test/test-tabulate.rb +0 -131
- data/test/test-util.rb +0 -42
data/Makefile
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
# I'll admit it -- I'm an absent-minded old-timer who has trouble
|
2
|
-
# learning new tricks.
|
3
|
-
|
4
|
-
.PHONY: test
|
5
|
-
|
6
|
-
RUBY ?= ruby
|
7
|
-
RAKE ?= rake
|
8
|
-
|
9
|
-
test: check
|
10
|
-
|
11
|
-
#: Default target; same as "make check"
|
12
|
-
all: check
|
13
|
-
true
|
14
|
-
|
15
|
-
#: Same as corresponding rake task
|
16
|
-
%:
|
17
|
-
$(RAKE) $@
|
data/demo/README.md
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
# Intro
|
2
|
-
|
3
|
-
SolveBio aims to provide robust access to highly curated biological datasets. While our datasets do not conform to any proprietary formats, they are organized in a systematic way.
|
4
|
-
|
5
|
-
*Depositories* (data repositories) are simply versioned containers of datasets
|
6
|
-
|
7
|
-
A depository contains many versions, which in turn contain many datasets. Each dataset represents an independent “datastore”. Datasets store semi-structured data similar to typical “NoSQL” databases.
|
8
|
-
|
9
|
-
The [depository folder](https://github.com/solvebio/solvebio-ruby/blob/master/demo/depository) has examples involving retrieving, getting version information or listing depositories.
|
10
|
-
|
11
|
-
*Datasets* are access points to data. Dataset names are unique within versions of a depository. The
|
12
|
-
[dataset folder](https://github.com/solvebio/solvebio-ruby/blob/master/demo/dataset) has programs for retrieving properties of a dataset.
|
13
|
-
|
14
|
-
However, issuing queries on a dataset is probably what you will most want to do. The [query folder](https://github.com/solvebio/solvebio-ruby/blob/master/demo/query) contains examples of queries.
|
data/demo/cheatsheet.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
# Cheet sheet for SolveBio API
|
2
|
-
require 'solvebio'
|
3
|
-
|
4
|
-
# Load the Dataset object
|
5
|
-
dataset = SolveBio::Dataset.retrieve('ClinVar/2.0.0-1/Variants')
|
6
|
-
|
7
|
-
# Print the Dataset
|
8
|
-
puts dataset.query()
|
9
|
-
|
10
|
-
# Get help (fields/facets)
|
11
|
-
dataset.help()
|
12
|
-
|
13
|
-
# Query the dataset (filterless)
|
14
|
-
q = dataset.query()
|
15
|
-
|
16
|
-
filters = SolveBio::Filter.new :gene_symbols => "BRCA2"
|
17
|
-
|
18
|
-
puts dataset.query(:filters => filters)
|
19
|
-
|
20
|
-
# Multiple keyword filter (boolean 'or')
|
21
|
-
filters = SolveBio::Filter.new :gene_symbols => "BRCA2"
|
22
|
-
filters |= SolveBio::Filter.new :gene_symbols => "BRCA1"
|
23
|
-
|
24
|
-
# Same as above 'or' in one go using 'in'
|
25
|
-
filters = SolveBio::Filter.new :gene_symbols__in => ["BRCA2", "BRCA1"]
|
26
|
-
|
27
|
-
puts dataset.query(:filters => filters)
|
28
|
-
|
29
|
-
# Range filter. Like 'in' for a contiguous numeric range
|
30
|
-
dataset.query(filters =>
|
31
|
-
SolveBio::RangeFilter.new('hg38', "13", 32_200_000, 32_200_500))
|
data/demo/dataset/facets.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# Simple use of SolveBio::DatsetField.retrieve ... facets
|
3
|
-
|
4
|
-
require 'solvebio'
|
5
|
-
|
6
|
-
# SolveBio.api_key = 'set-me-correctly'
|
7
|
-
unless SolveBio.api_key
|
8
|
-
puts 'Please set SolveBio.api_key. Hint: solvebio.rb login'
|
9
|
-
exit 1
|
10
|
-
end
|
11
|
-
|
12
|
-
fields = SolveBio::DatasetField.retrieve(691).facets
|
13
|
-
puts fields
|
data/demo/dataset/field.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# Simple use of SolveBio::DatsetField.retrieve
|
3
|
-
|
4
|
-
require 'solvebio'
|
5
|
-
|
6
|
-
# SolveBio.api_key = 'set-me-correctly'
|
7
|
-
unless SolveBio.api_key
|
8
|
-
puts 'Please set SolveBio.api_key. Hint: solvebio.rb login'
|
9
|
-
exit 1
|
10
|
-
end
|
11
|
-
|
12
|
-
fields = SolveBio::DatasetField.retrieve(1)
|
13
|
-
puts fields
|
data/demo/depository/README.md
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
# Depositories
|
2
|
-
|
3
|
-
A *depository* (or data repository) is like a source code repository,
|
4
|
-
but for datasets. Depositories have one or more versions, which in
|
5
|
-
turn contain one or more datasets. Typically, depositories contain a
|
6
|
-
series of datasets that are compatible with each other (i.e. they come
|
7
|
-
from the same data source or project).
|
8
|
-
|
9
|
-
Right now, all depositories are curated by the SolveBio team.
|
10
|
-
|
11
|
-
* retrieve a depository
|
12
|
-
|
13
|
-
The [retrieve.rb](https://github.com/solvebio/solvebio-ruby/blob/master/demo/depository/retrieve.rb) Ruby program shows how to retrieve a single depository
|
14
|
-
|
15
|
-
* listing a depository
|
16
|
-
|
17
|
-
The [all.rb](https://github.com/solvebio/solvebio-ruby/blob/master/demo/depository/all.rb) Ruby program shows how to list all depositories
|
18
|
-
|
19
|
-
* list all versions of a depository
|
20
|
-
|
21
|
-
The [versions-all.rb](https://github.com/solvebio/solvebio-ruby/blob/master/demo/depository/all.rb) Ruby program shows how to list all versions
|
22
|
-
of a depository
|
23
|
-
|
24
|
-
See also the [SolveBio Depository API](https://www.solvebio.com/docs/api/#depositories)
|
data/demo/depository/all.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# Simple use of SolveBio::Depository.all
|
3
|
-
|
4
|
-
require 'solvebio'
|
5
|
-
|
6
|
-
# SolveBio.api_key = 'set-me-correctly'
|
7
|
-
unless SolveBio.api_key
|
8
|
-
puts 'Please set SolveBio::api_key. Hint: solvebio.rb login'
|
9
|
-
exit 1
|
10
|
-
end
|
11
|
-
|
12
|
-
depo = SolveBio::Depository.all
|
13
|
-
puts depo.to_s
|
data/demo/depository/retrieve.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# Simple use of SolveBio::Depository.retrieve
|
3
|
-
|
4
|
-
require 'solvebio'
|
5
|
-
|
6
|
-
# SolveBio.api_key = 'set-me-correctly'
|
7
|
-
unless SolveBio.api_key
|
8
|
-
puts 'Please set SolveBio.api_key. Hint: solvebio.rb login'
|
9
|
-
exit 1
|
10
|
-
end
|
11
|
-
|
12
|
-
depo = SolveBio::Depository.retrieve('ClinVar')
|
13
|
-
puts depo.to_s
|
@@ -1,13 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# Simple use of SolveBio::Depository.retrieve({DEPOSITORY_ID}).versions.all
|
3
|
-
|
4
|
-
require 'solvebio'
|
5
|
-
|
6
|
-
# SolveBio.api_key = 'set-me-correctly'
|
7
|
-
unless SolveBio.api_key
|
8
|
-
puts 'Please set SolveBio.api_key. Hint: solvebio.rb login'
|
9
|
-
exit 1
|
10
|
-
end
|
11
|
-
|
12
|
-
depo = SolveBio::Depository.retrieve('ClinVar').versions.all
|
13
|
-
puts depo.to_s
|
data/demo/query/query-filter.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# Simple use of SolveBio::Query with simple equality tests, sometimes
|
3
|
-
# with "and" or "or"
|
4
|
-
|
5
|
-
require 'solvebio'
|
6
|
-
|
7
|
-
# SolveBio.api_key = 'set-me-correctly'
|
8
|
-
unless SolveBio.api_key
|
9
|
-
puts 'Please set SolveBio.api_key. Hint: solvebio.rb login'
|
10
|
-
exit 1
|
11
|
-
end
|
12
|
-
|
13
|
-
ds = SolveBio::Dataset.retrieve('ClinVar/2.0.0-1/Variants')
|
14
|
-
|
15
|
-
results = ds.query.filter :hg19_start__in => [148562304, 148459988]
|
16
|
-
|
17
|
-
puts results.to_h # Show as a hash
|
18
|
-
puts '=' * 10
|
19
|
-
puts results # show in a more formatted way
|
20
|
-
|
21
|
-
# Here is the same thing but a little more inefficiently
|
22
|
-
|
23
|
-
filters2 =
|
24
|
-
SolveBio::Filter.new(:hg19_start => 148459988) |
|
25
|
-
SolveBio::Filter.new(:hg19_start => 148562304) |
|
26
|
-
|
27
|
-
results = ds.query(:filters => filters2)
|
28
|
-
|
29
|
-
puts '=' * 10
|
30
|
-
puts results
|
data/demo/query/query.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# Simple use of SolveBio::Query
|
3
|
-
|
4
|
-
require 'solvebio'
|
5
|
-
|
6
|
-
# SolveBio.api_key = 'set-me-correctly'
|
7
|
-
unless SolveBio.api_key
|
8
|
-
puts 'Please set SolveBio.api_key. Hint: solvebio.rb login'
|
9
|
-
exit 1
|
10
|
-
end
|
11
|
-
|
12
|
-
dataset = SolveBio::Dataset.retrieve('ClinVar/2.0.0-1/Variants')
|
13
|
-
puts dataset.query
|
data/demo/query/range-filter.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# Simple use of SolveBio::Query
|
3
|
-
|
4
|
-
require 'solvebio'
|
5
|
-
|
6
|
-
# SolveBio.api_key = 'set-me-correctly'
|
7
|
-
unless SolveBio.api_key
|
8
|
-
puts 'Please set SolveBio.api_key. Hint: solvebio.rb login'
|
9
|
-
exit 1
|
10
|
-
end
|
11
|
-
|
12
|
-
filters = SolveBio::RangeFilter.
|
13
|
-
new "hg38", "13", 32200000, 32500000
|
14
|
-
|
15
|
-
ds = SolveBio::Dataset.retrieve 'ClinVar/2.0.0-1/Variants'
|
16
|
-
|
17
|
-
results = ds.query(:filters => filters)
|
18
|
-
puts results
|
data/demo/test-api.rb
DELETED
@@ -1,98 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# Test SolveBio API
|
3
|
-
require_relative '../lib/solvebio'
|
4
|
-
|
5
|
-
DEPOSITORY = 'ClinVar'
|
6
|
-
DEPOSITORY_VERSION = "#{DEPOSITORY}/2.0.0-1"
|
7
|
-
DATASET = "#{DEPOSITORY_VERSION}/Variants"
|
8
|
-
|
9
|
-
# Custom Exception class for running basic tests
|
10
|
-
class TestFail < RuntimeError
|
11
|
-
end
|
12
|
-
|
13
|
-
DEBUG = ARGV.size > 1
|
14
|
-
|
15
|
-
# Function for running small tests with nice printing and checks
|
16
|
-
def run_and_verify(func, title='run a test', check_func_symbols)
|
17
|
-
puts "Trying to #{title}..."
|
18
|
-
response = func.call
|
19
|
-
check_func_symbols.each do |sym|
|
20
|
-
unless response.send(sym)
|
21
|
-
raise TestFail, "Failed on #{DATASET} using #{sym}"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
puts "\x1b[32mOK!\x1b[39m\n"
|
25
|
-
return response
|
26
|
-
end
|
27
|
-
|
28
|
-
creds = SolveBio::Credentials.get_credentials
|
29
|
-
unless creds
|
30
|
-
puts 'You must be logged in as a SolveBio user ' +
|
31
|
-
'in order to run the test suite!'
|
32
|
-
exit(1)
|
33
|
-
end
|
34
|
-
|
35
|
-
SolveBio::Client.client.api_key = creds[1]
|
36
|
-
|
37
|
-
begin
|
38
|
-
# depository things
|
39
|
-
load_depo = proc { SolveBio::DepositoryVersion.
|
40
|
-
retrieve(DEPOSITORY_VERSION) }
|
41
|
-
begin
|
42
|
-
dataset = run_and_verify(load_depo, 'load a depository version',
|
43
|
-
[:id, :to_s, :inspect, :instance_url])
|
44
|
-
rescue SolveBio::Error => exc
|
45
|
-
raise TestFail, "Loading #{DEPOSITORY_VERSION} failed! (#{exc})"
|
46
|
-
end
|
47
|
-
|
48
|
-
# depository things
|
49
|
-
load_depo = proc { SolveBio::Depository.retrieve(DEPOSITORY) }
|
50
|
-
begin
|
51
|
-
dataset = run_and_verify(load_depo, 'load a depository',
|
52
|
-
[:to_s, :versions, :versions_url,
|
53
|
-
:first, :max, :min])
|
54
|
-
rescue SolveBio::Error => exc
|
55
|
-
raise TestFail, "Loading #{DEPOSITORY} failed! (#{exc})"
|
56
|
-
end
|
57
|
-
|
58
|
-
# try loading a Dataset
|
59
|
-
load_dataset = proc { SolveBio::Dataset.retrieve(DATASET) }
|
60
|
-
begin
|
61
|
-
dataset = run_and_verify(load_dataset, 'load a dataset',
|
62
|
-
[:depository, :depository_version, :fields])
|
63
|
-
rescue SolveBio::Error => exc
|
64
|
-
raise TestFail, "Loading #{DATASET} failed! (#{exc})"
|
65
|
-
end
|
66
|
-
|
67
|
-
# try loading a DatasetField
|
68
|
-
load_dataset = proc { SolveBio::DatasetField.retrieve(1) }
|
69
|
-
begin
|
70
|
-
dataset = run_and_verify(load_dataset, 'load a dataset field',
|
71
|
-
[:facets, :instance_url])
|
72
|
-
rescue SolveBio::Error => exc
|
73
|
-
raise TestFail, "Loading DataSetField 1 failed! (#{exc})"
|
74
|
-
end
|
75
|
-
|
76
|
-
# run a basic query
|
77
|
-
query_dataset = proc {
|
78
|
-
dataset = SolveBio::Dataset.retrieve(DATASET)
|
79
|
-
dataset.query({:paging=>true, :limit => 10})
|
80
|
-
}
|
81
|
-
query = run_and_verify(query_dataset, 'run a basic query',
|
82
|
-
[:size, :inspect, :clone])
|
83
|
-
|
84
|
-
# # run a basic filter
|
85
|
-
# basic_filter = proc { query.filter(clinical_significance='Pathogenic') }
|
86
|
-
# run_and_verify(basic_filter, 'run a basic filter')
|
87
|
-
|
88
|
-
# # run a range filter
|
89
|
-
# range_filter = solvebio.RangeFilter(build="hg19",
|
90
|
-
# chromosome=1,
|
91
|
-
# start=100000,
|
92
|
-
# last=900000)
|
93
|
-
# run_and_verify(proc { query.filter(range_filter) },
|
94
|
-
# 'run a range filter')
|
95
|
-
|
96
|
-
rescue TestFail, exc
|
97
|
-
puts "\n\n\x1b[31mFAIL!\x1b[39m #{exc}"
|
98
|
-
end
|
data/lib/cli/auth.rb
DELETED
@@ -1,122 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# -*- coding: utf-8 -*-
|
3
|
-
|
4
|
-
require 'readline'
|
5
|
-
require 'io/console'
|
6
|
-
|
7
|
-
require_relative '../errors'
|
8
|
-
require_relative '../credentials'
|
9
|
-
require_relative '../client'
|
10
|
-
|
11
|
-
module SolveBio::Auth
|
12
|
-
|
13
|
-
def ask_for_credentials(email=nil)
|
14
|
-
while true
|
15
|
-
email ||= Readline.readline('Email address: ', true)
|
16
|
-
print 'Password (typing will be hidden): '
|
17
|
-
password = STDIN.noecho(&:gets).chomp
|
18
|
-
puts
|
19
|
-
# FIXME: validate email address?
|
20
|
-
if email and password
|
21
|
-
return email, password
|
22
|
-
else
|
23
|
-
# FIXME: could say which one is needed.
|
24
|
-
print 'Email and password are both required.'
|
25
|
-
return nil, nil
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def send_install_report
|
31
|
-
require 'socket';
|
32
|
-
data = {
|
33
|
-
:hostname => Socket.gethostname(),
|
34
|
-
:ruby_version => SolveBio::RUBY_VERSION,
|
35
|
-
:ruby_implementation => SolveBio::RUBY_IMPLEMENTATION,
|
36
|
-
# :platform => platform(),
|
37
|
-
:architecture => SolveBio::ARCHITECTURE,
|
38
|
-
# :processor => processor(),
|
39
|
-
}
|
40
|
-
SolveBio::Client.client
|
41
|
-
.request('post', '/v1/reports/install',
|
42
|
-
{:params => data}) rescue nil
|
43
|
-
end
|
44
|
-
|
45
|
-
|
46
|
-
include SolveBio::Credentials
|
47
|
-
|
48
|
-
module_function
|
49
|
-
|
50
|
-
#
|
51
|
-
# Prompt user for login information (email/password).
|
52
|
-
# Email and password are used to get the user's auth_token key.
|
53
|
-
#
|
54
|
-
def login(email=nil)
|
55
|
-
delete_credentials
|
56
|
-
|
57
|
-
email, password = ask_for_credentials email unless
|
58
|
-
email and password
|
59
|
-
data = {
|
60
|
-
:email => email,
|
61
|
-
:password => password
|
62
|
-
}
|
63
|
-
|
64
|
-
# FIXME: begin/rescue is a direct translation of the Python
|
65
|
-
# code. Not sure if it's valid here, or what the equivalent
|
66
|
-
# is.
|
67
|
-
begin
|
68
|
-
response = SolveBio::Client.client
|
69
|
-
.request 'post', '/v1/auth/token', {:payload => data}
|
70
|
-
rescue SolveBio::Error => e
|
71
|
-
puts "Login failed: #{e.to_s}"
|
72
|
-
return false
|
73
|
-
else
|
74
|
-
save_credentials(email.downcase, response['token'])
|
75
|
-
# reset the default client's auth token
|
76
|
-
SolveBio::Client.client.api_key = response['token']
|
77
|
-
send_install_report
|
78
|
-
puts 'You are now logged-in.'
|
79
|
-
return true
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def logout
|
84
|
-
if get_credentials()
|
85
|
-
delete_credentials()
|
86
|
-
SolveBio::Client.client.api_key = nil
|
87
|
-
puts 'You have been logged out.'
|
88
|
-
return true
|
89
|
-
else
|
90
|
-
puts 'You are not logged-in.'
|
91
|
-
return false
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
def whoami
|
96
|
-
creds = get_credentials()
|
97
|
-
if creds
|
98
|
-
puts creds[0]
|
99
|
-
return creds[0]
|
100
|
-
else
|
101
|
-
puts 'You are not logged-in.'
|
102
|
-
return nil
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
end # SolveBio::Auth
|
107
|
-
|
108
|
-
# Demo code
|
109
|
-
if __FILE__ == $0
|
110
|
-
include SolveBio::Auth
|
111
|
-
case ARGV[0]
|
112
|
-
when 'password'
|
113
|
-
email, password = ask_for_credentials
|
114
|
-
puts email, password
|
115
|
-
when 'login'
|
116
|
-
login
|
117
|
-
when 'logout'
|
118
|
-
logout
|
119
|
-
when 'whoami'
|
120
|
-
whoami
|
121
|
-
end
|
122
|
-
end
|