Class: JIRAClient

Inherits:
Object
  • Object
show all
Defined in:
lib/jira_fix_version_release/jira_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(username, password, jira_domain) ⇒ JIRAClient

Returns a new instance of JIRAClient.



7
8
9
10
11
# File 'lib/jira_fix_version_release/jira_client.rb', line 7

def initialize(username, password, jira_domain)
  @username = username
  @password = password
  @jira_domain = jira_domain
end

Instance Method Details

#getResponseBody(response) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/jira_fix_version_release/jira_client.rb', line 32

def getResponseBody(response)
  begin
    data = JSON.parse(response.body)
  rescue
    data = nil
  end
  return data
end

#getResponseHeaders(response) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/jira_fix_version_release/jira_client.rb', line 41

def getResponseHeaders(response)
  begin
    data = JSON.parse(response.headers)
  rescue
    data = nil
  end
  return data
end

#run(method = nil, url = nil, headers = nil, payload = nil, username = @username, password = @password) ⇒ Object

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/jira_fix_version_release/jira_client.rb', line 13

def run(method=nil, url=nil, headers=nil, payload=nil, username=@username, password=@password)
  raise ArgumentError, "Missing required parameters" if (method==nil or url==nil or username==nil or password==nil)
  raise ArgumentError, "Payload required for post/put request" if ((method=="post" or method=="put") and payload==nil)

  options = Hash.new
  options[:method] = method.to_sym
  options[:url] = @jira_domain + url
  options[:user] = username
  options[:password] = password 
  options[:headers] = headers if headers != nil 
  options[:payload] = payload if payload !=nil and method != "get"
  response = RestClient::Request.execute(options)
  if(response.code < 200 or response.code > 299)
     raise "Error with the http request!"
  end
  
  return response
end