arvados 0.1.pre.20130710104038
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.
- checksums.yaml +7 -0
- data/lib/arvados.rb +195 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6d8302e2cefad2772e175c0144ab65c6d5bbb617
|
4
|
+
data.tar.gz: 75a8a641a6d0515496ef81d8c2019bb278e07040
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ce4cd9b45622b20b52508cad68069afcfea15bfb8e673aa76764607abb295ba6632d8588a2e070f8e41ff8f95aece4a732d76618e3953c0b3767509916b4b462
|
7
|
+
data.tar.gz: 8cbf824e87805119d078efb1ad29291a992ca8efb0dfce1e9108fd87ab45830c33ff56f69fa8a7a11ea89fbfca5fb6a368ec8e7f77c698d9950e8044c276b38c
|
data/lib/arvados.rb
ADDED
@@ -0,0 +1,195 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'google/api_client'
|
3
|
+
require 'active_support/inflector'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
ActiveSupport::Inflector.inflections do |inflect|
|
7
|
+
inflect.irregular 'specimen', 'specimens'
|
8
|
+
inflect.irregular 'human', 'humans'
|
9
|
+
end
|
10
|
+
|
11
|
+
module Kernel
|
12
|
+
def suppress_warnings
|
13
|
+
original_verbosity = $VERBOSE
|
14
|
+
$VERBOSE = nil
|
15
|
+
result = yield
|
16
|
+
$VERBOSE = original_verbosity
|
17
|
+
return result
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class Arvados
|
22
|
+
|
23
|
+
@@debuglevel = 0
|
24
|
+
class << self
|
25
|
+
attr_accessor :debuglevel
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize(opts={})
|
29
|
+
@application_version ||= 0.0
|
30
|
+
@application_name ||= File.split($0).last
|
31
|
+
|
32
|
+
@arvados_api_version = opts[:api_version] ||
|
33
|
+
ENV['ARVADOS_API_VERSION'] ||
|
34
|
+
'v1'
|
35
|
+
@arvados_api_host = opts[:api_host] ||
|
36
|
+
ENV['ARVADOS_API_HOST'] or
|
37
|
+
raise "#{$0}: no :api_host or ENV[ARVADOS_API_HOST] provided."
|
38
|
+
@arvados_api_token = opts[:api_token] ||
|
39
|
+
ENV['ARVADOS_API_TOKEN'] or
|
40
|
+
raise "#{$0}: no :api_token or ENV[ARVADOS_API_TOKEN] provided."
|
41
|
+
|
42
|
+
@suppress_ssl_warnings = opts[:suppress_ssl_warnings] || false
|
43
|
+
|
44
|
+
if @suppress_ssl_warnings
|
45
|
+
suppress_warnings do
|
46
|
+
OpenSSL::SSL.const_set 'VERIFY_PEER', OpenSSL::SSL::VERIFY_NONE
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Define a class and an Arvados instance method for each Arvados
|
51
|
+
# resource. After this, self.job will return Arvados::Job;
|
52
|
+
# self.job.new() and self.job.find() will do what you want.
|
53
|
+
_arvados = self
|
54
|
+
self.arvados_api.schemas.each do |classname, schema|
|
55
|
+
next if classname.match /List$/
|
56
|
+
klass = Class.new(Arvados::Model) do
|
57
|
+
def self.arvados
|
58
|
+
@arvados
|
59
|
+
end
|
60
|
+
def self.api_models_sym
|
61
|
+
@api_models_sym
|
62
|
+
end
|
63
|
+
def self.api_model_sym
|
64
|
+
@api_model_sym
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# Define the resource methods (create, get, update, delete, ...)
|
69
|
+
self.
|
70
|
+
arvados_api.
|
71
|
+
send(classname.underscore.split('/').last.pluralize.to_sym).
|
72
|
+
discovered_methods.
|
73
|
+
collect(&:name).
|
74
|
+
each do |method_name|
|
75
|
+
class << klass; self; end.class_eval do
|
76
|
+
define_method method_name do |*params|
|
77
|
+
self.api_exec(method_name.to_sym, *params)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# Give the new class access to the API
|
83
|
+
klass.instance_eval do
|
84
|
+
@arvados = _arvados
|
85
|
+
# These should be pulled from the discovery document instead:
|
86
|
+
@api_models_sym = classname.underscore.split('/').last.pluralize.to_sym
|
87
|
+
@api_model_sym = classname.underscore.split('/').last.to_sym
|
88
|
+
end
|
89
|
+
|
90
|
+
# This might produce confusing results when using multiple
|
91
|
+
# Arvados instances.
|
92
|
+
Arvados.const_set classname, klass
|
93
|
+
|
94
|
+
self.class.class_eval do
|
95
|
+
define_method classname.underscore do
|
96
|
+
klass
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
class Google::APIClient
|
103
|
+
def discovery_document(api, version)
|
104
|
+
api = api.to_s
|
105
|
+
return @discovery_documents["#{api}:#{version}"] ||=
|
106
|
+
begin
|
107
|
+
response = self.execute!(
|
108
|
+
:http_method => :get,
|
109
|
+
:uri => self.discovery_uri(api, version),
|
110
|
+
:authenticated => false
|
111
|
+
)
|
112
|
+
response.body.class == String ? JSON.parse(response.body) : response.body
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def client
|
118
|
+
@client ||= Google::APIClient.
|
119
|
+
new(:host => @arvados_api_host,
|
120
|
+
:application_name => @application_name,
|
121
|
+
:application_version => @application_version.to_s)
|
122
|
+
end
|
123
|
+
|
124
|
+
def arvados_api
|
125
|
+
@arvados_api ||= self.client.discovered_api('arvados', @arvados_api_version)
|
126
|
+
end
|
127
|
+
|
128
|
+
def self.debuglog(message, verbosity=1)
|
129
|
+
$stderr.puts "#{File.split($0).last} #{$$}: #{message}" if @@debuglevel >= verbosity
|
130
|
+
end
|
131
|
+
|
132
|
+
class Model
|
133
|
+
def self.arvados_api
|
134
|
+
arvados.arvados_api
|
135
|
+
end
|
136
|
+
def self.client
|
137
|
+
arvados.client
|
138
|
+
end
|
139
|
+
def self.debuglog(*args)
|
140
|
+
arvados.class.debuglog *args
|
141
|
+
end
|
142
|
+
def debuglog(*args)
|
143
|
+
self.class.arvados.class.debuglog *args
|
144
|
+
end
|
145
|
+
def self.api_exec(method, parameters={})
|
146
|
+
parameters = parameters.
|
147
|
+
merge(:api_token => ENV['ARVADOS_API_TOKEN'])
|
148
|
+
parameters.each do |k,v|
|
149
|
+
parameters[k] = v.to_json if v.is_a? Array or v.is_a? Hash
|
150
|
+
end
|
151
|
+
result = client.
|
152
|
+
execute(:api_method => arvados_api.send(api_models_sym).send(method),
|
153
|
+
:authenticated => false,
|
154
|
+
:parameters => parameters)
|
155
|
+
JSON.parse result.body, :symbolize_names => true
|
156
|
+
end
|
157
|
+
|
158
|
+
def []=(x,y)
|
159
|
+
@attributes_to_update[x] = y
|
160
|
+
@attributes[x] = y
|
161
|
+
end
|
162
|
+
def [](x)
|
163
|
+
if @attributes[x].is_a? Hash or @attributes[x].is_a? Array
|
164
|
+
# We won't be notified via []= if these change, so we'll just
|
165
|
+
# assume they are going to get changed, and submit them if
|
166
|
+
# save() is called.
|
167
|
+
@attributes_to_update[x] = @attributes[x]
|
168
|
+
end
|
169
|
+
@attributes[x]
|
170
|
+
end
|
171
|
+
def save
|
172
|
+
@attributes_to_update.keys.each do |k|
|
173
|
+
@attributes_to_update[k] = @attributes[k]
|
174
|
+
end
|
175
|
+
j = self.class.api_exec :update, {
|
176
|
+
:uuid => @attributes[:uuid],
|
177
|
+
self.class.api_model_sym => @attributes_to_update.to_json
|
178
|
+
}
|
179
|
+
unless j.is_a? Hash and j[:uuid]
|
180
|
+
debuglog "Failed to save #{self.to_s}: #{j[:errors] rescue nil}", 0
|
181
|
+
nil
|
182
|
+
else
|
183
|
+
@attributes_to_update = {}
|
184
|
+
@attributes = j
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
protected
|
189
|
+
|
190
|
+
def initialize(j)
|
191
|
+
@attributes_to_update = {}
|
192
|
+
@attributes = j
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: arvados
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.pre.20130710104038
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Arvados Authors
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: google-api-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.6.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.6.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.2.13
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.2.13
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: json
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.7.7
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.7.7
|
55
|
+
description: This is the Arvados SDK gem, git revision 7a5ae650df19557a5fa88a8a1ae73ae07cad01cf
|
56
|
+
email: gem-dev@clinicalfuture.com
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- lib/arvados.rb
|
62
|
+
homepage: http://arvados.org
|
63
|
+
licenses:
|
64
|
+
- Apache License, Version 2.0
|
65
|
+
metadata: {}
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - '>'
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 1.3.1
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 2.0.0
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: Arvados SDK Ruby
|
86
|
+
test_files: []
|