Class: Google::APIClient

Inherits:
Object
  • Object
show all
Defined in:
lib/arvados.rb

Instance Method Summary collapse

Instance Method Details

#discovery_document(api, version) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/arvados.rb', line 109

def discovery_document(api, version)
  api = api.to_s
  return @discovery_documents["#{api}:#{version}"] ||=
    begin
      # fetch new API discovery doc if stale
      cached_doc = File.expand_path '~/.cache/arvados/discovery_uri.json'
      if not File.exist?(cached_doc) or (Time.now - File.mtime(cached_doc)) > 86400
        response = self.execute!(:http_method => :get,
                                 :uri => self.discovery_uri(api, version),
                                 :authenticated => false)
        FileUtils.makedirs(File.dirname cached_doc)
        File.open(cached_doc, 'w') do |f|
          f.puts response.body
        end
      end

      File.open(cached_doc) { |f| JSON.load f }
    end
end