Skip to content

Instantly share code, notes, and snippets.

@mPastuszko
Created October 24, 2012 10:44
Show Gist options
  • Save mPastuszko/3945418 to your computer and use it in GitHub Desktop.
Save mPastuszko/3945418 to your computer and use it in GitHub Desktop.
XTRF API adapter in Ruby
require 'rubygems'
require 'savon'
require 'XTRFNamespaces'
class XTRFImporter
def initialize(config)
@config = config
end
def ws
@ws ||= Savon::Client.new do |wsdl, http|
wsdl.document = @config[:xtrf][:wsdl_url]
http.auth.ssl.verify_mode = :none
end
end
def login
response = ws.request :xtr, :login do |soap, http|
soap.namespaces["xmlns:xtr"] = XTRFNamespaces::Xtr
soap.body = {
'xtr:userName' => @config[:xtrf][:user],
'xtr:password' => @config[:xtrf][:password]
}
end
@logged_in = true and response if response
end
def create_project(params)
login unless @logged_in
ws.request :xtr, :create_project do
soap.namespaces["xmlns:xtr"] = XTRFNamespaces::Xtr
soap.namespaces["xmlns:proj"] = XTRFNamespaces::Proj
soap.namespaces["xmlns:com"] = XTRFNamespaces::Com
soap.body = { 'xtr:project' => params }
end
end
def get_customer(name)
login unless @logged_in
ws.request :xtr, :get_customer_by_name do
soap.namespaces["xmlns:xtr"] = XTRFNamespaces::Xtr
soap.body = { 'xtr:name' => name }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment