class Unsplash::User

Unsplash User operations.

Public Class Methods

current() click to toggle source

Get the currently-logged in user. @return [Unsplash::User] the current user.

# File lib/unsplash/user.rb, line 17
def current
  new JSON.parse(connection.get("/me").body)
end
find(username) click to toggle source

Get a user. @param username [String] the username of the user to retrieve. @return [Unsplash::User] the Unsplash User.

# File lib/unsplash/user.rb, line 11
def find(username)
  new JSON.parse(connection.get("/users/#{username}").body)
end
update_current(params) click to toggle source

Update the current user. @param params [Hash] the hash of attributes to update. @return [Unsplash::User] the updated user.

# File lib/unsplash/user.rb, line 24
def update_current(params)
  Unsplash::User.new JSON.parse(connection.put("/me", params).body)
end

Public Instance Methods

collections(page = 1, per_page = 10) click to toggle source

Get a list of collections created by the user. @param page [Integer] Which page of results to return. @param per_page [Integer] The number of results per page. (default: 10, maximum: 30) @return [Array] a list of Unsplash::Collection objects.

# File lib/unsplash/user.rb, line 80
def collections(page = 1, per_page = 10)
  params = {
    page:     page,
    per_page: per_page
  }

  list = JSON.parse(connection.get("/users/#{username}/collections", params).body)
  list.map do |collection|
    Unsplash::Collection.new collection.to_hash
  end
end
likes(page = 1, per_page = 10) click to toggle source

Get a list of photos liked by the user. @param page [Integer] Which page of results to return. @param per_page [Integer] The number of results per page. (default: 10, maximum: 30) @return [Array] a list of Unsplash::Photo objects.

# File lib/unsplash/user.rb, line 64
def likes(page = 1, per_page = 10)
  params = {
    page:     page,
    per_page: per_page
  }

  list = JSON.parse(connection.get("/users/#{username}/likes", params).body)
  list.map do |photo|
    Unsplash::Photo.new photo.to_hash
  end
end
photos(page = 1, per_page = 10) click to toggle source

Get a list of photos uploaded by the user. @param page [Integer] Which page of results to return. @param per_page [Integer] The number of results per page. @return [Array] a list of Unsplash::Photo objects.

# File lib/unsplash/user.rb, line 48
def photos(page = 1, per_page = 10)
  params = {
    page:     page,
    per_page: per_page
  }

  list = JSON.parse(connection.get("/users/#{username}/photos", params).body)
  list.map do |photo|
    Unsplash::Photo.new photo.to_hash
  end
end