lib/unsplash/photo.rb in unsplash-2.0.1 vs lib/unsplash/photo.rb in unsplash-2.1.0
- old
+ new
@@ -1,10 +1,15 @@
module Unsplash # :nodoc:
# Unsplash Photo operations.
class Photo < Client
+ def initialize(attrs)
+ super
+ add_utm_to_urls
+ end
+
# Like a photo for the current user.
# @return [Boolean] True if successful. Will raise on error.
def like!
connection.post("/photos/#{id}/like")
true
@@ -21,10 +26,16 @@
# @return [String] URL of image file for download.
def track_download
connection.get(links.download_location)["url"]
end
+ def add_utm_to_urls
+ (@attributes["urls"] || {}).each do |key, url|
+ @attributes["urls"][key] = add_utm_params(url)
+ end
+ end
+
class << self
# Get a photo. Can be cropped or resized using the optional parameters.
# @param id [String] The ID of the photo to retrieve.
# @return [Unsplash::Photo] The Unsplash Photo.
@@ -33,19 +44,21 @@
photo.user = Unsplash::User.new photo.user
photo
end
# Get a random photo or set of photos. The photo selection pool can be narrowed using
- # a combination of optional parameters. Can also optionally specify a custom image size.
+ # a combination of optional parameters.
# @param count [Integer] Number of photos required. Default=1, Max=30
# @param featured [Boolean] Limit selection to featured photos.
# @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.
# @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)
+ 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,
@@ -98,9 +111,8 @@
private
def parse_list(json)
JSON.parse(json).map { |photo| new photo }
end
-
end
end
end