Welcome to the "trac"-ing site of soap4r!
[soap4r] [httpclient] [openpgp4u] [pkcs1] [logger] [csv] [vtr]

root/branches/1_5/sample/basic/yahooNewsSearch.rb

Revision 1885, 0.9 kB (checked in by nahi, 1 year ago)
  • use httpclient instead of http-access2. (works with http-access/2.0.9 as same as with httpclient/2.1.0)
Line 
1 query = ARGV.shift or raise ArgumentError
2
3 require 'soap/marshal'
4 class MyXMLHandler < SOAP::EncodingStyle::SOAPHandler
5   Namespace = 'urn:myxmlhandler'
6   add_handler
7   def decode_parent(parent, node)
8     super if parent.node
9   end
10 end
11
12 require 'httpclient'
13 appid = 'soap4r-dev'
14 url = 'http://api.search.yahoo.com/NewsSearchService/V1/newsSearch'
15 type = 'all'    # any, phrase
16 results = 3
17 language = 'en'
18 results_sort = 'rank'     # date
19
20 param = {
21   'appid' => appid,
22   'query' => query,
23   'results' => results,
24   'language' => language,
25   'results_sort' => results_sort
26 }
27 proxy = ENV['http_proxy'] || ENV['HTTP_PROXY']
28 result = HTTPClient.new(proxy).get_content(url, param)
29
30 opt = {:default_encodingstyle => 'urn:myxmlhandler'}
31 soap = SOAP::Processor.unmarshal(result, opt)
32
33 SOAP::Mapping.soap2obj(soap).result.each do |result|
34   puts "== " + result.title + " =="
35   puts result.summary
36 end
Note: See TracBrowser for help on using the browser.