Module: ALM
- Defined in:
- lib/alm-rest-api.rb
Overview
alm-rest-api.rb
Defined Under Namespace
Classes: Constants, Response, RestConnector
Class Method Summary collapse
-
.attachWithMultipart(defectId, filePath) ⇒ Object
attach a file.
-
.createDefect(defect) ⇒ Object
create new defect.
-
.deleteDefect(defectId) ⇒ Object
delete a defect.
-
.getDefectFields(required = false) ⇒ Object
read all defects fields.
-
.getValueLists(defectFields = nil) ⇒ Object
read pre-defined defects fields values.
- .isAuthenticated ⇒ Object
-
.isLoggedIn(username, password) ⇒ Object
convenience method to do user login.
-
.login(loginUrl, username, password) ⇒ Object
Logging in to our system is standard http login (basic authentication), where one must store the returned cookies for further use.
- .logout ⇒ Object
Class Method Details
.attachWithMultipart(defectId, filePath) ⇒ Object
attach a file
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/alm-rest-api.rb', line 130 def self.attachWithMultipart(defectId, filePath) = RestConnector.instance.buildEntityCollectionUrl("attachment") boundary = "AaB03x" requestHeaders = Hash.new requestHeaders["Content-Type"] = "multipart/form-data, boundary=#{boundary}" #post_body = [] #post_body < < "--#{boundary}rn" #post_body < < "Content-Disposition: form-data; name="datafile"; filename="#{File.basename(file)}"rn" #post_body < < "Content-Type: text/plainrn" #post_body < < "rn" #post_body < < File.read(file) #post_body < < "rn--#{boundary}--rn" #Response response = RestConnector.instance.httpPost(attachmentUrl, post_body, requestHeaders) end |
.createDefect(defect) ⇒ Object
create new defect
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/alm-rest-api.rb', line 101 def self.createDefect(defect) defectsUrl = RestConnector.instance.buildEntityCollectionUrl("defect") requestHeaders = Hash.new requestHeaders["Content-Type"] = "application/xml" requestHeaders["Accept"] = "application/xml" response = RestConnector.instance.httpPost(defectsUrl, defect.to_xml, requestHeaders) defectId = nil if response.statusCode == '201' defectUrl = response.responseHeaders["Location"] defectId = defectUrl.split('/').last end return defectId end |
.deleteDefect(defectId) ⇒ Object
delete a defect
119 120 121 122 123 124 125 126 127 |
# File 'lib/alm-rest-api.rb', line 119 def self.deleteDefect(defectId) defectUrl = RestConnector.instance.buildDefectUrl(defectId) requestHeaders = Hash.new requestHeaders["Accept"] = "application/xml" response = RestConnector.instance.httpDelete(defectUrl, requestHeaders) return response.statusCode == '200' end |
.getDefectFields(required = false) ⇒ Object
read all defects fields
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/alm-rest-api.rb', line 53 def self.getDefectFields(required = false) defectFieldsUrl = RestConnector.instance.buildEntityCollectionUrl("customization/entities/defect/field") queryString = nil if required queryString = "required=true" end requestHeaders = Hash.new requestHeaders["Accept"] = "application/xml" response = RestConnector.instance.httpGet(defectFieldsUrl, queryString, requestHeaders) defectFields = nil if response.statusCode == '200' defectFields = DefectFields::Fields.parse(response.toString()) end return defectFields end |
.getValueLists(defectFields = nil) ⇒ Object
read pre-defined defects fields values
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/alm-rest-api.rb', line 72 def self.getValueLists(defectFields = nil) # ALM 11.0 the url is "customization/list" valueListsUrl = RestConnector.instance.buildEntityCollectionUrl("customization/list") queryString = nil if defectFields defectFields.fields.each do |field| if field.list_id if queryString == nil queryString = "id=" + field.list_id.to_s else queryString = queryString + "," + field.list_id.to_s end end end end requestHeaders = Hash.new requestHeaders["Accept"] = "application/xml" response = RestConnector.instance.httpGet(valueListsUrl, queryString, requestHeaders) valueLists = nil if response.statusCode == '200' valueLists = ValueLists::Lists.parse(response.toString()) end return valueLists end |
.isAuthenticated ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/alm-rest-api.rb', line 22 def self.isAuthenticated() isAuthenticateUrl = RestConnector.instance.buildUrl("qcbin/rest/is-authenticated") response = RestConnector.instance.httpGet(isAuthenticateUrl, nil, nil) responseCode = response.statusCode # if already authenticated # if not authenticated - get the address where to authenticate # via WWW-Authenticate if responseCode == "200" ret = nil elsif responseCode == "401" authenticationHeader = response.responseHeaders["WWW-Authenticate"] newUrl = authenticationHeader.split("=").at(1) newUrl = newUrl.delete("\"") newUrl = newUrl + "/authenticate" ret = newUrl end return ret end |
.isLoggedIn(username, password) ⇒ Object
convenience method to do user login
44 45 46 47 48 49 50 |
# File 'lib/alm-rest-api.rb', line 44 def self.isLoggedIn(username, password) authenticationPoint = isAuthenticated(); if (authenticationPoint != nil) return login(authenticationPoint, username, password) end return true end |
.login(loginUrl, username, password) ⇒ Object
Logging in to our system is standard http login (basic authentication), where one must store the returned cookies for further use.
7 8 9 10 11 |
# File 'lib/alm-rest-api.rb', line 7 def self.login(loginUrl, username, password) response = RestConnector.instance.httpBasicAuth(loginUrl, username, password) return response.statusCode == '200' end |
.logout ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/alm-rest-api.rb', line 13 def self.logout() # note the get operation logs us out by setting authentication cookies to: # LWSSO_COOKIE_KEY="" via server response header Set-Cookie logoutUrl = RestConnector.instance.buildUrl("qcbin/authentication-point/logout") response = RestConnector.instance.httpGet(logoutUrl, nil, nil) return response.statusCode == '200' end |