Skip to content

Commit

Permalink
Merge pull request #86 from jigar786/add-content-filter-for-photo-sea…
Browse files Browse the repository at this point in the history
…rch-and-random

Added content_filter for photo search and random
  • Loading branch information
arg authored Sep 19, 2023
2 parents 77db1e7 + ff94f9a commit 56d7ef4
Show file tree
Hide file tree
Showing 4 changed files with 1,077 additions and 42 deletions.
12 changes: 8 additions & 4 deletions lib/unsplash/photo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,19 @@ def find(id)
# @param user [String] Limit selection to given User's ID.
# @param query [String] Limit selection to given search query.
# @param orientation [String] Filter by orientation of the photo. Valid values are landscape, portrait, and squarish.
# @param content_filter [String] Limit results by content_filter to avoid content that may be unsuitable for younger audiences. Valid values are low, high. Defaults to low.
# @return [Unsplash::Photo] An Unsplash Photo if count parameter is omitted
# @return [Array] An array of Unsplash Photos if the count parameter is specified. An array is returned even if count is 1
def random(count: nil, collections: nil, featured: nil, user: nil, query: nil, orientation: nil)
def random(count: nil, collections: nil, featured: nil, user: nil, query: nil, orientation: nil, content_filter: "low")
Unsplash.configuration.logger.warn "You cannot combine 'collections' and 'query' parameters. 'query' will be ignored." if collections && query

params = {
collections: (collections && collections.join(",")),
featured: featured,
username: user,
query: query,
orientation: orientation
orientation: orientation,
content_filter: content_filter
}.select { |k,v| v }
if count
params[:count] = count
Expand All @@ -83,13 +85,15 @@ def random(count: nil, collections: nil, featured: nil, user: nil, query: nil, o
# @param page [Integer] Which page of search results to return.
# @param per_page [Integer] The number of users search result per page. (default: 10, maximum: 30)
# @param orientation [String] Filter by orientation of the photo. Valid values are landscape, portrait, and squarish.
# @param content_filter [String] Limit results by content_filter to avoid content that may be unsuitable for younger audiences. Valid values are low, high. Defaults to low.
# @return [SearchResult] a list of +Unsplash::Photo+ objects.
def search(query, page = 1, per_page = 10, orientation = nil)
def search(query, page = 1, per_page = 10, orientation = nil, content_filter = "low")
params = {
query: query,
page: page,
per_page: per_page,
orientation: orientation
orientation: orientation,
content_filter: content_filter
}.select { |_k, v| v }
Unsplash::Search.search("/search/photos", self, params)
end
Expand Down
Loading

0 comments on commit 56d7ef4

Please sign in to comment.