Last active
August 13, 2019 16:33
-
-
Save pupca/23b5a75eff0a818f8a40cfb622a8ad38 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'savon' | |
class PolarionService | |
def initialize | |
@tracker_url = 'https://example.com/polarion/ws/services/TrackerWebService?wsdl' | |
@session_url = 'https://example.com/polarion/ws/services/SessionWebService?wsdl' | |
end | |
def tracker_client | |
Savon.client(open_timeout: 5000, read_timeout: 5000, :ssl_verify_mode => :none, wsdl: @tracker_url, soap_header: { "ns1:sessionID" => get_session_id, :attributes! => { "ns1:sessionID" => {"env:actor" => "http://schemas.xmlsoap.org/soap/actor/next", "env:mustUnderstand" => "0", "xmlns:ns1" => "http://ws.polarion.com/session"}}}) | |
end | |
def get_session_id | |
session_client = Savon.client(wsdl: @session_url, :ssl_verify_mode => :none) | |
response = session_client.call(:log_in, message: {user_name: ENV["POLARION_LOGIN"], password: ENV["POLARION_PASSWORD"]}) | |
session_id = response.header[:session_id] | |
end | |
def query_workitems(query) | |
workitems = tracker_client.call(:query_work_items, message: {query: query, sort: "id", fields: ["id", "severity", "title"]}) | |
result = workitems.body[:query_work_items_response][:query_work_items_return] | |
result = [result] if result.class == Hash | |
result = [] if result.class == NilClass | |
puts "Quering '#{query}'' with result #{result.to_a.count}" | |
return result | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment