<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: webservice code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 25 Jul 2008 05:03:12 GMT</pubDate>
    <description>DZone Snippets: webservice code</description>
    <item>
      <title>Using Google's API to Access Picasa Albums</title>
      <link>http://snippets.dzone.com/posts/show/5672</link>
      <description>Google provides its API in multiple languages. Here is an example that shows how to access a picasa album.&lt;br /&gt;&lt;br /&gt;Before you start, you need to download Google's API for .NET. Then copy the files to you project (in the project explorer) in Visual Studio and in the references in the project explorer. Now you can make use of the namespaces:&lt;br /&gt;&lt;br /&gt;using Google.GData.Client;&lt;br /&gt;using Google.GData.Photos;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;namespace GetPicasaFeed&lt;br /&gt;{&lt;br /&gt;    public partial class Form1 : Form&lt;br /&gt;    {&lt;br /&gt;        public Form1()&lt;br /&gt;        {&lt;br /&gt;            InitializeComponent();&lt;br /&gt;            this.getAtomFeed();&lt;br /&gt;            return;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        private void getAtomFeed()&lt;br /&gt;        {&lt;br /&gt;&lt;br /&gt;            // Album query and picasa query are specialized atomfeed classes&lt;br /&gt;            AlbumQuery aQuery = new AlbumQuery(PicasaQuery.CreatePicasaUri("saschatayefeh"));&lt;br /&gt;            PicasaService pService = new PicasaService("PicasaDemo");&lt;br /&gt;            AtomFeed kResultFeed = pService.Query(aQuery);&lt;br /&gt;&lt;br /&gt;            foreach (AtomEntry entry in kResultFeed.Entries)&lt;br /&gt;            {&lt;br /&gt;                this.textBox1.AppendText(entry.Title.Text + "\r\n");&lt;br /&gt;                foreach (AtomLink eLink in entry.Links)&lt;br /&gt;                {&lt;br /&gt;                    this.textBox1.AppendText("  " + eLink.HRef.ToString() + "\r\n"); ;&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;            return;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 19 Jun 2008 08:36:37 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5672</guid>
      <author>stayefeh (Sascha Tayefeh)</author>
    </item>
    <item>
      <title>Accessing a web service </title>
      <link>http://snippets.dzone.com/posts/show/5671</link>
      <description>1. In Visual Studio, add a web reference in the project explorer.&lt;br /&gt;&lt;br /&gt;2. Create an class describing an object that represents the web service.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;    public class CurrentWeather&lt;br /&gt;    {&lt;br /&gt;&lt;br /&gt;        #region attributes&lt;br /&gt;&lt;br /&gt;        private String location;&lt;br /&gt;        private String time;&lt;br /&gt;        private String wind;&lt;br /&gt;        private String visibility;&lt;br /&gt;        private String temperature;&lt;br /&gt;        private String dewPoint;&lt;br /&gt;        private String relativeHumidity;&lt;br /&gt;        private String pressure;&lt;br /&gt;        private String status;&lt;br /&gt;&lt;br /&gt;        #endregion&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;        #region properties&lt;br /&gt;&lt;br /&gt;        public String Location { get { return this.location; } set { this.location = value; } }&lt;br /&gt;        public String Time { get { return this.time; } set { this.time = value; } }&lt;br /&gt;        public String Wind { get { return this.wind; } set { this.wind = value; } }&lt;br /&gt;        public String Visibility { get { return this.visibility; } set { this.visibility = value; } }&lt;br /&gt;        public String Temperature { get { return this.temperature; } set { this.temperature = value; } }&lt;br /&gt;        public String DewPoint { get { return this.dewPoint; } set { this.dewPoint = value; } }&lt;br /&gt;        public String RelativeHumidity { get { return this.relativeHumidity; } set { this.relativeHumidity = value; } }&lt;br /&gt;        public String Pressure { get { return this.pressure; } set { this.pressure = value; } }&lt;br /&gt;        public String Status { get { return this.status; } set { this.status = value; } }&lt;br /&gt;&lt;br /&gt;        #endregion&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Use a method like this to call the service&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;        private void btRead_Click(object sender, EventArgs e)&lt;br /&gt;        {&lt;br /&gt;            net.webservice.www.MyWeather gw = new net.webservice.www.MyWeather ();&lt;br /&gt;            this.lblShowStatus.Text = "Accessing Service";&lt;br /&gt;            this.Refresh();&lt;br /&gt; &lt;br /&gt;            Objects.CurrentWeather cwo = new Objects.CurrentWeather();&lt;br /&gt;            System.Xml.Serialization.XmlSerializer xs =&lt;br /&gt;                new System.Xml.Serialization.XmlSerializer(typeof(Objects.CurrentWeather));&lt;br /&gt;&lt;br /&gt;            // Deserialize&lt;br /&gt;            try&lt;br /&gt;            {&lt;br /&gt;                System.IO.TextReader tr = new System.IO.StringReader(gw.GetWeather(this.tbCity.Text, this.tbCountry.Text));&lt;br /&gt;                cwo = (Objects.CurrentWeather)xs.Deserialize(tr);&lt;br /&gt;                this.lblShowStatus.Text = cwo.Status;&lt;br /&gt;                this.lbShowHumidity.Text = cwo.RelativeHumidity;&lt;br /&gt;                this.lbShowPressure.Text = cwo.Pressure;&lt;br /&gt;                this.lbShowWind.Text = cwo.Wind;&lt;br /&gt;                this.lbShowTemperature.Text = cwo.Temperature;&lt;br /&gt;            }&lt;br /&gt;            catch&lt;br /&gt;            {&lt;br /&gt;                this.lblShowStatus.Text = String.Empty;&lt;br /&gt;                this.lbShowHumidity.Text = String.Empty;&lt;br /&gt;                this.lbShowPressure.Text = String.Empty;&lt;br /&gt;                this.lbShowWind.Text = String.Empty;&lt;br /&gt;                this.lbShowTemperature.Text = String.Empty;&lt;br /&gt;                this.lblShowStatus.Text = "Error";&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 19 Jun 2008 08:23:03 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5671</guid>
      <author>stayefeh (Sascha Tayefeh)</author>
    </item>
    <item>
      <title>Get a bible passage from the Living Stones / Seek-First Web Service with Ruby</title>
      <link>http://snippets.dzone.com/posts/show/2185</link>
      <description>&lt;code&gt;&lt;br /&gt;require 'net/http'&lt;br /&gt;&lt;br /&gt;LS_BASE_URL = 'http://www.seek-first.com/Bible.php?q=&amp;passage=Seek'&lt;br /&gt;&lt;br /&gt;def lookup_ls(reference, translation) # living stones (KJV, ASV, YLT, AKJV, WEB)&lt;br /&gt;  return if reference.nil? or reference.empty?&lt;br /&gt;  url = LS_BASE_URL + '&amp;p=' + URI.escape(reference) + '&amp;version=' + translation&lt;br /&gt;  result = Net::HTTP.get(URI.parse(url))&lt;br /&gt;  url = /&lt;!\-\-\s*(http:\/\/api\.seek\-first\.com.+?)\s*\-\-&gt;/.match(result)[1]&lt;br /&gt;  result = Net::HTTP.get(URI.parse(url)).gsub(/\s+/, ' ').gsub(/&#226;&#8364;&#339;|&#226;&#8364;?/, '"').gsub(/&#226;&#8364;&#732;|&#226;&#8364;&#8482;/, "'").gsub('*', '')&lt;br /&gt;  text = result.scan(/&lt;Text&gt;(.+?)&lt;\/Text&gt;/).map { |p| p[0].strip.gsub(/&lt;.+?&gt;/, '') }.join(' ') rescue nil&lt;br /&gt;  return {:reference =&gt; reference, :text =&gt; text}&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 14 Jun 2006 20:53:11 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2185</guid>
      <author>timmorgan (Tim Morgan)</author>
    </item>
    <item>
      <title>Get a Bible passage from the ESV Web Service with Ruby</title>
      <link>http://snippets.dzone.com/posts/show/2068</link>
      <description>&lt;code&gt;&lt;br /&gt;require 'net/http'&lt;br /&gt;&lt;br /&gt;BASE_URL = 'http://www.gnpcb.org/esv/share/get/'&lt;br /&gt;OPTIONS = {&lt;br /&gt;  'key' =&gt; 'IP',&lt;br /&gt;  'action' =&gt; 'doPassageQuery',&lt;br /&gt;  'include-verse-numbers' =&gt; '0',&lt;br /&gt;  'include-short-copyright' =&gt; '0',&lt;br /&gt;  'output-format' =&gt; 'plain-text',&lt;br /&gt;  'include-passage-horizontal-lines' =&gt; '0',&lt;br /&gt;  'include-heading-horizontal-lines' =&gt; '0',&lt;br /&gt;  'include-passage-references' =&gt; '1',&lt;br /&gt;  'include-first-verse-numbers' =&gt; '0',&lt;br /&gt;  'include-footnotes' =&gt; '0',&lt;br /&gt;  'include-footnote-links' =&gt; '0',&lt;br /&gt;  'include-headings' =&gt; '0',&lt;br /&gt;  'include-subheadings' =&gt; '0',&lt;br /&gt;  'line-length' =&gt; '0',&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;def combine_refs(refs)&lt;br /&gt;  combined = refs.first&lt;br /&gt;  refs[1..-1].each do |ref|&lt;br /&gt;    if combined.index(ref.gsub(/\:.*$/, '')) == 0&lt;br /&gt;      combined += ',' + /\:(.*)$/.match(ref)[1]&lt;br /&gt;    elsif combined.index(ref.gsub(/\d+\:.*$/, '')) == 0&lt;br /&gt;      combined += ';' + /\d+\:.*$/.match(ref)[0]&lt;br /&gt;    else&lt;br /&gt;      return nil # couldn't do it - fail *not* gracefully&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;  combined&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;def lookup_esv(reference)&lt;br /&gt;  return if reference.nil? or reference.empty?&lt;br /&gt;  url = BASE_URL + '?' + OPTIONS.map { |name, value| "#{name}=#{value}" }.join('&amp;') + '&amp;passage=' + URI.escape(reference)&lt;br /&gt;  result = Net::HTTP.get(URI.parse(url))&lt;br /&gt;  if result =~ /^ERROR/&lt;br /&gt;    puts 'Error retrieving verse from web service'&lt;br /&gt;    nil&lt;br /&gt;  else&lt;br /&gt;    refs = []&lt;br /&gt;    result.scan(/^\S.+$/) {|ref| refs &lt;&lt; ref }&lt;br /&gt;    refs.each {|ref| result.gsub! ref, '' }&lt;br /&gt;    reference = combine_refs(refs)&lt;br /&gt;    text = result.gsub(/\s+/, ' ').strip&lt;br /&gt;    text = text.gsub(/"/, '') if (text.count('"') == 1 and text[0..0] == '"')&lt;br /&gt;    return {:reference =&gt; reference, :text =&gt; text}&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Usage:&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&gt; lookup_esv('John 3:16')&lt;br /&gt;=&gt; {:text=&gt;"For God so loved the world, that he gave his only Son, that whoever&lt;br /&gt;believes in him should not perish but have eternal life.", :reference=&gt;"John 3:16"}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 18 May 2006 03:24:42 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2068</guid>
      <author>timmorgan (Tim Morgan)</author>
    </item>
    <item>
      <title>wsdl the google API (search google with ruby)</title>
      <link>http://snippets.dzone.com/posts/show/826</link>
      <description>sign up to get a key first&lt;br /&gt;&lt;br /&gt;&lt;codE&gt;&lt;br /&gt;require 'soap/wsdlDriver'&lt;br /&gt;$KCODE = "UTF8"&lt;br /&gt;key = 'LVJnAm5QFHblahblahblah your key here'&lt;br /&gt;&lt;br /&gt;#create driver&lt;br /&gt;wsdl = "http://api.google.com/GoogleSearch.wsdl"&lt;br /&gt;driver = SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver&lt;br /&gt;query = "your query string here"&lt;br /&gt;start = 0&lt;br /&gt;max = 10&lt;br /&gt;  &lt;br /&gt;# see http://dev.ctor.org/soap4r/browser/trunk/sample/wsdl/googleSearch/wsdlDriver.rb&lt;br /&gt;@results = driver.doGoogleSearch( key, query, start, max, true, "", true, 'lang_en', '','')&lt;br /&gt;snippets = @results.resultElements.collect { |r| r.snippet } # you can get all kinds'a' info here&lt;br /&gt;self.update_attribute(:html, snippets.join("\n")) # or whatever&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;</description>
      <pubDate>Fri, 21 Oct 2005 13:54:54 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/826</guid>
      <author>court3nay ()</author>
    </item>
  </channel>
</rss>
