arvados 0.1.20140117103233 → 0.1.20140209152900

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/arvados.rb +70 -16
  3. metadata +70 -82
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d730f67cac173e2ed364c0efcf1934d03fc38a8e
4
+ data.tar.gz: 6f4d30d91f02eab3992852d200083bbfeb648318
5
+ SHA512:
6
+ metadata.gz: 89075e33b692d8b5636dbfda526e122e9a89fb4da918dae53416abda92d4cfa2361537783b77c34cfb8e5243fc66ef5025547f0d13b9f55b6431dc089946e7c6
7
+ data.tar.gz: 9b7cf63edc1f2e0978d73e5760d428360186604abce8a495206837731717734ca2c709f630969f302335460df6e0724df0d9c82a18990c4a916777851722b49f
data/lib/arvados.rb CHANGED
@@ -2,6 +2,8 @@ require 'rubygems'
2
2
  require 'google/api_client'
3
3
  require 'active_support/inflector'
4
4
  require 'json'
5
+ require 'fileutils'
6
+ require 'andand'
5
7
 
6
8
  ActiveSupport::Inflector.inflections do |inflect|
7
9
  inflect.irregular 'specimen', 'specimens'
@@ -23,6 +25,7 @@ class Arvados
23
25
  class TransactionFailedError < StandardError
24
26
  end
25
27
 
28
+ @@config = nil
26
29
  @@debuglevel = 0
27
30
  class << self
28
31
  attr_accessor :debuglevel
@@ -33,17 +36,17 @@ class Arvados
33
36
  @application_name ||= File.split($0).last
34
37
 
35
38
  @arvados_api_version = opts[:api_version] ||
36
- ENV['ARVADOS_API_VERSION'] ||
39
+ config['ARVADOS_API_VERSION'] ||
37
40
  'v1'
38
41
  @arvados_api_host = opts[:api_host] ||
39
- ENV['ARVADOS_API_HOST'] or
42
+ config['ARVADOS_API_HOST'] or
40
43
  raise "#{$0}: no :api_host or ENV[ARVADOS_API_HOST] provided."
41
44
  @arvados_api_token = opts[:api_token] ||
42
- ENV['ARVADOS_API_TOKEN'] or
45
+ config['ARVADOS_API_TOKEN'] or
43
46
  raise "#{$0}: no :api_token or ENV[ARVADOS_API_TOKEN] provided."
44
47
 
45
- if (opts[:api_host] ? opts[:suppress_ssl_warnings] :
46
- ENV['ARVADOS_API_HOST_INSECURE'])
48
+ if (opts[:suppress_ssl_warnings] or
49
+ config['ARVADOS_API_HOST_INSECURE'])
47
50
  suppress_warnings do
48
51
  OpenSSL::SSL.const_set 'VERIFY_PEER', OpenSSL::SSL::VERIFY_NONE
49
52
  end
@@ -76,7 +79,7 @@ class Arvados
76
79
  each do |method|
77
80
  class << klass; self; end.class_eval do
78
81
  define_method method.name do |*params|
79
- self.api_exec(method.name.to_sym, *params)
82
+ self.api_exec method, *params
80
83
  end
81
84
  end
82
85
  end
@@ -84,7 +87,7 @@ class Arvados
84
87
  # Give the new class access to the API
85
88
  klass.instance_eval do
86
89
  @arvados = _arvados
87
- # These should be pulled from the discovery document instead:
90
+ # TODO: Pull these from the discovery document instead.
88
91
  @api_models_sym = classname.underscore.split('/').last.pluralize.to_sym
89
92
  @api_model_sym = classname.underscore.split('/').last.to_sym
90
93
  end
@@ -107,12 +110,19 @@ class Arvados
107
110
  api = api.to_s
108
111
  return @discovery_documents["#{api}:#{version}"] ||=
109
112
  begin
110
- response = self.execute!(
111
- :http_method => :get,
112
- :uri => self.discovery_uri(api, version),
113
- :authenticated => false
114
- )
115
- response.body.class == String ? JSON.parse(response.body) : response.body
113
+ # fetch new API discovery doc if stale
114
+ cached_doc = File.expand_path '~/.cache/arvados/discovery_uri.json'
115
+ if not File.exist?(cached_doc) or (Time.now - File.mtime(cached_doc)) > 86400
116
+ response = self.execute!(:http_method => :get,
117
+ :uri => self.discovery_uri(api, version),
118
+ :authenticated => false)
119
+ FileUtils.makedirs(File.dirname cached_doc)
120
+ File.open(cached_doc, 'w') do |f|
121
+ f.puts response.body
122
+ end
123
+ end
124
+
125
+ File.open(cached_doc) { |f| JSON.load f }
116
126
  end
117
127
  end
118
128
  end
@@ -132,6 +142,37 @@ class Arvados
132
142
  $stderr.puts "#{File.split($0).last} #{$$}: #{message}" if @@debuglevel >= verbosity
133
143
  end
134
144
 
