Sha256: e0c983904fef40637752128be0619be6f916936535042d1d8ffdf21206405aac

Contents?: true

Size: 1.31 KB

Versions: 21

Compression:

Stored size: 1.31 KB

Contents

require 'rubygems'
require 'rest_client'
require 'json'

module SauceREST

  # A simple class for using the Sauce Labs REST API
  class Client
    @@roots = {
      :script => 'scripts',
      :job => 'jobs',
      :result => 'results',
      :tunnel => 'tunnels'
    }

    def initialize base_url
      @base_url = base_url
      @resource = RestClient::Resource.new @base_url
    end

    def create type, *args
      doc = args[-1]
      doc_json = doc.to_json
      resp_json = @resource[@@roots[type]].post(doc_json,
                                                :content_type =>
                                                'application/octet-stream')
      resp = JSON.parse resp_json
      return resp
    end

    def get type, docid
      resp_json = @resource[@@roots[type] + '/' + docid].get
      resp = JSON.parse resp_json
      return resp
    end

    def attach docid, name, data
      resp_json = @resource[@@roots[:script] + '/' + docid + '/' + name].put data
      resp = JSON.parse resp_json
      return resp
    end

    def delete type, docid
      resp_json = @resource[@@roots[type] + '/' + docid].delete
      resp = JSON.parse resp_json
      return resp
    end

    def list type
      resp_json = @resource[@@roots[type] + '/'].get
      resp = JSON.parse resp_json
      return resp
    end
  end

end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
saucelabs-adapter-0.9.2 lib/saucerest-ruby/saucerest.rb
saucelabs-adapter-0.9.1 lib/saucerest-ruby/saucerest.rb
saucelabs-adapter-0.9.0 lib/saucerest-ruby/saucerest.rb
saucelabs-adapter-0.8.24 lib/saucerest-ruby/saucerest.rb
saucelabs-adapter-0.8.22 lib/saucerest-ruby/saucerest.rb
saucelabs-adapter-0.8.19 lib/saucerest-ruby/saucerest.rb
saucelabs-adapter-0.8.17 lib/saucerest-ruby/saucerest.rb
saucelabs-adapter-0.8.16 lib/saucerest-ruby/saucerest.rb
saucelabs-adapter-0.8.12 lib/saucerest-ruby/saucerest.rb
saucelabs-adapter-0.8.11 lib/saucerest-ruby/saucerest.rb
saucelabs-adapter-0.8.10 lib/saucerest-ruby/saucerest.rb
saucelabs-adapter-0.8.8 lib/saucerest-ruby/saucerest.rb
saucelabs-adapter-0.8.7 lib/saucerest-ruby/saucerest.rb
saucelabs-adapter-0.8.5 lib/saucerest-ruby/saucerest.rb
saucelabs-adapter-0.8.4 lib/saucerest-ruby/saucerest.rb
saucelabs-adapter-0.8.3 lib/saucerest-ruby/saucerest.rb
saucelabs-adapter-0.8.2 lib/saucerest-ruby/saucerest.rb
saucelabs-adapter-0.8.1 lib/saucerest-ruby/saucerest.rb
saucelabs-adapter-0.8.0 lib/saucerest-ruby/saucerest.rb
saucelabs-adapter-0.7.7 lib/saucerest-ruby/saucerest.rb