arvados 0.1.20150116063758 → 0.1.20150128223752

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b3e69c326ebdfbd4759f072b1143baa76bb8f215
4
- data.tar.gz: b17e6cbcd637f0cfbed773f71459344d21eaa9d1
3
+ metadata.gz: 233fa50a34cf6c9c5195cef6b0fb6a1d5744a4de
4
+ data.tar.gz: 89bec26cdbc1a2c646ffa8d666ddbf9f5b70805b
5
5
  SHA512:
6
- metadata.gz: cc23ff188453b70428cd851ce3d13e34973ed7e229f696ce9a413a1e3bdadeb1ffe84a30eeccf0c411e7b45f349d5378335c450a2b95e29864b6e9c828337359
7
- data.tar.gz: d67bcfd4e0af3a717b4648608e7d5c91041fcb701499c0058eb3fdb0198341d54cef66637f3bb14bb3c5969d5866a7a2d3c5c304e8bb5c350058607eab6c73f1
6
+ metadata.gz: 685d2babbaa167b408bf87e555d92c2b981fda8b4c1dcf2ed007d758d88649694e3d8ca483d20134f1a3bc40cbfb54f2fff66ad67974130c685d427444556ff9
7
+ data.tar.gz: f8ade0a881674e7e81e13193ca2ee95278f5fc6f5887ddb4ea4cee52bbd535f03995643f74965ee4a6ef5b14c03dba9122ed0655bb00c5392ee96e550945f258
@@ -1,10 +1,11 @@
1
1
  require 'rubygems'
2
- require 'google/api_client'
3
2
  require 'active_support/inflector'
4
3
  require 'json'
5
4
  require 'fileutils'
6
5
  require 'andand'
7
6
 
7
+ require 'arvados/google_api_client'
8
+
8
9
  ActiveSupport::Inflector.inflections do |inflect|
9
10
  inflect.irregular 'specimen', 'specimens'
10
11
  inflect.irregular 'human', 'humans'
@@ -105,34 +106,6 @@ class Arvados
105
106
  end
106
107
  end
107
108
 
108
- class Google::APIClient
109
- def discovery_document(api, version)
110
- api = api.to_s
111
- discovery_uri = self.discovery_uri(api, version)
112
- discovery_uri_hash = Digest::MD5.hexdigest(discovery_uri)
113
- return @discovery_documents[discovery_uri_hash] ||=
114
- begin
115
- # fetch new API discovery doc if stale
116
- cached_doc = File.expand_path "~/.cache/arvados/discovery-#{discovery_uri_hash}.json" rescue nil
117
- if cached_doc.nil? or not File.exist?(cached_doc) or (Time.now - File.mtime(cached_doc)) > 86400
118
- response = self.execute!(:http_method => :get,
119
- :uri => discovery_uri,
120
- :authenticated => false)
121
- begin
122
- FileUtils.makedirs(File.dirname cached_doc)
123
- File.open(cached_doc, 'w') do |f|
124
- f.puts response.body
125
- end
126
- rescue
127
- return JSON.load response.body
128
- end
129
- end
130
-
131
- File.open(cached_doc) { |f| JSON.load f }
132
- end
133
- end
134
- end
135
-
136
109
  def client
137
110
  @client ||= Google::APIClient.
138
111
  new(:host => @arvados_api_host,
@@ -0,0 +1,55 @@
1
+ require 'google/api_client'
2
+ require 'json'
3
+ require 'tempfile'
4
+
5
+ class Google::APIClient
6
+ def discovery_document(api, version)
7
+ api = api.to_s
8
+ discovery_uri = self.discovery_uri(api, version)
9
+ discovery_uri_hash = Digest::MD5.hexdigest(discovery_uri)
10
+ discovery_cache_path =
11
+ File.expand_path("~/.cache/arvados/discovery-#{discovery_uri_hash}.json")
12
+ @discovery_documents[discovery_uri_hash] ||=
13
+ disk_cached_discovery_document(discovery_cache_path) or
14
+ fetched_discovery_document(discovery_uri, discovery_cache_path)
15
+ end
16
+
17
+ private
18
+
19
+ def disk_cached_discovery_document(cache_path)
20
+ begin
21
+ if (Time.now - File.mtime(cache_path)) < 86400
22
+ open(cache_path) do |cache_file|
23
+ return JSON.load(cache_file)
24
+ end
25
+ end
26
+ rescue IOError, SystemCallError, JSON::JSONError
27
+ # Error reading the cache. Act like it doesn't exist.
28
+ end
29
+ nil
30
+ end
31
+
32
+ def write_cached_discovery_document(cache_path, body)
33
+ cache_dir = File.dirname(cache_path)
34
+ cache_file = nil
35
+ begin
36
+ FileUtils.makedirs(cache_dir)
37
+ cache_file = Tempfile.new("discovery", cache_dir)
38
+ cache_file.write(body)
39
+ cache_file.flush
40
+ File.rename(cache_file.path, cache_path)
41
+ rescue IOError, SystemCallError
42
+ # Failure to write the cache is non-fatal. Do nothing.
43
+ ensure
44
+ cache_file.close! unless cache_file.nil?
45
+ end
46
+ end
47
+
48
+ def fetched_discovery_document(uri, cache_path)
49
+ response = self.execute!(:http_method => :get,
50
+ :uri => uri,
51
+ :authenticated => false)
52
+ write_cached_discovery_document(cache_path, response.body)
53
+ JSON.load(response.body)
54
+ end
55
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arvados
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.20150116063758
4
+ version: 0.1.20150128223752
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arvados Authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-16 00:00:00.000000000 Z
11
+ date: 2015-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-api-client
@@ -104,13 +104,14 @@ dependencies:
104
104
  - - "<"
105
105
  - !ruby/object:Gem::Version
106
106
  version: 1.0.0
107
- description: Arvados client library, git commit 3fec99e70492e163763ed185aafbf022bf5e16b7
107
+ description: Arvados client library, git commit 0fb26747fa229d6b19ec911b907259a8e84acd83
108
108
  email: gem-dev@curoverse.com
109
109
  executables: []
110
110
  extensions: []
111
111
  extra_rdoc_files: []
112
112
  files:
113
113
  - lib/arvados.rb
114
+ - lib/arvados/google_api_client.rb
114
115
  - lib/arvados/keep.rb
115
116
  homepage: https://arvados.org
116
117
  licenses:
@@ -132,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
133
  version: '0'
133
134
  requirements: []
134
135
  rubyforge_project:
135
- rubygems_version: 2.2.2
136
+ rubygems_version: 2.4.3
136
137
  signing_key:
137
138
  specification_version: 4
138
139
  summary: Arvados client library