Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #3910 > unrolled thread

Check url address

Started by"Lukáš N." <dmnc.mobile@gmail.com>
First post2011-05-04 02:50 -0500
Last post2011-05-04 04:49 -0500
Articles 3 — 2 participants

Back to article view | Back to comp.lang.ruby


Contents

  Check url address "Lukáš N." <dmnc.mobile@gmail.com> - 2011-05-04 02:50 -0500
    Re: Check url address Jesús Gabriel y Galán <jgabrielygalan@gmail.com> - 2011-05-04 03:13 -0500
    Re: Check url address "Lukáš N." <dmnc.mobile@gmail.com> - 2011-05-04 04:49 -0500

#3910 — Check url address

From"Lukáš N." <dmnc.mobile@gmail.com>
Date2011-05-04 02:50 -0500
SubjectCheck url address
Message-ID<b2b29f58f6cdf0b1ff4c70ee93baea60@ruby-forum.com>
Hello all,

i would like to do something like define two urls, primary and
secondary. After that, check them and if primary is not available,
choose secondary url. At the end, put these to some variable for next
usage.

Thanks a lot! L.

-- 
Posted via http://www.ruby-forum.com/.

[toc] | [next] | [standalone]


#3911

FromJesús Gabriel y Galán <jgabrielygalan@gmail.com>
Date2011-05-04 03:13 -0500
Message-ID<BANLkTik8vhCOYLqdH0C0fAMc7HBh9gHA3w@mail.gmail.com>
In reply to#3910
On Wed, May 4, 2011 at 9:50 AM, Lukáš N. <dmnc.mobile@gmail.com> wrote:
> Hello all,
>
> i would like to do something like define two urls, primary and
> secondary. After that, check them and if primary is not available,
> choose secondary url. At the end, put these to some variable for next
> usage.

You can try to open the first URL and if there's any exception, use
the second one.
Something like:

ruby-1.9.1-p431 :004 > require 'open-uri'
 => true
ruby-1.9.1-p431 :005 > url1 = "http://fsdfsdfsdf.com"
 => "http://fsdfsdfsdf.com"
ruby-1.9.1-p431 :006 > url2 = "http://www.google.com"
 => "http://www.google.com"
ruby-1.9.1-p431 :007 > valid_url = begin
ruby-1.9.1-p431 :008 >     open(url1)
ruby-1.9.1-p431 :009?>     url1
ruby-1.9.1-p431 :010?>   rescue
ruby-1.9.1-p431 :011?>   url2
ruby-1.9.1-p431 :012?>   end
 => "http://www.google.com"
ruby-1.9.1-p431 :013 > valid_url
 => "http://www.google.com"

Jesus.

[toc] | [prev] | [next] | [standalone]


#3913

From"Lukáš N." <dmnc.mobile@gmail.com>
Date2011-05-04 04:49 -0500
Message-ID<3712fbfc24aebae545ea120cb280f8b4@ruby-forum.com>
In reply to#3910
Great, thank you so much :)

-- 
Posted via http://www.ruby-forum.com/.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.ruby


csiph-web