Class: SauceREST::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/saucerest-ruby/saucerest.rb

Overview

A simple class for using the Sauce Labs REST API

Constant Summary collapse

@@roots =
{
  :script => 'scripts',
  :job => 'jobs',
  :result => 'results',
  :tunnel => 'tunnels'
}

Instance Method Summary collapse

Constructor Details

#initialize(base_url) ⇒ Client

Returns a new instance of Client.



16
17
18
19
# File 'lib/saucerest-ruby/saucerest.rb', line 16

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

Instance Method Details

#attach(docid, name, data) ⇒ Object



37
38
39
40
41
# File 'lib/saucerest-ruby/saucerest.rb', line 37

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

#create(type, *args) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/saucerest-ruby/saucerest.rb', line 21

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

#delete(type, docid) ⇒ Object



43
44
45
46
47
# File 'lib/saucerest-ruby/saucerest.rb', line 43

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

#get(type, docid) ⇒ Object



31
32
33
34
35
# File 'lib/saucerest-ruby/saucerest.rb', line 31

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

#list(type) ⇒ Object



49
50
51
52
53
# File 'lib/saucerest-ruby/saucerest.rb', line 49

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