Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 4b5c64be8bc8a228f6e04611d06d49cce3ac242d @zackchandler zackchandler committed Nov 18, 2008
@@ -0,0 +1,23 @@
+### What is it? ###
+
+Sinatra ruby server implementing QBWC callbacks in < 75 LOC
+
+### Introduction ###
+
+I've blogged extensively on QuickBooks integration in Rails on my blog [Depixelate](http://depixelate.com).
+
+The short story is that working with ActionWebService sucks.
+
+mini-qbwc is an experiment in simplicity and non-suckiness.
+
+### Setup ###
+
+1) Install sinatra
+
+ $ sudo gem install sinatra
+
+2) Start server
+
+ $ ruby qbwc.rb
+
+3) Install app.qwc in QBWC and run sync
12 app.qwc
@@ -0,0 +1,12 @@
+<QBWCXML>
+ <AppName>Test App</AppName>
+ <AppID></AppID>
+ <AppURL>http://localhost1:4567/api</AppURL>
+ <AppDescription></AppDescription>
+ <AppSupport>http://localhost1:4567/api</AppSupport>
+ <UserName>c541924d887c1faa5c8b5601101f7ff3b120e5bf</UserName>
+ <OwnerID>{34F3B9B1-88F1-4fcc-B1EE-566DE1812D20}</OwnerID>
+ <FileID>{12F3B9B3-36F1-4fcc-B1EE-566DE1813D20}</FileID>
+ <QBType>QBFS</QBType>
+ <Style>Document</Style>
+</QBWCXML>
64 qbwc.rb
@@ -0,0 +1,64 @@
+require 'rubygems'
+require 'sinatra'
+require 'hpricot'
+require 'fast_xs'
+
+class NilClass
+ def fast_xs
+ ''
+ end
+end
+
+post '/api' do
+ content_type 'text/xml'
+
+ payload = Hpricot.uxs(request.body.read)
+ doc = Hpricot.XML(payload)
+ api_call = doc.containers[0].containers[0].containers[0].name.split(':').last
+
+ # log request
+ puts ''
+ puts "========== #{api_call} =========="
+ puts payload
+
+ case api_call
+ when 'serverVersion'
+ erb :serverVersion
+ when 'clientVersion'
+ erb :clientVersion
+ when 'authenticate'
+ @token = 'abc123'
+ erb :authenticate
+ when 'sendRequestXML'
+ @qbxml = <<-XML
+<?xml version="1.0" ?>
+<?qbxml version="5.0" ?>
+<QBXML>
+ <QBXMLMsgsRq onError="continueOnError">
+ <CustomerQueryRq requestID="1">
+ <MaxReturned>10</MaxReturned>
+ <IncludeRetElement>Name</IncludeRetElement>
+ </CustomerQueryRq>
+ </QBXMLMsgsRq>
+</QBXML>
+XML
+ erb :sendRequestXML
+ when 'receiveResponseXML'
+ (doc/'CustomerRet').each do |node|
+ puts "Customer: #{node.innerText.strip}"
+ end
+ @result = 100
+ erb :receiveResponseXML
+ when 'getLastError'
+ @message = 'An error occurred'
+ erb :getLastError
+ when 'connectionError'
+ @message = 'done'
+ erb :connectionError
+ when 'closeConnection'
+ @message = 'OK'
+ erb :closeConnection
+ else
+ ''
+ end
+end
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
+ <soap:Body>
+ <authenticateResponse xmlns="http://developer.intuit.com/">
+ <authenticateResult>
+ <string><%= @token.fast_xs %></string>
+ <string><%= @message.fast_xs %></string>
+ <string><%= @seconds_until_next_update %></string>
+ <string><%= @seconds_between_runs %></string>
+ </authenticateResult>
+ </authenticateResponse>
+ </soap:Body>
+</soap:Envelope>
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
+ <soap:Body>
+ <clientVersionResponse xmlns="http://developer.intuit.com/">
+ <clientVersionResult><%= @version %></clientVersionResult>
+ </clientVersionResponse>
+ </soap:Body>
+</soap:Envelope>
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
+ <soap12:Body>
+ <closeConnectionResponse xmlns="http://developer.intuit.com/">
+ <closeConnectionResult><%= @message.fast_xs %></closeConnectionResult>
+ </closeConnectionResponse>
+ </soap12:Body>
+</soap12:Envelope>
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
+ <soap:Body>
+ <connectionErrorResponse xmlns="http://developer.intuit.com/">
+ <connectionErrorResult><%= @message.fast_xs %></connectionErrorResult>
+ </connectionErrorResponse>
+ </soap:Body>
+</soap:Envelope>
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
+ <soap:Body>
+ <getLastErrorResponse xmlns="http://developer.intuit.com/">
+ <getLastErrorResult><%= @message.fast_xs %></getLastErrorResult>
+ </getLastErrorResponse>
+ </soap:Body>
+</soap:Envelope>
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
+ <soap:Body>
+ <receiveResponseXMLResponse xmlns="http://developer.intuit.com/">
+ <receiveResponseXMLResult><%= @result %></receiveResponseXMLResult>
+ </receiveResponseXMLResponse>
+ </soap:Body>
+</soap:Envelope>
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
+ <soap:Body>
+ <sendRequestXMLResponse xmlns="http://developer.intuit.com/">
+ <sendRequestXMLResult><%= @qbxml.fast_xs %></sendRequestXMLResult>
+ </sendRequestXMLResponse>
+ </soap:Body>
+</soap:Envelope>
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
+ <soap:Body>
+ <serverVersionResponse xmlns="http://developer.intuit.com/">
+ <serverVersionResult><%= @version %></serverVersionResult>
+ </serverVersionResponse>
+ </soap:Body>
+</soap:Envelope>

0 comments on commit 4b5c64b

Please sign in to comment.