Class: Wisebed::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/wisebedclientruby.rb,
lib/wisebedclientruby/client.rb

Direct Known Subclasses

Testbed, WebsocketClient

Instance Method Summary collapse

Instance Method Details

#delete_from_wisebed(url_extension, data) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/wisebedclientruby/client.rb', line 57

def delete_from_wisebed(url_extension, data)
  url_extension = "/#{url_extension}" unless url_extension[0] == "/"
  #puts "debug: deleting "+self.class.base_uri+url_extension
  if @cookie
    headers = {'Cookie' => @cookie}
  else
    headers = {}
  end
  headers.merge!({'Content-Type' => "application/json; charset=utf-8"})
  res = self.class.delete(url_extension, :body => data.to_json, :headers => headers)
  begin        
    JSON.parse(res.body)
  rescue JSON::ParserError => e
    res.body
  end
end

#experimentconfiguration(url) ⇒ Object



16
17
18
# File 'lib/wisebedclientruby/client.rb', line 16

def experimentconfiguration(url)
  request_from_wisebed("experimentconfiguration?url=#{url}")
end

#post_to_wisebed(url_extension, data) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/wisebedclientruby/client.rb', line 38

def post_to_wisebed(url_extension, data)
  url_extension = "/#{url_extension}" unless url_extension[0] == "/"
  #puts "debug: posting "+self.class.base_uri+url_extension
  #puts "debug: with data: #{data.to_json}"
  if @cookie
    headers = {'Cookie' => @cookie}
  else
    headers = {}
  end
  headers.merge!({'Content-Type' => "application/json; charset=utf-8"})
  res = self.class.post(url_extension, :body => data.to_json, :headers => headers)
  @cookie = res.headers['Set-Cookie'] if res.headers['Set-Cookie']
  begin        
    JSON.parse(res.body)
  rescue JSON::ParserError => e
    res.body
  end
end

#request_from_wisebed(url_extension) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/wisebedclientruby/client.rb', line 20

def request_from_wisebed(url_extension)
  url_extension = "/#{url_extension}" unless url_extension[0] == "/"
  #puts "debug: requesting "+self.class.base_uri+url_extension
  if @cookie
    headers = {'Cookie' => @cookie}
  else
    headers = {}
  end      
  res = self.class.get(url_extension, :headers => headers)
  begin        
    JSON.parse(res.body)
  rescue JSON::ParserError => e
    res.body
  end

end

#testbedsObject



12
13
14
# File 'lib/wisebedclientruby/client.rb', line 12

def testbeds
  request_from_wisebed("testbeds")["testbedMap"]
end