This pull request addresses multiple issues around the consistency and control of photo sizing (#117 and #130).
Going forward, users may pass a size parameter that will specify the size of the returned photos. This is achieved by altering the suffix of each img_src in the photos_controller.rb and latest_photos_controller.rb to correspond with the requested size and rover_id. I stored the logic for resizing in photo_helper.rb so it can be shared between both controllers.
Original suffixes (what is stored in the database)
Curiosity
Opportunity
Spirit
Perseverance
.jpg or .JPG
-BR.JPG
-BR.JPG
_1200.jpg
New suffix outputs
Size Parameter Value
Curiosity
Opportunity
Spirit
Perseverance
small
-thm.jpg
-THM.JPG
-THM.JPG
_320.jpg
medium
-br.jpg
-BR.JPG
-BR.JPG
_800.jpg
large or nil
.JPG
.JPG
.JPG
_1200.jpg
full
N/A
N/A
N/A
.png
Note: Some of these suffixes are case sensitive
Other changes
Move logic for searching photos by params and rover from photos_controller.rb and latest_photos_controller.rb to Photo.search method in models/photo.rb
Fix non-breaking syntax error in latest_photos_controller.rb (#145)
Add RSpec test file for latest_photos_controller.rb
Add RSpec tests for photos_controller.rb and latest_photos_controller.rb with size parameter
Change how img_src is sequenced in spec/factories.rb, so it does not conflict with tests involving size parameter
Potential problems for users
When not given a size parameter, photos from Opportunity and Spirit rovers will now be served in their large format; whereas they used to be served as medium.
Notes before merge
I have not tested these changes extensively with Opportunity and Spirit photos, because their scrapers are deprecated. Please test on a full development version of the API with Opportunity and Spirit photos before merging.
This pull request addresses multiple issues around the consistency and control of photo sizing (#117 and #130).
Going forward, users may pass a
size
parameter that will specify the size of the returned photos. This is achieved by altering the suffix of eachimg_src
in thephotos_controller.rb
andlatest_photos_controller.rb
to correspond with the requestedsize
androver_id
. I stored the logic for resizing inphoto_helper.rb
so it can be shared between both controllers.Original suffixes (what is stored in the database)
.jpg
or.JPG
-BR.JPG
-BR.JPG
_1200.jpg
New suffix outputs
small
-thm.jpg
-THM.JPG
-THM.JPG
_320.jpg
medium
-br.jpg
-BR.JPG
-BR.JPG
_800.jpg
large
ornil
.JPG
.JPG
.JPG
_1200.jpg
full
.png
Note: Some of these suffixes are case sensitive
Other changes
params
androver
fromphotos_controller.rb
andlatest_photos_controller.rb
toPhoto.search
method inmodels/photo.rb
latest_photos_controller.rb
(#145)latest_photos_controller.rb
photos_controller.rb
andlatest_photos_controller.rb
withsize
parameterimg_src
is sequenced inspec/factories.rb
, so it does not conflict with tests involvingsize
parameterPotential problems for users
size
parameter, photos from Opportunity and Spirit rovers will now be served in theirlarge
format; whereas they used to be served asmedium
.Notes before merge
I have not tested these changes extensively with Opportunity and Spirit photos, because their scrapers are deprecated. Please test on a full development version of the API with Opportunity and Spirit photos before merging.