Sha256: c450e5950cbed6cdb71f7c63d8a31c76a11e4bd3d6820cfc022e0e326ee236d4

Contents?: true

Size: 1.33 KB

Versions: 2

Compression:

Stored size: 1.33 KB

Contents

module Unsplash # nodoc:

  # Unsplash User operations.
  class User < Client

    class << self

      # Get a user.
      # @param username [String] the username of the user to retrieve.
      # @return [Unsplash::User] the Unsplash User.
      def find(username)
        new JSON.parse(connection.get("/users/#{username}").body)
      end

      # Get the currently-logged in user.
      # @return [Unsplash::User] the current user.
      def current
        new JSON.parse(connection.get("/me").body)
      end

      # Update the current user.
      # @param params [Hash] the hash of attributes to update.
      # @return [Unsplash::User] the updated user.
      def update_current(params)
        Unsplash::User.new JSON.parse(connection.put("/me", params).body)
      end

    end

    # Get a list of photos uploaded by the user.
    # @return [Array] a list of +Unsplash::Photo+ objects. 
    def photos
      list = JSON.parse(connection.get("/users/#{username}/photos").body)
      list.map do |photo|
        Unsplash::Photo.new photo.to_hash
      end
    end

    # Get a list of photos liked by the user.
    # @return [Array] a list of +Unsplash::Photo+ objects. 
    def likes
      list = JSON.parse(connection.get("/users/#{username}/likes").body)
      list.map do |photo|
        Unsplash::Photo.new photo.to_hash
      end
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
unsplash-1.2.1 lib/unsplash/user.rb
unsplash-1.2.0 lib/unsplash/user.rb