solvebio 1.6.1 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/.bumpversion.cfg
ADDED
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -1,35 +1,49 @@
|
|
|
1
1
|
[](https://travis-ci.org/solvebio/solvebio-ruby)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
SolveBio Ruby Client
|
|
4
|
+
====================
|
|
4
5
|
|
|
6
|
+
This is the SolveBio Ruby module and command-line interface (CLI).
|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
For more information about SolveBio, see [solvebio.com](https://www.solvebio.com).
|
|
7
9
|
|
|
8
|
-
For more information about the SolveBio API, https://www.solvebio.com/docs/api/
|
|
9
|
-
For more information about SolveBio, see https://www.solvebio.com
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
Guided Installation
|
|
12
|
+
-------------------
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
To use the guided installer, open up your terminal and paste this:
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
curl -kL install.solvebio.com/ruby | bash
|
|
16
17
|
|
|
17
|
-
git clone https://github.com/solvebio/solvebio-ruby.git
|
|
18
|
-
cd solvebio-ruby
|
|
19
|
-
gem install netrc # install gem dependencies, may need sudo
|
|
20
|
-
rake test # or "make test"
|
|
21
|
-
sudo rake install # or "make install"
|
|
22
18
|
|
|
23
|
-
|
|
19
|
+
Manual Installation
|
|
20
|
+
-------------------
|
|
21
|
+
|
|
22
|
+
sudo gem install solvebio
|
|
23
|
+
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
Installing from Git
|
|
26
|
+
-------------------
|
|
27
|
+
|
|
28
|
+
First, install dependencies:
|
|
29
|
+
|
|
30
|
+
gem install rest_client
|
|
31
|
+
gem install addressable
|
|
32
|
+
gem install netrc
|
|
33
|
+
|
|
34
|
+
Install from source:
|
|
26
35
|
|
|
27
36
|
git clone https://github.com/solvebio/solvebio-ruby.git
|
|
28
|
-
solvebio-ruby
|
|
37
|
+
cd solvebio-ruby
|
|
38
|
+
rake test
|
|
39
|
+
sudo rake install
|
|
40
|
+
|
|
29
41
|
|
|
30
|
-
will
|
|
42
|
+
This will install the `solvebio` gem and the `solvebio.rb` CLI.
|
|
31
43
|
|
|
32
|
-
|
|
44
|
+
|
|
45
|
+
Optional Dependencies
|
|
46
|
+
---------------------
|
|
33
47
|
|
|
34
48
|
The following optional gems can make your shell experience better
|
|
35
49
|
|
|
@@ -45,22 +59,8 @@ The following optional gems can make your shell experience better
|
|
|
45
59
|
|
|
46
60
|
Localization for number formatting
|
|
47
61
|
|
|
48
|
-
# Demo code and Documentation
|
|
49
|
-
|
|
50
|
-
See the [demo folder](https://github.com/solvebio/solvebio-ruby/tree/master/demo) for ready-to-run examples.
|
|
51
|
-
|
|
52
|
-
The online [SolveBio Python API documentation](https://www.solvebio.com/docs/api/?python) has additional examples. To use these with the Ruby client, change `import solvebio` to `require 'solvebio'` and change `solvebio.` to `SolveBio::` everywhere it occurs.
|
|
53
|
-
|
|
54
|
-
e.g., a Python example:
|
|
55
|
-
|
|
56
|
-
solvebio.Depository.retrieve("ClinVar").versions()
|
|
57
|
-
|
|
58
|
-
the same Python example ported to Ruby:
|
|
59
|
-
|
|
60
|
-
SolveBio::Depository.retrieve("ClinVar").versions()
|
|
61
|
-
|
|
62
|
-
As with any other Ruby method call, you can drop the final parenthesis if you like.
|
|
63
62
|
|
|
64
|
-
|
|
63
|
+
Documentation
|
|
64
|
+
-------------
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
See the [SolveBio API Reference](https://www.solvebio.com/docs/api/?ruby) for more information about using the API.
|
data/Rakefile
CHANGED
|
@@ -10,12 +10,10 @@ end
|
|
|
10
10
|
|
|
11
11
|
require 'rubygems/package_task'
|
|
12
12
|
|
|
13
|
-
desc "Validate the gemspec"
|
|
14
13
|
task :gemspec do
|
|
15
14
|
gemspec.validate
|
|
16
15
|
end
|
|
17
16
|
|
|
18
|
-
desc "Build the gem"
|
|
19
17
|
task :package=>:gem
|
|
20
18
|
task :gem=>:gemspec do
|
|
21
19
|
Dir.chdir(ROOT_DIR) do
|
|
@@ -25,7 +23,6 @@ task :gem=>:gemspec do
|
|
|
25
23
|
end
|
|
26
24
|
end
|
|
27
25
|
|
|
28
|
-
desc "Install the gem locally"
|
|
29
26
|
task :install => :gem do
|
|
30
27
|
Dir.chdir(ROOT_DIR) do
|
|
31
28
|
sh %{gem install --both pkg/#{gemspec.file_name}}
|
|
@@ -33,27 +30,13 @@ task :install => :gem do
|
|
|
33
30
|
end
|
|
34
31
|
|
|
35
32
|
require 'rake/testtask'
|
|
36
|
-
desc "Test everything."
|
|
37
33
|
Rake::TestTask.new(:test) do |t|
|
|
38
34
|
t.libs << './lib'
|
|
39
|
-
t.
|
|
35
|
+
t.pattern = './test/**/test*.rb'
|
|
40
36
|
t.verbose = true
|
|
41
37
|
end
|
|
42
38
|
|
|
43
|
-
|
|
44
|
-
require 'rbconfig'
|
|
45
|
-
RUBY_PATH = File.join(RbConfig::CONFIG['bindir'],
|
|
46
|
-
RbConfig::CONFIG['RUBY_INSTALL_NAME'])
|
|
47
|
-
desc "Run all of the demo files."
|
|
48
|
-
task :'run-demo' do
|
|
49
|
-
FileList['demo/*.rb']+FileList['demo/*/*.rb'].each do |ruby_file|
|
|
50
|
-
puts(('-' * 20) + ' ' + ruby_file + ' ' + ('-' * 20))
|
|
51
|
-
system(RUBY_PATH, ruby_file)
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
55
39
|
task :test => :lib
|
|
56
40
|
|
|
57
|
-
desc "same as test"
|
|
58
41
|
task :check => :test
|
|
59
42
|
task :default => :test
|
data/bin/solvebio.rb
CHANGED
|
@@ -1,36 +1,34 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
# -*- coding: utf-8 -*-
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
require_relative '../lib/solvebio'
|
|
7
|
-
require_relative '../lib/cli/options'
|
|
8
|
-
require_relative '../lib/cli/irb'
|
|
4
|
+
require 'solvebio'
|
|
5
|
+
require 'solvebio/cli'
|
|
9
6
|
|
|
10
7
|
DIR = File.dirname(__FILE__)
|
|
11
|
-
TEST_PROGRAM = File.join(DIR, %w(.. demo test-api.rb))
|
|
12
|
-
|
|
13
|
-
include SolveBio::CLIOptions
|
|
14
|
-
options, rest, parser = process_options(ARGV)
|
|
15
8
|
|
|
16
|
-
|
|
9
|
+
include SolveBio
|
|
10
|
+
include SolveBio::CLI
|
|
11
|
+
include SolveBio::CLI::Auth
|
|
12
|
+
include SolveBio::CLI::Credentials
|
|
13
|
+
include SolveBio::CLI::Tutorial
|
|
17
14
|
|
|
18
|
-
|
|
15
|
+
options, argv = process_options(ARGV)
|
|
16
|
+
argv = ['shell'] if argv.empty?
|
|
19
17
|
|
|
20
|
-
cmd =
|
|
18
|
+
cmd = argv.shift
|
|
21
19
|
case cmd
|
|
22
20
|
when 'shell'
|
|
23
21
|
IRB::shell
|
|
24
22
|
when 'login'
|
|
25
|
-
login
|
|
23
|
+
login
|
|
26
24
|
when 'logout'
|
|
27
25
|
logout
|
|
28
26
|
when 'whoami'
|
|
29
27
|
whoami
|
|
30
|
-
when '
|
|
31
|
-
|
|
28
|
+
when 'tutorial'
|
|
29
|
+
tutorial
|
|
32
30
|
else
|
|
33
|
-
$stderr.puts "Unknown
|
|
31
|
+
$stderr.puts "Unknown subcommand command: #{cmd}"
|
|
34
32
|
$stderr.puts parser
|
|
35
33
|
exit 1
|
|
36
34
|
end
|
data/installer
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
#
|
|
3
|
+
# This is the guided installer for the SolveBio Ruby Client:
|
|
4
|
+
#
|
|
5
|
+
# curl -kL install.solve.bio/ruby | bash
|
|
6
|
+
#
|
|
7
|
+
|
|
8
|
+
echo
|
|
9
|
+
echo " ____ _ ____ _"
|
|
10
|
+
echo " / ___| ___ | |_ _____| __ )(_) ___"
|
|
11
|
+
echo " \___ \ / _ \| \ \ / / _ \ _ \| |/ _ \\"
|
|
12
|
+
echo " ___) | (_) | |\ V / __/ |_) | | (_) |"
|
|
13
|
+
echo " |____/ \___/|_| \_/ \___|____/|_|\___/"
|
|
14
|
+
echo
|
|
15
|
+
echo " Copyright © 2014 Solve, Inc. <https://www.solvebio.com>. All rights reserved."
|
|
16
|
+
echo
|
|
17
|
+
|
|
18
|
+
shopt -s extglob
|
|
19
|
+
|
|
20
|
+
function fail_exit() {
|
|
21
|
+
echo
|
|
22
|
+
echo " #####################################"
|
|
23
|
+
echo
|
|
24
|
+
echo " Failed to install SolveBio."
|
|
25
|
+
echo " Contact us at support@solvebio.com"
|
|
26
|
+
echo
|
|
27
|
+
echo " #####################################"
|
|
28
|
+
echo
|
|
29
|
+
exit
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
trap ctrl_c INT
|
|
33
|
+
|
|
34
|
+
function ctrl_c() {
|
|
35
|
+
echo
|
|
36
|
+
echo
|
|
37
|
+
echo " Installation was aborted..."
|
|
38
|
+
fail_exit
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
echo " Installing SolveBio for Ruby..."
|
|
42
|
+
echo
|
|
43
|
+
echo " IMPORTANT: Your computer's password may be required. It will NOT be sent to SolveBio."
|
|
44
|
+
|
|
45
|
+
# Are we installing or upgrading?
|
|
46
|
+
if [ $(gem list | grep solvebio -c) -ne 0 ]; then
|
|
47
|
+
sudo gem update -q solvebio 2>&1 > /dev/null
|
|
48
|
+
else
|
|
49
|
+
sudo gem install -q solvebio 2>&1 > /dev/null
|
|
50
|
+
fi
|
|
51
|
+
|
|
52
|
+
if [ $? -eq 0 ]; then
|
|
53
|
+
echo
|
|
54
|
+
echo " ##############################################"
|
|
55
|
+
echo
|
|
56
|
+
echo " Success! SolveBio for Ruby is now installed."
|
|
57
|
+
echo
|
|
58
|
+
echo " Please run 'solvebio.rb login' to finish the setup."
|
|
59
|
+
echo
|
|
60
|
+
echo " ##############################################"
|
|
61
|
+
echo
|
|
62
|
+
else
|
|
63
|
+
fail_exit
|
|
64
|
+
fi
|
data/lib/solvebio.rb
CHANGED
|
@@ -1,14 +1,53 @@
|
|
|
1
|
-
#
|
|
2
|
-
#
|
|
1
|
+
# SolveBio Ruby bindings
|
|
2
|
+
# Learn more at https://www.solvebio.com/docs/api
|
|
3
|
+
require 'logger'
|
|
4
|
+
require 'fileutils'
|
|
5
|
+
require 'json'
|
|
6
|
+
require 'logger'
|
|
7
|
+
require 'netrc'
|
|
8
|
+
require 'openssl'
|
|
9
|
+
require 'rest_client'
|
|
10
|
+
require 'uri'
|
|
11
|
+
require 'addressable/uri'
|
|
12
|
+
require 'set'
|
|
3
13
|
|
|
4
|
-
|
|
5
|
-
|
|
14
|
+
require 'solvebio/version'
|
|
15
|
+
require 'solvebio/util'
|
|
16
|
+
require 'solvebio/tabulate'
|
|
17
|
+
require 'solvebio/solve_object'
|
|
18
|
+
require 'solvebio/api_resource'
|
|
19
|
+
require 'solvebio/singleton_api_resource'
|
|
20
|
+
require 'solvebio/list_object'
|
|
21
|
+
require 'solvebio/client'
|
|
22
|
+
require 'solvebio/api_operations'
|
|
23
|
+
require 'solvebio/locale'
|
|
24
|
+
require 'solvebio/query'
|
|
25
|
+
require 'solvebio/filter'
|
|
26
|
+
require 'solvebio/acccount'
|
|
27
|
+
require 'solvebio/annotation'
|
|
28
|
+
require 'solvebio/dataset'
|
|
29
|
+
require 'solvebio/dataset_field'
|
|
30
|
+
require 'solvebio/depository'
|
|
31
|
+
require 'solvebio/depository_version'
|
|
32
|
+
require 'solvebio/sample'
|
|
33
|
+
require 'solvebio/user'
|
|
34
|
+
require 'solvebio/errors'
|
|
6
35
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
36
|
+
module SolveBio
|
|
37
|
+
class << self
|
|
38
|
+
attr_accessor :api_key, :api_host, :logger
|
|
39
|
+
end
|
|
10
40
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
41
|
+
@api_key = ENV['SOLVEBIO_API_KEY']
|
|
42
|
+
@api_host = ENV['SOLVEBIO_API_HOST'] || 'https://api.solvebio.com'
|
|
43
|
+
|
|
44
|
+
logfile =
|
|
45
|
+
if ENV['SOLVEBIO_LOGFILE']
|
|
46
|
+
ENV['SOLVEBIO_LOGFILE']
|
|
47
|
+
else
|
|
48
|
+
dir = File::expand_path '~/.solvebio'
|
|
49
|
+
FileUtils.mkdir_p(dir) unless File.exist? dir
|
|
50
|
+
File::expand_path File.join(dir, 'solvebio.log')
|
|
51
|
+
end
|
|
52
|
+
@logger = Logger.new(logfile)
|
|
53
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Annotations are genomic samples that have been annotated.
|
|
2
|
+
# See https://www.solvebio.com/docs/api/?ruby#annotations
|
|
3
|
+
module SolveBio
|
|
4
|
+
class Annotation < APIResource
|
|
5
|
+
include SolveBio::APIOperations::Create
|
|
6
|
+
include SolveBio::APIOperations::Update
|
|
7
|
+
include SolveBio::APIOperations::Download
|
|
8
|
+
include SolveBio::APIOperations::List
|
|
9
|
+
include SolveBio::APIOperations::Delete
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
module SolveBio
|
|
2
|
+
module APIOperations
|
|
3
|
+
module Create
|
|
4
|
+
module ClassMethods
|
|
5
|
+
def create(params={})
|
|
6
|
+
response = Client.request('post', url, {:payload => params} )
|
|
7
|
+
Util.to_solve_object(response)
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.included(base)
|
|
12
|
+
base.extend(ClassMethods)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
module Delete
|
|
17
|
+
def delete(params={})
|
|
18
|
+
response = Client.request('delete', url, params)
|
|
19
|
+
refresh_from(response)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
module Update
|
|
24
|
+
def save
|
|
25
|
+
refresh_from(request('patch', url,
|
|
26
|
+
{:payload => serialize(self)}))
|
|
27
|
+
return self
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def serialize(obj)
|
|
31
|
+
params = {}
|
|
32
|
+
if obj.unsaved_values
|
|
33
|
+
obj.unsaved_values.each do |k|
|
|
34
|
+
next if k == 'id'
|
|
35
|
+
params[k] = getattr(obj, k) or ''
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
params
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
module Download
|
|
43
|
+
def download(path=nil)
|
|
44
|
+
download_url = url + '/download'
|
|
45
|
+
response = Client.get(download_url, :raw => true)
|
|
46
|
+
|
|
47
|
+
if response.code != 302
|
|
48
|
+
# Some kind of error. We expect a redirect
|
|
49
|
+
raise SolveError('Could not download file: response code' %
|
|
50
|
+
response.status_code)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
download_url = response.headers[:location]
|
|
54
|
+
filename = download_url.split('%3B%20filename%3D')[1]
|
|
55
|
+
|
|
56
|
+
path = Dir.tmpdir unless path
|
|
57
|
+
filename = File.join(path, filename)
|
|
58
|
+
response = nil
|
|
59
|
+
|
|
60
|
+
response = Client.get(download_url, :raw => true,
|
|
61
|
+
:default_headers => false)
|
|
62
|
+
|
|
63
|
+
File.open(filename, 'wb') do |fh|
|
|
64
|
+
fh.write(response.body)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
self['filename'] = filename
|
|
68
|
+
self['code'] = response.code
|
|
69
|
+
self
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
module Help
|
|
74
|
+
attr_reader :have_launchy
|
|
75
|
+
|
|
76
|
+
@@have_launchy = false
|
|
77
|
+
begin
|
|
78
|
+
@@have_launchy = require 'launchy'
|
|
79
|
+
rescue LoadError
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def self.included base
|
|
83
|
+
base.send :include, InstanceMethods
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
module InstanceMethods
|
|
87
|
+
def help
|
|
88
|
+
open_help(self['full_name'])
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def open_help(path)
|
|
93
|
+
url = URI::join('https://www.solvebio.com/', path)
|
|
94
|
+
if @@have_launchy
|
|
95
|
+
Launchy.open(url)
|
|
96
|
+
else
|
|
97
|
+
puts('The SolveBio Ruby client needs the "launchy" gem to ' +
|
|
98
|
+
"open help url: #{url.to_s}")
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
module List
|
|
104
|
+
module ClassMethods
|
|
105
|
+
def all(params={})
|
|
106
|
+
response = Client.get(url, {:params => params})
|
|
107
|
+
Util.to_solve_object(response)
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def self.included base
|
|
112
|
+
base.extend ClassMethods
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def to_s
|
|
116
|
+
if self.class.constants.member?(:TAB_FIELDS)
|
|
117
|
+
items = self.class.const_get(:TAB_FIELDS).map{
|
|
118
|
+
|name| [name, self[name]]
|
|
119
|
+
}
|
|
120
|
+
else
|
|
121
|
+
items = self
|
|
122
|
+
end
|
|
123
|
+
return Tabulate.tabulate(items, ['Fields', 'Data'],
|
|
124
|
+
['right', 'left'], true)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def size
|
|
128
|
+
self[:total]
|
|
129
|
+
end
|
|
130
|
+
alias :total :size
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
module Search
|
|
134
|
+
module ClassMethods
|
|
135
|
+
def search(query='', params={})
|
|
136
|
+
params['q'] = query
|
|
137
|
+
response = Client.get(url, {:params => params})
|
|
138
|
+
Util.to_solve_object(response)
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def self.included base
|
|
143
|
+
base.extend ClassMethods
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
end
|