Class: RequestHelper
- Inherits:
-
Object
- Object
- RequestHelper
- Includes:
- CookieJar
- Defined in:
- lib/request_helper.rb
Instance Method Summary collapse
- #diffrun(options) ⇒ Object
- #dryrun(options) ⇒ Object
-
#initialize(conf) ⇒ RequestHelper
constructor
A new instance of RequestHelper.
- #show_diffrun(options) ⇒ Object
- #show_dryrun(options) ⇒ Object
- #show_tag(options) ⇒ Object
- #tag(options) ⇒ Object
Methods included from CookieJar
Constructor Details
#initialize(conf) ⇒ RequestHelper
Returns a new instance of RequestHelper.
9 10 11 12 13 14 |
# File 'lib/request_helper.rb', line 9 def initialize(conf) @server = conf[:server] || "localhost" @username = conf[:username] @password = conf[:password] @cookies = end |
Instance Method Details
#diffrun(options) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/request_helper.rb', line 31 def diffrun() begin response = RestClient.post("http://#{@server}/diff_requests", {:diff_request => {'dryruns_attributes[0][node_group]' => [:nodegroup1], 'dryruns_attributes[0][tag]' => [:tag1], 'dryruns_attributes[1][node_group]' => [:nodegroup2], 'dryruns_attributes[1][tag]' => [:tag2]} }, {:cookies => @cookies, :content_type => 'application/json', :accept => :json}) result = JSON.parse(response) puts "http://#{@server}/diff_requests/#{result['diff_request']['id']}" rescue => e puts e.inspect end end |
#dryrun(options) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/request_helper.rb', line 47 def dryrun() tag = [:tag] nodegroup = [:nodegroup] begin response = RestClient.post("http://#{@server}/dryruns", {:dryrun => {'node_group' => nodegroup, :tag => tag}}, {:cookies => @cookies, :content_type => 'application/json', :accept => :json}) result = JSON.parse(response) puts "http://#{@server}/dryruns/#{result['dryrun']['id']}" rescue => e puts e.inspect end end |
#show_diffrun(options) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/request_helper.rb', line 76 def show_diffrun() begin response = RestClient.get("http://#{@server}/diff_requests/#{[:id]}", {:cookies => @cookies, :content_type => 'application/json', :accept => :json}) result = JSON.parse(response) if [:json] puts JSON.pretty_generate(result) else display_diff(result) end rescue => e puts e.inspect end end |
#show_dryrun(options) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/request_helper.rb', line 61 def show_dryrun() begin response = RestClient.get("http://#{@server}/dryruns/#{[:id]}", {:cookies => @cookies, :content_type => 'application/json', :accept => :json}) result = JSON.parse(response) if [:json] puts JSON.pretty_generate(result) else display_dryrun(result) end rescue => e puts e.inspect end end |
#show_tag(options) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/request_helper.rb', line 91 def show_tag() begin response = RestClient.get("http://#{@server}/tags/#{[:id]}", {:cookies => @cookies, :content_type => 'application/json', :accept => :json}) result = JSON.parse(response) if [:json] puts JSON.pretty_generate(result) else display_tag(result) end rescue => e puts e.inspect end end |
#tag(options) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/request_helper.rb', line 16 def tag() revision = [:revision] nodegroup = [:nodegroup] begin response = RestClient.post("http://#{@server}/tags", {:tag => {:revision => revision, :nodegroup => nodegroup}}, {:cookies => @cookies, :content_type => 'application/json', :accept => :json}) result = JSON.parse(response) puts "Tag id: #{result['tag']['id']}" puts "URL: http://#{@server}/tags/#{result['tag']['id']}" rescue => e puts e.inspect end end |