Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9271583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:39:23+00:00 2026-06-18T15:39:23+00:00

I have the following if else statement in a lib method: begin url =

  • 0

I have the following if else statement in a lib method:

begin
    url                  = URI.parse("url"+ product )
    @response            = JSON.parse(Net::HTTP.get_response(url).body)
    url2                 = URI.parse("url" + product)
    @response1           = JSON.parse(Net::HTTP.get_response(url2).body)

    if @response != nil
        @url                 = @response["product"]["url"]
        image_url1           = @response["product"]["image_url"]
        @title               = @response["product"]["title"] 

    else
        @url                 = @response1["ProductUrl"]
        @image_url           = @response1["ImagePath"]  
        @title               = @response1["ProductName"]
    end
  rescue 
     next 
end

Currently this method is only checking url and @response, and is simply skipping if @response = nil. How do I check if @response is nil, and if so, use url2 and @response1 and save the variables returned from that response. If @response is not nil, save the variables returned from @respoonse.

@response and @response1 are different APIs

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T15:39:26+00:00Added an answer on June 18, 2026 at 3:39 pm

    I think this is what you want. The key is that to check for nil, use @response.nil? Another problem is see is that you get the same url if it fails the first time – not sure why you would ask for the same url again and treat it differently if it failed the first time.

    begin
      url = URI.parse("url+ product )
      @response = JSON.parse(Net::HTTP.get_response(url).body)
    
      if !@response.nil?
        @url = @response["product"]["walmart_canonical_url"]
        @image_url = @response["product"]["image_url"]
        @title = @response["product"]["title"] 
      else
        url = URI.parse("url" + product)
        @response = JSON.parse(Net::HTTP.get_response(url2).body)
        @url = @response["ProductUrl"]
        @image_url = @response["ImagePath"]  
        @title = @response["ProductName"]
      end
    
    rescue
      next
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following fiddle: http://jsfiddle.net/BFSH4/ As you see there are two issues: The h1
I have the following code: http://jsfiddle.net/SPWWx/ I'm completely new to javascript, this is my
Not having much luck, I have the following if/else statement in Razor which works
I have following PHP if/else statement - how can I tell it to go
I have the following code with the if...else statement within a while loop. $colour
I have the following python code for an if,elif,else statement: if line_num == 151:
I have the following statement: SELECT CASE WHEN (1 = 1) THEN 10 ELSE
I have the following T-SQL if statement: if @changeType = 'ChangeFrom' begin print 'yep'
I have the following class written by someone else that I'm trying to understand
I have the following short version of a tsql if else if.. IF @var

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.