Day 76 : #100DaysofCode - First Time Using Unsplash Gem

sincerelybrittany

Brittany

Posted on August 16, 2020

Day 76 : #100DaysofCode - First Time Using Unsplash Gem

Today I continued to work on my photo app . I decided to use the unsplash gem . I was able to add it and now I am just trying to iterate though the unsplash object to get the photos I need. At the moment what I am able to search for the following:

@photo = Unsplash::Photo.search("cats")

And when I run @photo.first, I get the following:

#<Unsplash::Photo:0x00007fc9406d3768 @attributes=#<OpenStruct 
id="1l2waV8glIQ", created_at="2018-07-23T18:51:02-04:00",
updated_at="2020-08-14T01:05:24-04:00", promoted_at=nil, 
 width=3200, height=2361, color="#090708", description=nil, 
 alt_description="selective focus photography brown cat lying
  over black cat", urls=
{"raw"=>"https://images.unsplash.com/photo-1532386236358- 
a33d8a9434e3?ixlib=rb- 
1.2.1&ixid=eyJhcHBfaWQiOjE1Nzk4OX0&utm_source=photo_app&utm_me dium=referral&utm_campaign=api-credit",
  "full"=>"https://images.unsplash.com/photo-1532386236358- a33d8a9434e3?ixlib=rb- 
1.2.1&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE1Nz
k4OX0&utm_source=photo_app&utm_medium=referral&utm_campaign=ap
i-credit", "regular"=>"https://images.unsplash.com/photo-
1532386236358-a33d8a9434e3?ixlib=rb-
1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max&ixid
=eyJhcHBfaWQiOjE1Nzk4OX0&utm_source=photo_app&utm_medium=refer
ral&utm_campaign=api-credit", 
"small"=>"https://images.unsplash.com/photo-1532386236358-
a33d8a9434e3?ixlib=rb-
1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=
eyJhcHBfaWQiOjE1Nzk4OX0&utm_source=photo_app&utm_medium=referr
al&utm_campaign=api-credit", 
"thumb"=>"https://images.unsplash.com/photo-1532386236358-
a33d8a9434e3?ixlib=rb-
1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=200&fit=max&ixid=
eyJhcHBfaWQiOjE1Nzk4OX0&utm_source=photo_app&utm_medium=referr
al&utm_campaign=api-credit"}, links=
{"self"=>"https://api.unsplash.com/photos/1l2waV8glIQ?
utm_source=photo_app&utm_medium=referral&utm_campaign=api-
credit", "html"=>"https://unsplash.com/photos/1l2waV8glIQ?
utm_source=photo_app&utm_medium=referral&utm_campaign=api-
credit", 
"download"=>"https://unsplash.com/photos/1l2waV8glIQ/download?
utm_source=photo_app&utm_medium=referral&utm_campaign=api-
credit", 
"download_location"=>"https://api.unsplash.com/photos/1l2waV8g
lIQ/download?
utm_source=photo_app&utm_medium=referral&utm_campaign=api-
credit"}, categories=[], likes=463, liked_by_user=false, 
current_user_collections=[], sponsorship=nil, user=
{"id"=>"R9blcTCtiXs", "updated_at"=>"2020-08-13T12:39:52-
04:00", "username"=>"calypso999", "name"=>"Raul Varzar",
 "first_name"=>"Raul", "last_name"=>"Varzar", 
"twitter_username"=>"VarzarR", 
"portfolio_url"=>"http://www.raulvarzar.com/", "bio"=>"Thanks
 for checking out my profile ;)\r\n\r\nMy Instagram: 
@raulvarzar", "location"=>"Targu Mures", "links"=>
{"self"=>"https://api.unsplash.com/users/calypso999", 
"html"=>"https://unsplash.com/@calypso999", 
 "photos"=>"https://api.unsplash.com/users/calypso999/photos",
 "likes"=>"https://api.unsplash.com/users/calypso999/likes", 
"portfolio"=>"https://api.unsplash.com/users/calypso999/portfo
lio", "following"=>"https://api.unsplash.com/users/calypso999/follow
ing", "followers"=>"https://api.unsplash.com/users/calypso999/follow
ers"}, "profile_image"=>
{"small"=>"https://images.unsplash.com/profile-1538941834664-
a6d8eb80866b?ixlib=rb-
1.2.1&q=80&fm=jpg&crop=faces&cs=tinysrgb&fit=crop&h=32&w=32",
 "medium"=>"https://images.unsplash.com/profile-1538941834664-
a6d8eb80866b?ixlib=rb-
1.2.1&q=80&fm=jpg&crop=faces&cs=tinysrgb&fit=crop&h=64&w=64", 
"large"=>"https://images.unsplash.com/profile-1538941834664-
a6d8eb80866b?ixlib=rb-
1.2.1&q=80&fm=jpg&crop=faces&cs=tinysrgb&fit=crop&h=128&w=128"
}, "instagram_username"=>"raulvarzar", "total_collections"=>7,
 "total_likes"=>3960, "total_photos"=>38, 
"accepted_tos"=>true}, tags=[{"type"=>"landing_page", 
"title"=>"cat", "source"=>{"ancestry"=>{"type"=>
{"slug"=>"images", "pretty_slug"=>"Images"}, "category"=>
{"slug"=>"animals", "pretty_slug"=>"Animals"}, "subcategory"=>
{"slug"=>"cat", "pretty_slug"=>"Cat"}}, "title"=>"Cat Images &
 Pictures", "subtitle"=>"Download free cat images", 
"description"=>"9 lives isn't enough to capture the amazing-
ness of cats. You need high-quality, professionally 
photographed images to do that. Unsplash's collection of cat 
images capture the wonder of the kitty in high-definition, and
 you can use these images however you wish for free.", 
"meta_title"=>"20+ Cat Pictures & Images [HD] | Download Free
 Images & Stock Photos on Unsplash", 
"meta_description"=>"Choose from hundreds of free cat 
pictures. Download HD cat photos for free on Unsplash.", 
"cover_photo"=>{"id"=>"_SMNO4cN9vs", "created_at"=>"2018-12-
30T12:17:38-05:00", "updated_at"=>"2020-07-21T01:17:49-04:00",
 "promoted_at"=>"2019-01-01T05:23:58-05:00", "width"=>4000, 
"height"=>4000, "color"=>"#E8C98D", "description"=>"Glow in 
the Dark", "alt_description"=>"yellow eyes", "urls"=>
{"raw"=>"https://images.unsplash.com/photo-1546190255-
451a91afc548?ixlib=rb-1.2.1", 
"full"=>"https://images.unsplash.com/photo-1546190255-451a91afc548?ixlib=rb-1.2.1&q=85&fm=jpg&crop=entropy&cs=srgb", "regular"=>"https://images.unsplash.com/photo-1546190255-451a91afc548?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max",
 "small"=>"https://images.unsplash.com/photo-1546190255-
451a91afc548?ixlib=rb-
1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max", 
"thumb"=>"https://images.unsplash.com/photo-1546190255-
451a91afc548?ixlib=rb-
1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=200&fit=max"}, 
"links"=>
{"self"=>"https://api.unsplash.com/photos/_SMNO4cN9vs", 
"html"=>"https://unsplash.com/photos/_SMNO4cN9vs", 
"download"=>"https://unsplash.com/photos/_SMNO4cN9vs/download"
, "download_location"=>"https://api.unsplash.com/photos/_SMNO4cN
9vs/download"}, "categories"=>[], "likes"=>413, 
"liked_by_user"=>false, "current_user_collections"=>[], 
"sponsorship"=>nil, "user"=>{"id"=>"KlbPlQFM3j4", 
"updated_at"=>"2020-02-01T14:47:55-05:00", 
"username"=>"unlesbar", "name"=>"Stephan Henning", 
"first_name"=>"Stephan", "last_name"=>"Henning", 
"twitter_username"=>nil, "portfolio_url"=>nil, "bio"=>nil, 
"location"=>"Germany", "links"=>
{"self"=>"https://api.unsplash.com/users/unlesbar", 
"html"=>"https://unsplash.com/@unlesbar", 
"photos"=>"https://api.unsplash.com/users/unlesbar/photos", 
"likes"=>"https://api.unsplash.com/users/unlesbar/likes", 
"portfolio"=>"https://api.unsplash.com/users/unlesbar/portfolio", 
"following"=>"https://api.unsplash.com/users/unlesbar/following", 
"followers"=>"https://api.unsplash.com/users/unlesbar/followers"}, "profile_image"=>
{"small"=>"https://images.unsplash.com/profile-1531167540173-a920494357e7?ixlib=rb-
1.2.1&q=80&fm=jpg&crop=faces&cs=tinysrgb&fit=crop&h=32&w=32", 
"medium"=>"https://images.unsplash.com/profile-1531167540173-a920494357e7?ixlib=rb-
1.2.1&q=80&fm=jpg&crop=faces&cs=tinysrgb&fit=crop&h=64&w=64",
 "large"=>"https://images.unsplash.com/profile-1531167540173-
a920494357e7?ixlib=rb-
1.2.1&q=80&fm=jpg&crop=faces&cs=tinysrgb&fit=crop&h=128&w=128"
}, "instagram_username"=>nil, "total_collections"=>3, 
"total_likes"=>77, "total_photos"=>23, 
"accepted_tos"=>true}}}}, {"type"=>"landing_page", 
"title"=>"animal", "source"=>{"ancestry"=>{"type"=>
{"slug"=>"images", "pretty_slug"=>"Images"}, "category"=>
{"slug"=>"animals", "pretty_slug"=>"Animals"}}, "title"=>"Animals Images & Pictures", "subtitle"=>"Download 
free animals images", "description"=>"Passionate photographers
 have captured the most gorgeous animals in the world in their
 natural habitats and shared them with Unsplash. Now you can 
use these photos however you wish, for free!", 
"meta_title"=>"Best 20+ Animals Pictures [HD] | Download Free
 Images on Unsplash", "meta_description"=>"Choose from 
hundreds of free animals pictures. Download HD animals photos
 for free on Unsplash.", "cover_photo"=>{"id"=>"YozNeHM8MaA",
 "created_at"=>"2017-04-18T13:00:04-04:00", 
"updated_at"=>"2020-07-21T01:26:52-04:00", 
"promoted_at"=>"2017-04-19T13:54:55-04:00", "width"=>5184, 
"height"=>3456, "color"=>"#120803", "description"=>"I met this
 dude on safari in Kruger National park in northern South
 Africa. The giraffes were easily in my favorite creatures to
 witness. They seemed almost prehistoric the the way the 
graced the African plain.", "alt_description"=>"selective 
focus photography of giraffe", "urls"=>
{"raw"=>"https://images.unsplash.com/photo-1492534513006-
37715f336a39?ixlib=rb-1.2.1", 
"full"=>"https://images.unsplash.com/photo-1492534513006-
37715f336a39?ixlib=rb-1.2.1&q=85&fm=jpg&crop=entropy&cs=srgb",
 "regular"=>"https://images.unsplash.com/photo-1492534513006-37715f336a39?ixlib=rb-
1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max",
 "small"=>"https://images.unsplash.com/photo-1492534513006-37715f336a39?ixlib=rb-
1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max", "thumb"=>"https://images.unsplash.com/photo-1492534513006-37715f336a39?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=200&fit=max"}, "links"=>{"self"=>"https://api.unsplash.com/photos/YozNeHM8MaA", "html"=>"https://unsplash.com/photos/YozNeHM8MaA", "download"=>"https://unsplash.com/photos/YozNeHM8MaA/download", "download_location"=>"https://api.unsplash.com/photos/YozNeHM8MaA/download"}, "categories"=>[], "likes"=>1127, "liked_by_user"=>false, "current_user_collections"=>[], "sponsorship"=>nil, "user"=>{"id"=>"J6cg9TA8-e8", "updated_at"=>"2020-05-12T09:05:39-04:00", 
"username"=>"judahlegge", "name"=>"Judah Legge", 
"first_name"=>"Judah", "last_name"=>"Legge", 
"twitter_username"=>nil, "portfolio_url"=>nil, "bio"=>nil, "location"=>nil, "links"=>
{"self"=>"https://api.unsplash.com/users/judahlegge", 
"html"=>"https://unsplash.com/@judahlegge", 
"photos"=>"https://api.unsplash.com/users/judahlegge/photos", "likes"=>"https://api.unsplash.com/users/judahlegge/likes", 
"portfolio"=>"https://api.unsplash.com/users/judahlegge/portfolio", 
"following"=>"https://api.unsplash.com/users/judahlegge/following", 
"followers"=>"https://api.unsplash.com/users/judahlegge/follow
ers"}, "profile_image"=>
{"small"=>"https://images.unsplash.com/profile-fb-1492532922-
001f65e39343.jpg?ixlib=rb-
1.2.1&q=80&fm=jpg&crop=faces&cs=tinysrgb&fit=crop&h=32&w=32",
 "medium"=>"https://images.unsplash.com/profile-fb-1492532922-
001f65e39343.jpg?ixlib=rb-
1.2.1&q=80&fm=jpg&crop=faces&cs=tinysrgb&fit=crop&h=64&w=64", 
"large"=>"https://images.unsplash.com/profile-fb-1492532922-
001f65e39343.jpg?ixlib=rb-
1.2.1&q=80&fm=jpg&crop=faces&cs=tinysrgb&fit=crop&h=128&w=128"
}, "instagram_username"=>nil, "total_collections"=>0, 
"total_likes"=>4, "total_photos"=>1, 
"accepted_tos"=>false}}}}, {"type"=>"landing_page", 
"title"=>"kitten", "source"=>{"ancestry"=>{"type"=>
{"slug"=>"images", "pretty_slug"=>"Images"}, "category"=>
{"slug"=>"animals", "pretty_slug"=>"Animals"}, "subcategory"=>
{"slug"=>"kitten", "pretty_slug"=>"Kitten"}}, "title"=>"Kitten Images & Pictures", "subtitle"=>"Download free kitten images",
 "description"=>"Caution: Unsplash users are known to perish 
from cuteness overload after flipping through our massive 
catalogue of beautiful (and beautifully cute) kitten images. 
Free to use, courtesy of the Unsplash community!", 
"meta_title"=>"100+ Kitten Images | Download Free Images on 
Unsplash", "meta_description"=>"Choose from hundreds of free 
kitten pictures. Download HD kitten photos for free on 
Unsplash.", "cover_photo"=>{"id"=>"RCfi7vgJjUY", 
"created_at"=>"2019-06-09T17:25:56-04:00",
"updated_at"=>"2020-07-14T01:03:18-04:00", "promoted_at"=>nil, "width"=>6000, "height"=>4000, "color"=>"#182B1F", 
"description"=>nil, "alt_description"=>"orange tabby kitten in
 grasses", "urls"=>{"raw"=>"https://images.unsplash.com/photo-
1560114928-40f1f1eb26a0?ixlib=rb-1.2.1", 
"full"=>"https://images.unsplash.com/photo-1560114928-
40f1f1eb26a0?ixlib=rb-1.2.1&q=85&fm=jpg&crop=entropy&cs=srgb",
 "regular"=>"https://images.unsplash.com/photo-1560114928-
40f1f1eb26a0?ixlib=rb-
1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max", 
"small"=>"https://images.unsplash.com/photo-1560114928-
40f1f1eb26a0?ixlib=rb-
1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max", 
"thumb"=>"https://images.unsplash.com/photo-1560114928-
40f1f1eb26a0?ixlib=rb-
1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=200&fit=max"}, 
"links"=>
{"self"=>"https://api.unsplash.com/photos/RCfi7vgJjUY", 
"html"=>"https://unsplash.com/photos/RCfi7vgJjUY", 
"download"=>"https://unsplash.com/photos/RCfi7vgJjUY/download"
, "download_location"=>"https://api.unsplash.com/photos/RCfi7vgJ
jUY/download"}, "categories"=>[], "likes"=>108, 
"liked_by_user"=>false, "current_user_collections"=>[], 
"sponsorship"=>nil, "user"=>{"id"=>"blas3WX3vv8", 
"updated_at"=>"2020-07-21T05:55:06-04:00", 
"username"=>"yirage", "name"=>"Andriyko Podilnyk", 
"first_name"=>"Andriyko", "last_name"=>"Podilnyk", 
"twitter_username"=>nil, 
"portfolio_url"=>"https://www.patreon.com/andriykopodilnyk", 
"bio"=>"♥The portal of creativity, emotion аnd minimalism for 
you\r\n♥Instagram: @andriyko.podilnyk  // ♥You can help me to 
get more motivation in order to make more pics for you, you 
can check them via the link above↑", "location"=>"Ukraine, 
Lviv", "links"=>
{"self"=>"https://api.unsplash.com/users/yirage", 
"html"=>"https://unsplash.com/@yirage", 
"photos"=>"https://api.unsplash.com/users/yirage/photos", 
"likes"=>"https://api.unsplash.com/users/yirage/likes", 
"portfolio"=>"https://api.unsplash.com/users/yirage/portfolio"
, 
"following"=>"https://api.unsplash.com/users/yirage/following", 
"followers"=>"https://api.unsplash.com/users/yirage/followers"}, "profile_image"=>
{"small"=>"https://images.unsplash.com/profile-1590751211107-
90af24223cddimage?ixlib=rb-
1.2.1&q=80&fm=jpg&crop=faces&cs=tinysrgb&fit=crop&h=32&w=32",
 "medium"=>"https://images.unsplash.com/profile-1590751211107-
90af24223cddimage?ixlib=rb-
1.2.1&q=80&fm=jpg&crop=faces&cs=tinysrgb&fit=crop&h=64&w=64", 
"large"=>"https://images.unsplash.com/profile-1590751211107-
90af24223cddimage?ixlib=rb-
1.2.1&q=80&fm=jpg&crop=faces&cs=tinysrgb&fit=crop&h=128&w=128"
}, "instagram_username"=>"andriyko.podilnyk", 
"total_collections"=>6, "total_likes"=>45, 
"total_photos"=>1309, "accepted_tos"=>true}}}}]>>
Enter fullscreen mode Exit fullscreen mode

My goal tomorrow is to get the information to show in my views!

Song of the Day:

💖 💪 🙅 🚩
sincerelybrittany
Brittany

Posted on August 16, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related