Module: QBWC::Controller
- Defined in:
- lib/qbwc/controller.rb
Defined Under Namespace
Classes: StringArray
Constant Summary collapse
- AUTHENTICATE_NOT_VALID_USER =
'nvu'
- AUTHENTICATE_NO_WORK =
'none'
Class Method Summary collapse
Instance Method Summary collapse
- #app_name ⇒ Object
- #authenticate ⇒ Object
- #client_version ⇒ Object
- #close_connection ⇒ Object
- #connection_error ⇒ Object
- #file_id ⇒ Object
- #get_last_error ⇒ Object
- #qwc ⇒ Object
- #receive_response ⇒ Object
- #send_request ⇒ Object
- #server_version ⇒ Object
Class Method Details
.included(base) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/qbwc/controller.rb', line 10 def self.included(base) base.class_eval do soap_service skip_before_action :_authenticate_wsse, :_map_soap_parameters, :only => :qwc before_action :get_session, :except => [:qwc, :authenticate, :_generate_wsdl] after_action :save_session, :except => [:qwc, :authenticate, :_generate_wsdl, :close_connection, :connection_error] # wash_out changed the format of app/views/wash_with_soap/rpc/response.builder in commit # https://github.com/inossidabile/wash_out/commit/24a77f4a3d874562732c6e8c3a30e8defafea7cb wash_out_xml_namespace = (Gem::Version.new(WashOut::VERSION) < Gem::Version.new('0.9.1') ? 'tns:' : '') soap_action 'serverVersion', :to => :server_version, :return => {'tns:serverVersionResult' => :string}, :response_tag => "#{wash_out_xml_namespace}serverVersionResponse" soap_action 'clientVersion', :to => :client_version, :args => {:strVersion => :string}, :return => {'tns:clientVersionResult' => :string}, :response_tag => "#{wash_out_xml_namespace}clientVersionResponse" soap_action 'authenticate', :args => {:strUserName => :string, :strPassword => :string}, :return => {'tns:authenticateResult' => StringArray}, :response_tag => "#{wash_out_xml_namespace}authenticateResponse" soap_action 'sendRequestXML', :to => :send_request, :args => {:ticket => :string, :strHCPResponse => :string, :strCompanyFilename => :string, :qbXMLCountry => :string, :qbXMLMajorVers => :string, :qbXMLMinorVers => :string}, :return => {'tns:sendRequestXMLResult' => :string}, :response_tag => "#{wash_out_xml_namespace}sendRequestXMLResponse" soap_action 'receiveResponseXML', :to => :receive_response, :args => {:ticket => :string, :response => :string, :hresult => :string, :message => :string}, :return => {'tns:receiveResponseXMLResult' => :integer}, :response_tag => "#{wash_out_xml_namespace}receiveResponseXMLResponse" soap_action 'closeConnection', :to => :close_connection, :args => {:ticket => :string}, :return => {'tns:closeConnectionResult' => :string}, :response_tag => "#{wash_out_xml_namespace}closeConnectionResponse" soap_action 'connectionError', :to => :connection_error, :args => {:ticket => :string, :hresult => :string, :message => :string}, :return => {'tns:connectionErrorResult' => :string}, :response_tag => "#{wash_out_xml_namespace}connectionErrorResponse" soap_action 'getLastError', :to => :get_last_error, :args => {:ticket => :string}, :return => {'tns:getLastErrorResult' => :string}, :response_tag => "#{wash_out_xml_namespace}getLastErrorResponse" end end |
Instance Method Details
#app_name ⇒ Object
164 165 166 |
# File 'lib/qbwc/controller.rb', line 164 def app_name "#{Rails.application.class.parent_name} #{Rails.env}" end |
#authenticate ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/qbwc/controller.rb', line 103 def authenticate username = params[:strUserName] password = params[:strPassword] if !QBWC.authenticator.nil? company_file_path = QBWC.authenticator.call(username, password) elsif username == QBWC.username && password == QBWC.password company_file_path = QBWC.company_file_path else company_file_path = nil end ticket = nil if company_file_path.nil? QBWC.logger.info "Authentication of user '#{username}' failed." company_file_path = AUTHENTICATE_NOT_VALID_USER else ticket = QBWC.storage_module::Session.new(username, company_file_path).ticket session = get_session(ticket) if !QBWC.pending_jobs(company_file_path, session).present? QBWC.logger.info "Authentication of user '#{username}' succeeded, but no jobs pending for '#{company_file_path}'." company_file_path = AUTHENTICATE_NO_WORK else QBWC.logger.info "Authentication of user '#{username}' succeeded, jobs are pending for '#{company_file_path}'." QBWC.session_initializer.call(session) unless QBWC.session_initializer.nil? end end render :soap => {"tns:authenticateResult" => {"tns:string" => [ticket || '', company_file_path]}} end |
#client_version ⇒ Object
99 100 101 |
# File 'lib/qbwc/controller.rb', line 99 def client_version render :soap => {"tns:clientVersionResult" => check_client_version} end |
#close_connection ⇒ Object
149 150 151 152 |
# File 'lib/qbwc/controller.rb', line 149 def close_connection @session.destroy render :soap => {'tns:closeConnectionResult' => 'OK'} end |
#connection_error ⇒ Object
154 155 156 157 158 |
# File 'lib/qbwc/controller.rb', line 154 def connection_error @session.destroy logger.warn "#{params[:hresult]}: #{params[:message]}" render :soap => {'tns:connectionErrorResult' => 'done'} end |
#file_id ⇒ Object
168 169 170 |
# File 'lib/qbwc/controller.rb', line 168 def file_id '90A44FB5-33D9-4815-AC85-BC87A7E7D1EB' end |
#get_last_error ⇒ Object
160 161 162 |
# File 'lib/qbwc/controller.rb', line 160 def get_last_error render :soap => {'tns:getLastErrorResult' => @session.error || ''} end |
#qwc ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/qbwc/controller.rb', line 62 def qwc # Optional tag scheduler_block = '' if !QBWC.minutes_to_run.nil? scheduler_block = <<SB <Scheduler> <RunEveryNMinutes>#{QBWC.minutes_to_run}</RunEveryNMinutes> </Scheduler> SB end qwc = <<QWC <QBWCXML> <AppName>#{app_name}</AppName> <AppID></AppID> <AppURL>#{qbwc_action_url(:only_path => false)}</AppURL> <AppDescription>Quickbooks integration</AppDescription> <AppSupport>#{QBWC.support_site_url || root_url(:protocol => 'https://')}</AppSupport> <UserName>#{QBWC.username}</UserName> <OwnerID>#{QBWC.owner_id}</OwnerID> <FileID>{#{file_id}}</FileID> <QBType>QBFS</QBType> <Style>Document</Style> #{scheduler_block} </QBWCXML> QWC send_data qwc, :filename => "#{Rails.application.class.parent_name}.qwc", :content_type => 'application/x-qwc' end |
#receive_response ⇒ Object
138 139 140 141 142 143 144 145 146 147 |
# File 'lib/qbwc/controller.rb', line 138 def receive_response if params[:hresult] QBWC.logger.warn "#{params[:hresult]}: #{params[:message]}" @session.error = params[:message] @session.status_code = params[:hresult] @session.status_severity = 'Error' end @session.response = params[:response] render :soap => {'tns:receiveResponseXMLResult' => (QBWC::on_error == 'continueOnError' || @session.error.nil?) ? @session.progress : -1} end |
#send_request ⇒ Object
133 134 135 136 |
# File 'lib/qbwc/controller.rb', line 133 def send_request request = @session.request_to_send render :soap => {'tns:sendRequestXMLResult' => request} end |
#server_version ⇒ Object
95 96 97 |
# File 'lib/qbwc/controller.rb', line 95 def server_version render :soap => {"tns:serverVersionResult" => server_version_response} end |