Class: RequestHelper

Inherits:
Object
  • Object
show all
Includes:
CookieJar
Defined in:
lib/request_helper.rb

Instance Method Summary collapse

Methods included from CookieJar

#get_cookies

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 = get_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(options)
  begin
    response = RestClient.post("http://#{@server}/diff_requests",
                               {:diff_request => 
                                  {'dryruns_attributes[0][node_group]' => options[:nodegroup1], 'dryruns_attributes[0][tag]' => options[:tag1], 
                                   'dryruns_attributes[1][node_group]' => options[:nodegroup2], 'dryruns_attributes[1][tag]' => options[: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(options)
  tag = options[:tag]
  nodegroup = options[: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(options)
  begin
    response = RestClient.get("http://#{@server}/diff_requests/#{options[:id]}",
                               {:cookies => @cookies, :content_type => 'application/json', :accept => :json})
    result = JSON.parse(response)
    if options[: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(options)
  begin
    response = RestClient.get("http://#{@server}/dryruns/#{options[:id]}",
                               {:cookies => @cookies, :content_type => 'application/json', :accept => :json})
    result = JSON.parse(response)
    if options[: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(options)
  begin
    response = RestClient.get("http://#{@server}/tags/#{options[:id]}",
                               {:cookies => @cookies, :content_type => 'application/json', :accept => :json})
    result = JSON.parse(response)
    if options[: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(options)
  revision = options[:revision]
  nodegroup = options[: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