Looping and selecting

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Looping and selecting

kaine wright
i have this output from an api call

@output['products'][0]
 => {"url"=>"http://omgili.com/ri/.wHSUbtEfZTzBH6c9Z4cI15_sA3Hthoy48U8beRZ_m5lA7IjRC07KAl_t9PZZTUpVyIElYRPNwESkpgWrFuLtCsKQ1Apdjx_jld142pfHUAdippyPkgHob2bwpktxkzZqvVelr3L3OOq9qp5XCHXEYkx1GYb0O_awd5Z8FnemrBnhIJ4ZIOaKn7WinS9k36LajW78ScZZFngDQem4_p6BKrC02m1OhRc", "uuid"=>"bc54af0e0b4da231cad1a1352544fd3e6c234c68", "source"=>{"site_full"=>"www.walmart.com", "site"=>"walmart.com", "site_section"=>"https://www.walmart.com/", "section_title"=>"Walmart.com: Free 2-Day Shipping on Millions of Items", "country"=>"US"}, "name"=>"DIY Home Security for Preppers: 16 DIY Home Security Projects to Protect Your Family from Any Disaster: (Home Security Arduino, Home Security Raspberr", "description"=>"Getting Your FREE Bonus Download this book, read it to the end and see \"BONUS: Your FREE Gift\" chapter after the conclusion. DIY Home Security for Preppers (FREE Bonus Included) 16 DIY Home Security Projects To Protect Your Family From Any Disaster", "brand"=>"", "price"=>8.95, "currency"=>"$", "offer_price"=>7.46, "model"=>nil, "manufacturer"=>nil, "in_stock"=>true, "on_sale"=>true, "product_id"=>"53228544", "sku"=>nil, "mpn"=>nil, "colors"=>[], "aggregated_rating"=>nil, "best_rating"=>nil, "worst_rating"=>nil, "rating_count"=>nil, "reviews_count"=>nil, "categories"=>["equipment, appliances & supplies", "books", "house & home", "home page", "travel", "house, home & gardening", "toys-hobbies"], "width"=>nil, "height"=>nil, "weight"=>nil, "depth"=>nil, "images"=>["https://i5.walmartimages.com/asr/8db293c3-165e-4d4c-85bd-0d07390211f1_1.4f4822a5adfdb0ade9491a1a4db775e9.jpeg"], "language"=>"english", "last_changed"=>"2017-10-10T06:22:00.000+03:00", "crawled"=>"2017-10-10T06:22:00.000+03:00", "product_history"=>"/productHistory?token=b0a6c338-0c8a-4ece-82ee-b374101d9fcb&productId=http%3A%2F%2Fomgili.com%2Fri%2F.wHSUbtEfZTzBH6c9Z4cI15_sA3Hthoy48U8beRZ_m5lA7IjRC07KAl_t9PZZTUpVyIElYRPNwESkpgWrFuLtCsKQ1Apdjx_jld142pfHUAdippyPkgHob2bwpktxkzZqvVelr3L3OOq9qp5XCHXEYkx1GYb0O_awd5Z8FnemrBnhIJ4ZIOaKn7WinS9k36LajW78ScZZFngDQem4_p6BKrC02m1OhRc"}

for some reason i am unable to loop through all 100 products. i also am unable to use something like @output['products'][0]['images'] to select the image using image_tag. I can use ['products'][0]['name'] etc just not the images or looping.

Could anyone help in what im doing wrong. I tried looping the outer elements first then the inner elements but failed. @output contains 100 results from the api call from webhoseio. (i dont want to use the webhose gem im really trying to grasp an understanding of how to use other gems like httparty or rest-client.)

the format was set to :json

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/bb7f95f9-95ce-4440-832d-4b33f2060ea2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Looping and selecting

dasibre
How are you looping through the result. When you say you are unable to loop through, what do you mean exactly, what error are you getting
On Tuesday, April 10, 2018 at 1:14:24 PM UTC-4, kaine wright wrote:
i have this output from an api call

