Sha256: b50d443dbdf5daeb196fcd8b608a2827b97134fec4221d86f0d4ab381ce80b48

Contents?: true

Size: 1.68 KB

Versions: 20

Compression:

Stored size: 1.68 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_md_5 = Digest::MD5.hexdigest File.read file_path

    files.each do |f|
      if f['md5'] == local_md5
        puts 'File already uploaded' if @debug
        return true
      end
    end

    url        = "#{@url}/#{file_name}?overwrite=plz"
    json = RestClient.post(url, file, content_type: 'application/octet-stream')
    remote_md_5 = JSON.parse(json)['md5']
    if @debug
      puts "Uploaded #{file_path}"
      puts " local_md5: #{local_md_5}"
      puts "remote_md5: #{remote_md_5}"
    end
    local_md_5 == remote_md_5
  end

  def files
    get = RestClient.get @url
    JSON.parse(get)['files']
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
appium_lib-9.4.5 ios_tests/upload/sauce_storage.rb
appium_lib-9.4.4 ios_tests/upload/sauce_storage.rb
appium_lib-9.4.3 ios_tests/upload/sauce_storage.rb
appium_lib-9.4.2 ios_tests/upload/sauce_storage.rb
appium_lib-9.4.1 ios_tests/upload/sauce_storage.rb
appium_lib-9.4.0 ios_tests/upload/sauce_storage.rb
appium_lib-9.3.8 ios_tests/upload/sauce_storage.rb
appium_lib-9.3.7 ios_tests/upload/sauce_storage.rb
appium_lib-9.3.6 ios_tests/upload/sauce_storage.rb
appium_lib-9.3.5 ios_tests/upload/sauce_storage.rb
appium_lib-9.3.4 ios_tests/upload/sauce_storage.rb
appium_lib-9.3.3 ios_tests/upload/sauce_storage.rb
appium_lib-9.3.2 ios_tests/upload/sauce_storage.rb
appium_lib-9.3.1 ios_tests/upload/sauce_storage.rb
appium_lib-9.3.0 ios_tests/upload/sauce_storage.rb
appium_lib-9.2.0 ios_tests/upload/sauce_storage.rb
appium_lib-9.1.3 ios_tests/upload/sauce_storage.rb
appium_lib-9.1.2 ios_tests/upload/sauce_storage.rb
appium_lib-9.1.1 ios_tests/upload/sauce_storage.rb
appium_lib-9.1.0 ios_tests/upload/sauce_storage.rb