145
+ def config(config_file_path="~/.config/arvados/settings.conf")
146
+ return @@config if @@config
147
+
148
+ # Initialize config settings with environment variables.
149
+ config = {}
150
+ config['ARVADOS_API_HOST'] = ENV['ARVADOS_API_HOST']
151
+ config['ARVADOS_API_TOKEN'] = ENV['ARVADOS_API_TOKEN']
152
+ config['ARVADOS_API_HOST_INSECURE'] = ENV['ARVADOS_API_HOST_INSECURE']
153
+ config['ARVADOS_API_VERSION'] = ENV['ARVADOS_API_VERSION']
154
+
155
+ expanded_path = File.expand_path config_file_path
156
+ if File.exist? expanded_path
157
+ # Load settings from the config file.
158
+ lineno = 0
159
+ File.open(expanded_path).each do |line|
160
+ lineno = lineno + 1
161
+ # skip comments and blank lines
162
+ next if line.match('^\s*#') or not line.match('\S')
163
+ var, val = line.chomp.split('=', 2)
164
+ # allow environment settings to override config files.
165
+ if var and val
166
+ config[var] ||= val
167
+ else
168
+ warn "#{expanded_path}: #{lineno}: could not parse `#{line}'"
169
+ end
170
+ end
171
+ end
172
+
173
+ @@config = config
174
+ end
175
+
135
176
  class Model
136
177
  def self.arvados_api
137
178
  arvados.arvados_api
@@ -146,15 +187,28 @@ class Arvados
146
187
  self.class.arvados.class.debuglog *args
147
188
  end
148
189
  def self.api_exec(method, parameters={})
190
+ api_method = arvados_api.send(api_models_sym).send(method.name.to_sym)
149
191
  parameters = parameters.
150
- merge(:api_token => ENV['ARVADOS_API_TOKEN'])
192
+ merge(:api_token => arvados.config['ARVADOS_API_TOKEN'])
151
193
  parameters.each do |k,v|
152
194
  parameters[k] = v.to_json if v.is_a? Array or v.is_a? Hash
153
195
  end
196
+ # Look for objects expected by request.properties.(key).$ref and
197
+ # move them from parameters (query string) to request body.
198
+ body = nil
199
+ method.discovery_document['request'].
200
+ andand['properties'].
201
+ andand.each do |k,v|
202
+ if v.is_a? Hash and v['$ref']
203
+ body ||= {}
204
+ body[k] = parameters.delete k.to_sym
205
+ end
206
+ end
154
207
  result = client.
155
- execute(:api_method => arvados_api.send(api_models_sym).send(method),
208
+ execute(:api_method => api_method,
156
209
  :authenticated => false,
157
- :parameters => parameters)
210
+ :parameters => parameters,
211
+ :body => body)
158
212
  resp = JSON.parse result.body, :symbolize_names => true
159
213
  if resp[:errors]
160
214
  raise Arvados::TransactionFailedError.new(resp[:errors])
metadata CHANGED
@@ -1,112 +1,100 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: arvados
3
- version: !ruby/object:Gem::Version
4
- hash: 40280234206489
5
- prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 20140117103233
10
- version: 0.1.20140117103233
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.20140209152900
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Arvados Authors
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2014-01-17 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
11
+ date: 2014-02-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
21
14
  name: google-api-client
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 1
29
- segments:
30
- - 0
31
- - 6
32
- - 3
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
33
19
  version: 0.6.3
34
20
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: activesupport
38
21
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
40
- none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 21
45
- segments:
46
- - 3
47
- - 2
48
- - 13
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
49
33
  version: 3.2.13
50
34
  type: :runtime
51
- version_requirements: *id002
52
- - !ruby/object:Gem::Dependency
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
53
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
54
49
  prerelease: false
55
- requirement: &id003 !ruby/object:Gem::Requirement
56
- none: false
57
- requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- hash: 5
61
- segments:
62
- - 1
63
- - 7
64
- - 7
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
65
54
  version: 1.7.7
55
+ - !ruby/object:Gem::Dependency
56
+ name: andand
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
66
62
  type: :runtime
67
- version_requirements: *id003
68
- description: This is the Arvados SDK gem, git revision 3055130be14ab26d68fd1c01a934870855ecbd5c
69
- email: gem-dev@clinicalfuture.com
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: This is the Arvados SDK gem, git revision ff963e6ce16fc276cb41b5fb66f8febdbae30d95
70
+ email: gem-dev@curoverse.com
70
71
  executables: []
71
-
72
72
  extensions: []
73
-
74
73
  extra_rdoc_files: []
75
-
76
- files:
74
+ files:
77
75
  - lib/arvados.rb
78
76
  homepage: http://arvados.org
79
- licenses:
77
+ licenses:
80
78
  - Apache License, Version 2.0
79
+ metadata: {}
81
80
  post_install_message:
82
81
  rdoc_options: []
83
-
84
- require_paths:
82
+ require_paths:
85
83
  - lib
86
- required_ruby_version: !ruby/object:Gem::Requirement
87
- none: false
88
- requirements:
89
- - - ">="
90
- - !ruby/object:Gem::Version
91
- hash: 3
92
- segments:
93
- - 0
94
- version: "0"
95
- required_rubygems_version: !ruby/object:Gem::Requirement
96
- none: false
97
- requirements:
98
- - - ">="
99
- - !ruby/object:Gem::Version
100
- hash: 3
101
- segments:
102
- - 0
103
- version: "0"
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
104
94
  requirements: []
105
-
106
95
  rubyforge_project:
107
- rubygems_version: 1.8.24
96
+ rubygems_version: 2.2.1
108
97
  signing_key:
109
- specification_version: 3
98
+ specification_version: 4
110
99
  summary: Arvados SDK Ruby
111
100
  test_files: []
112
-