@output['products'][0]
 => {"url"=>"<a href="http://omgili.com/ri/.wHSUbtEfZTzBH6c9Z4cI15_sA3Hthoy48U8beRZ_m5lA7IjRC07KAl_t9PZZTUpVyIElYRPNwESkpgWrFuLtCsKQ1Apdjx_jld142pfHUAdippyPkgHob2bwpktxkzZqvVelr3L3OOq9qp5XCHXEYkx1GYb0O_awd5Z8FnemrBnhIJ4ZIOaKn7WinS9k36LajW78ScZZFngDQem4_p6BKrC02m1OhRc" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fomgili.com%2Fri%2F.wHSUbtEfZTzBH6c9Z4cI15_sA3Hthoy48U8beRZ_m5lA7IjRC07KAl_t9PZZTUpVyIElYRPNwESkpgWrFuLtCsKQ1Apdjx_jld142pfHUAdippyPkgHob2bwpktxkzZqvVelr3L3OOq9qp5XCHXEYkx1GYb0O_awd5Z8FnemrBnhIJ4ZIOaKn7WinS9k36LajW78ScZZFngDQem4_p6BKrC02m1OhRc\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEBnr-BZ08X5sWXcDKvHhnCEHXofw&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fomgili.com%2Fri%2F.wHSUbtEfZTzBH6c9Z4cI15_sA3Hthoy48U8beRZ_m5lA7IjRC07KAl_t9PZZTUpVyIElYRPNwESkpgWrFuLtCsKQ1Apdjx_jld142pfHUAdippyPkgHob2bwpktxkzZqvVelr3L3OOq9qp5XCHXEYkx1GYb0O_awd5Z8FnemrBnhIJ4ZIOaKn7WinS9k36LajW78ScZZFngDQem4_p6BKrC02m1OhRc\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEBnr-BZ08X5sWXcDKvHhnCEHXofw&#39;;return true;">http://omgili.com/ri/.wHSUbtEfZTzBH6c9Z4cI15_sA3Hthoy48U8beRZ_m5lA7IjRC07KAl_t9PZZTUpVyIElYRPNwESkpgWrFuLtCsKQ1Apdjx_jld142pfHUAdippyPkgHob2bwpktxkzZqvVelr3L3OOq9qp5XCHXEYkx1GYb0O_awd5Z8FnemrBnhIJ4ZIOaKn7WinS9k36LajW78ScZZFngDQem4_p6BKrC02m1OhRc", "uuid"=>"bc54af0e0b4da231cad1a1352544fd3e6c234c68", "source"=>{"site_full"=>"<a href="http://www.walmart.com" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.walmart.com\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF11nakMeIJ37iSE23Cz7dyQLBQyQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.walmart.com\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF11nakMeIJ37iSE23Cz7dyQLBQyQ&#39;;return true;">www.walmart.com", "site"=>"<a href="http://walmart.com" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwalmart.com\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFU5kqx3koozbxM_2c8L3gjGtm8DQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwalmart.com\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFU5kqx3koozbxM_2c8L3gjGtm8DQ&#39;;return true;">walmart.com", "site_section"=>"<a href="https://www.walmart.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwww.walmart.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFbLOVAdkN_LG8GzKemLDgrD_3sSQ&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwww.walmart.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFbLOVAdkN_LG8GzKemLDgrD_3sSQ&#39;;return true;">https://www.walmart.com/", "section_title"=>"Walmart.com: Free 2-Day Shipping on Millions of Items", "country"=>"US"}, "name"=>"DIY Home Security for Preppers: 16 DIY Home Security Projects to Protect Your Family from Any Disaster: (Home Security Arduino, Home Security Raspberr", "description"=>"Getting Your FREE Bonus Download this book, read it to the end and see \"BONUS: Your FREE Gift\" chapter after the conclusion. DIY Home Security for Preppers (FREE Bonus Included) 16 DIY Home Security Projects To Protect Your Family From Any Disaster", "brand"=>"", "price"=>8.95, "currency"=>"$", "offer_price"=>7.46, "model"=>nil, "manufacturer"=>nil, "in_stock"=>true, "on_sale"=>true, "product_id"=>"53228544", "sku"=>nil, "mpn"=>nil, "colors"=>[], "aggregated_rating"=>nil, "best_rating"=>nil, "worst_rating"=>nil, "rating_count"=>nil, "reviews_count"=>nil, "categories"=>["equipment, appliances & supplies", "books", "house & home", "home page", "travel", "house, home & gardening", "toys-hobbies"], "width"=>nil, "height"=>nil, "weight"=>nil, "depth"=>nil, "images"=>["<a href="https://i5.walmartimages.com/asr/8db293c3-165e-4d4c-85bd-0d07390211f1_1.4f4822a5adfdb0ade9491a1a4db775e9.jpeg" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fi5.walmartimages.com%2Fasr%2F8db293c3-165e-4d4c-85bd-0d07390211f1_1.4f4822a5adfdb0ade9491a1a4db775e9.jpeg\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHp-h5yuSLzdNH9iNTd8JNcv1qPzw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fi5.walmartimages.com%2Fasr%2F8db293c3-165e-4d4c-85bd-0d07390211f1_1.4f4822a5adfdb0ade9491a1a4db775e9.jpeg\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHp-h5yuSLzdNH9iNTd8JNcv1qPzw&#39;;return true;">https://i5.walmartimages.com/asr/8db293c3-165e-4d4c-85bd-0d07390211f1_1.4f4822a5adfdb0ade9491a1a4db775e9.jpeg"], "language"=>"english", "last_changed"=>"2017-10-10T06:22:00.000+03:00", "crawled"=>"2017-10-10T06:22:00.000+03:00", "product_history"=>"/productHistory?token=b0a6c338-0c8a-4ece-82ee-b374101d9fcb&productId=http%3A%2F%2Fomgili.com%2Fri%2F.wHSUbtEfZTzBH6c9Z4cI15_sA3Hthoy48U8beRZ_m5lA7IjRC07KAl_t9PZZTUpVyIElYRPNwESkpgWrFuLtCsKQ1Apdjx_jld142pfHUAdippyPkgHob2bwpktxkzZqvVelr3L3OOq9qp5XCHXEYkx1GYb0O_awd5Z8FnemrBnhIJ4ZIOaKn7WinS9k36LajW78ScZZFngDQem4_p6BKrC02m1OhRc"}

for some reason i am unable to loop through all 100 products. i also am unable to use something like @output['products'][0]['images'] to select the image using image_tag. I can use ['products'][0]['name'] etc just not the images or looping.

Could anyone help in what im doing wrong. I tried looping the outer elements first then the inner elements but failed. @output contains 100 results from the api call from webhoseio. (i dont want to use the webhose gem im really trying to grasp an understanding of how to use other gems like httparty or rest-client.)

the format was set to :json

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/b5eb68e9-f697-42b5-8a2d-ad514904b18c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Looping and selecting

Colin Law
In reply to this post by kaine wright
On 10 April 2018 at 16:08, kaine wright <[hidden email]> wrote:

> i have this output from an api call
>
> @output['products'][0]
>  =>
> {"url"=>"http://omgili.com/ri/.wHSUbtEfZTzBH6c9Z4cI15_sA3Hthoy48U8beRZ_m5lA7IjRC07KAl_t9PZZTUpVyIElYRPNwESkpgWrFuLtCsKQ1Apdjx_jld142pfHUAdippyPkgHob2bwpktxkzZqvVelr3L3OOq9qp5XCHXEYkx1GYb0O_awd5Z8FnemrBnhIJ4ZIOaKn7WinS9k36LajW78ScZZFngDQem4_p6BKrC02m1OhRc",
> "uuid"=>"bc54af0e0b4da231cad1a1352544fd3e6c234c68",
> "source"=>{"site_full"=>"www.walmart.com", "site"=>"walmart.com",
> "site_section"=>"https://www.walmart.com/", "section_title"=>"Walmart.com:
> Free 2-Day Shipping on Millions of Items", "country"=>"US"}, "name"=>"DIY
> Home Security for Preppers: 16 DIY Home Security Projects to Protect Your
> Family from Any Disaster: (Home Security Arduino, Home Security Raspberr",
> "description"=>"Getting Your FREE Bonus Download this book, read it to the
> end and see \"BONUS: Your FREE Gift\" chapter after the conclusion. DIY Home
> Security for Preppers (FREE Bonus Included) 16 DIY Home Security Projects To
> Protect Your Family From Any Disaster", "brand"=>"", "price"=>8.95,
> "currency"=>"$", "offer_price"=>7.46, "model"=>nil, "manufacturer"=>nil,
> "in_stock"=>true, "on_sale"=>true, "product_id"=>"53228544", "sku"=>nil,
> "mpn"=>nil, "colors"=>[], "aggregated_rating"=>nil, "best_rating"=>nil,
> "worst_rating"=>nil, "rating_count"=>nil, "reviews_count"=>nil,
> "categories"=>["equipment, appliances & supplies", "books", "house & home",
> "home page", "travel", "house, home & gardening", "toys-hobbies"],
> "width"=>nil, "height"=>nil, "weight"=>nil, "depth"=>nil,
> "images"=>["https://i5.walmartimages.com/asr/8db293c3-165e-4d4c-85bd-0d07390211f1_1.4f4822a5adfdb0ade9491a1a4db775e9.jpeg"],
> "language"=>"english", "last_changed"=>"2017-10-10T06:22:00.000+03:00",
> "crawled"=>"2017-10-10T06:22:00.000+03:00",
> "product_history"=>"/productHistory?token=b0a6c338-0c8a-4ece-82ee-b374101d9fcb&productId=http%3A%2F%2Fomgili.com%2Fri%2F.wHSUbtEfZTzBH6c9Z4cI15_sA3Hthoy48U8beRZ_m5lA7IjRC07KAl_t9PZZTUpVyIElYRPNwESkpgWrFuLtCsKQ1Apdjx_jld142pfHUAdippyPkgHob2bwpktxkzZqvVelr3L3OOq9qp5XCHXEYkx1GYb0O_awd5Z8FnemrBnhIJ4ZIOaKn7WinS9k36LajW78ScZZFngDQem4_p6BKrC02m1OhRc"}
>
> for some reason i am unable to loop through all 100 products. i also am
> unable to use something like @output['products'][0]['images'] to select the
> image using image_tag. I can use ['products'][0]['name'] etc just not the
> images or looping.

Did you realise that images is an array?

Colin

>
> Could anyone help in what im doing wrong. I tried looping the outer elements
> first then the inner elements but failed. @output contains 100 results from
> the api call from webhoseio. (i dont want to use the webhose gem im really
> trying to grasp an understanding of how to use other gems like httparty or
> rest-client.)
>
> the format was set to :json
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [hidden email].
> To post to this group, send email to [hidden email].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-talk/bb7f95f9-95ce-4440-832d-4b33f2060ea2%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLu%2B9hU_JGOnqTSPyK8RthEWAXw0z_StBRgMzWL2SCgj7w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Looping and selecting

kaine wright
Hi thanks for the reply id over looked that completely. what solved this was @output['products'][0]['images'].first

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/8011c55c-c789-4332-8768-d168fbde7b7c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Looping and selecting

kaine wright
In reply to this post by dasibre


On Wednesday, April 11, 2018 at 7:10:53 PM UTC+8, dasibre wrote:
How are you looping through the result. When you say you are unable to loop through, what do you mean exactly, what error are you getting


Hi thanks for the reply. Ive been trying to loop through like so

<% @output['products'].each do |out| %>
<p><% @output['name'] %></p>
<P><% image_tag @output['images'].first %>  </p>
<% link_to 'Show', product[:id]_show_path %> 
<% end %>

ive been using this as a basic template.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/60062487-0b2c-4c40-9e5c-fbde50017df0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Looping and selecting

kaine wright
In my pagecontentController i have index and show. for index its
def index
          @keyword = "Arduino"
          webhoseio = Webhoseio.new(' # { ENV [ ' APIKEY2 ' ] } ' )
          @output = webhoseio.query('productFilter', {'q': @keyword})
end

def show
         @output['products'][:id]
end

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/ac4ca2f0-1789-4e17-a978-d2690c48a17a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Looping and selecting

Colin Law
In reply to this post by kaine wright
On 12 April 2018 at 14:27, kaine wright <[hidden email]> wrote:

>
>
> On Wednesday, April 11, 2018 at 7:10:53 PM UTC+8, dasibre wrote:
>>
>> How are you looping through the result. When you say you are unable to
>> loop through, what do you mean exactly, what error are you getting
>>
>
> Hi thanks for the reply. Ive been trying to loop through like so
>
> <% @output['products'].each do |out| %>
> <p><% @output['name'] %></p>
> <P><% image_tag @output['images'].first %>  </p>

That should be out['images'].first

> <% link_to 'Show', product[:id]_show_path %>
> <% end %>
>
> ive been using this as a basic template.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [hidden email].
> To post to this group, send email to [hidden email].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-talk/60062487-0b2c-4c40-9e5c-fbde50017df0%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLsSR_XdXj4Yddyt_Od6fkvf2Z%3DGgZPak0G0Gfq0xcAROg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.