Created
January 24, 2009 06:47
-
-
Save zackchandler/51372 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| class QbwcController < ApplicationController | |
| session :off | |
| def api | |
| # respond successfully to a GET which some versions of the Web Connector send to verify the url | |
| if request.get? | |
| render :nothing => true | |
| return | |
| end | |
| # Examine raw post and determine which API call to process | |
| payload = Hpricot.uxs(request.raw_post) | |
| doc = Hpricot.XML(payload) | |
| api_call = doc.containers[0].containers[0].containers[0].name | |
| # process logic | |
| case api_call | |
| when 'serverVersion' | |
| when 'clientVersion' | |
| when 'authenticate' | |
| @token, @message = QbwcSupervisor.authenticate(doc) | |
| when 'sendRequestXML' | |
| @qbxml = QbwcSupervisor.sendRequestXML(doc) | |
| when 'receiveResponseXML' | |
| @result = QbwcSupervisor.receiveResponseXML(doc) | |
| when 'getLastError' | |
| @message = 'An error occurred' | |
| when 'connectionError' | |
| @message = 'done' | |
| when 'closeConnection' | |
| @message = QbwcSupervisor.closeConnection(doc) | |
| else | |
| '' | |
| end | |
| # render appropriate template | |
| render :template => "qbwc/#{api_call}.erb", :layout => false, :content_type => 'text/xml' | |
| end | |
| end |
This file contains hidden or 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
| module QbwcSupervisor | |
| extend self | |
| def authenticate(doc) | |
| [ 'ticket', '' ] | |
| end | |
| def sendRequestXML(doc) | |
| <<-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 | |
| end | |
| def receiveResponseXML(doc) | |
| doc.search('CustomerRet').each do |node| | |
| puts "Customer: #{node.innerText.strip}" | |
| end | |
| 100 | |
| end | |
| def closeConnection(doc) | |
| 'OK' | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment