Sha256: 52d9c2a35ecbecdbaffd3c0e7e42fcb7cba23a5f7d9099a9fdcb14c1b52b8a3c
Contents?: true
Size: 1.64 KB
Versions: 1
Compression:
Stored size: 1.64 KB
Contents
=begin See docs @ http://saucelabs.com/docs/rest#storage s = SauceStorage.new username: 'my_user_name', key: '00', debug: true # or if you have SAUCE_USERNAME and SAUCE_ACCESS_KEY in env already s = SauceStorage.new debug: true # list all files s.files # upload a file s.upload '/tmp/sauce/test.zip' > s.files => [{"size"=>8, "mtime"=>1367700857.1011374, "name"=>"test.zip", "md5"=>"d8064dccc0b399d37c73ffa9661a79b6"}] > s.upload '/tmp/sauce/test.zip' Uploaded /tmp/sauce/test.zip local_md5: 764efa883dda1e11db47671c4a3bbd9e remote_md5: 764efa883dda1e11db47671c4a3bbd9e =end require 'rubygems' require 'restclient' require 'json' class SauceStorage attr_reader :username, :key, :url, :debug def initialize opts @username = opts.fetch :username, ENV['SAUCE_USERNAME'] @key = opts.fetch :key, ENV['SAUCE_ACCESS_KEY'] @url = "https://#{@username}:#{@key}@saucelabs.com/rest/v1/storage/#{@username}" @debug = opts.fetch :debug, false end def upload file_path file_name = File.basename file_path file = File.new file_path local_md5 = Digest::MD5.hexdigest File.read file_path self.files.each do |file| if file['md5'] == local_md5 puts 'File already uploaded' if @debug return true end end url = "#{@url}/#{file_name}?overwrite=plz" remote_md5 = JSON.parse( RestClient.post url, file, content_type: 'application/octet-stream' )['md5'] if @debug puts "Uploaded #{file_path}" puts " local_md5: #{local_md5}" puts "remote_md5: #{remote_md5}" end local_md5 == remote_md5 end def files JSON.parse( RestClient.get @url )['files'] end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
appium_lib-1.0.0 | ios_tests/upload/sauce_storage.rb |