Skip to content

Commit

Permalink
Merge 2a9d689 into d09f115
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavosobral committed Jun 18, 2018
2 parents d09f115 + 2a9d689 commit d5da1d0
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 44 deletions.
18 changes: 7 additions & 11 deletions lib/unsplash/category.rb
Expand Up @@ -7,31 +7,27 @@ class << self

# Get a list of all of the Unsplash photo categories.
# @return [Array] The list categories.
# <b>DEPRECATED</b>
def all
JSON.parse(connection.get("/categories/").body).map do |category|
new category
end
raise Unsplash::DeprecationError.new "Category has been deprecated and removed."
end

# Get an Unsplash Category.
# @param id [Integer] The ID of the category to retrieve.
# @return [Unsplash::Category] The specified category.
# <b>DEPRECATED</b>
def find(id)
new JSON.parse(connection.get("/categories/#{id}").body)
raise Unsplash::DeprecationError.new "Category has been deprecated and removed."
end
end

# Get a list of all photos in this category.
# @param page [Integer] Which page of search results to return.
# @param per_page [Integer] The number of search results per page.
# @return [Array] A single page of +Unsplash::Photo+s.
# <b>DEPRECATED</b>
def photos(page = 1, per_page = 10)
params = {
page: page,
per_page: per_page
}
list = JSON.parse(connection.get("/categories/#{id}/photos", params).body)
list.map { |photo| Unsplash::Photo.new photo }
raise Unsplash::DeprecationError.new "Category has been deprecated and removed."
end
end
end
end
2 changes: 1 addition & 1 deletion lib/unsplash/configuration.rb
Expand Up @@ -26,4 +26,4 @@ def application_id
end

end
end
end
2 changes: 1 addition & 1 deletion lib/unsplash/curated_batch.rb
Expand Up @@ -40,4 +40,4 @@ def photos
end

end
end
end
4 changes: 3 additions & 1 deletion lib/unsplash/errors.rb
@@ -1,4 +1,6 @@
module Unsplash # :nodoc:
# Raised when there is an error communicating with Unsplash.
class Error < StandardError; end
end
# Raise for deprecation errors
class DeprecationError < Error; end
end
2 changes: 1 addition & 1 deletion lib/unsplash/photo.rb
Expand Up @@ -128,7 +128,7 @@ def curated(page = 1, per_page = 10, order_by = "popular")
# @return [Unsplash::Photo] The uploaded photo.
# <b>DEPRECATED</b>
def create(filepath)
raise Unsplash::Error.new "API photo-upload endpoint has been deprecated and removed."
raise Unsplash::DeprecationError.new "API photo-upload endpoint has been deprecated and removed."
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/unsplash/stats.rb
Expand Up @@ -12,4 +12,4 @@ def total
end
end

end
end
37 changes: 13 additions & 24 deletions spec/lib/category_spec.rb
Expand Up @@ -3,45 +3,34 @@
describe Unsplash::Category do

let (:category_id) { 7 }
let (:fake_id) { 42 }

describe "#find" do
it "returns a Category object" do
VCR.use_cassette("categories") do
@category = Unsplash::Category.find(category_id)
end

expect(@category).to be_a Unsplash::Category
end

it "errors if the category doesn't exist" do
expect {
VCR.use_cassette("categories") do
@category = Unsplash::Category.find(fake_id)
@category = Unsplash::Category.find(category_id)
end
}.to raise_error Unsplash::Error
}.to raise_error Unsplash::DeprecationError
end
end

describe "#all" do
it "returns an array of Categories" do
VCR.use_cassette("categories") do
@categories = Unsplash::Category.all
end

expect(@categories).to be_an Array
expect(@categories.size).to eq 6
expect {
VCR.use_cassette("categories") do
@categories = Unsplash::Category.all
end
}.to raise_error Unsplash::DeprecationError
end
end

describe "#photos" do
it "returns an array of Photos" do
VCR.use_cassette("categories") do
@photos = Unsplash::Category.find(category_id).photos(1, 13)
end

expect(@photos).to be_an Array
expect(@photos.size).to eq 13
expect {
VCR.use_cassette("categories") do
@photos = Unsplash::Category.find(category_id).photos(1, 13)
end
}.to raise_error Unsplash::DeprecationError
end
end
end
end
1 change: 0 additions & 1 deletion spec/lib/connection_spec.rb
Expand Up @@ -111,4 +111,3 @@
end
end
end

2 changes: 1 addition & 1 deletion spec/lib/curated_batch_spec.rb
Expand Up @@ -61,4 +61,4 @@
expect(@photos.size).to eq 10
end
end
end
end
2 changes: 1 addition & 1 deletion spec/lib/photo_spec.rb
Expand Up @@ -195,7 +195,7 @@
VCR.use_cassette("photos", match_requests_on: [:method, :path, :body]) do
@photo = Unsplash::Photo.create "spec/support/upload-1.txt"
end
}.to raise_error Unsplash::Error
}.to raise_error Unsplash::DeprecationError
end

end
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/stats_spec.rb
Expand Up @@ -30,4 +30,4 @@
end
end

end
end

0 comments on commit d5da1d0

Please sign in to comment.