Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Web Services
1.
2. Define the SOAP methods you want to call
3. Call the SOAP methods
4.
5. Here's a controller that uses SOAP to find the first three results from a Google search. Update the code_controller.rb file from the previous example to contain this new googletest method: class CodeController < ApplicationController def googletest yourkey = 'YOUR GOOGLE DEVELOPER KEY' # Your Google dev key @yourquery = 'SEARCH TEXT' # Search value XSD::Charset.encoding = 'UTF8' # Set encoding for response googleurl = "http://api.google.com/search/beta2" urn = "urn:GoogleSearch" driver = SOAP::RPC::Driver.new(googleurl, urn) # Create our driver driver.add_method('doGoogleSearch', 'key', 'q', # Set up methods we'll call 'start', 'maxResults', 'filter', 'restrict', 'safeSearch', 'lr', 'ie', 'oe') @result = driver.doGoogleSearch(yourkey, # make our SOAP request @yourquery, 0, 3, false, '', false, '', '', '') end end
6. Here's the code for the view. Save it as googletest.rhtml in your app/views/code/ directory: Query for: <%= @yourquery %><br> Found: <%= @result.estimatedTotalResultsCount %><br> Query took about <%= @result.searchTime %> seconds<br> <% @result.resultElements.each do |rec| %> <b>Title:</b> <%= rec["title"] %><br> <b>Summary:</b> <%= rec.snippet %><br> <b>Link:</b> <a href="<%= rec["URL"] %>"><%= rec["URL"] %></a> <br><br> <% end %>