Sha256: 030e07775e772273fd67d6d6c8f54f8854ab0e81a4cd2ac598459a358ce8c39c

Contents?: true

Size: 1.06 KB

Versions: 4

Compression:

Stored size: 1.06 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

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
unsplash-1.1.0 lib/unsplash/user.rb
unsplash-1.0.0 lib/unsplash/user.rb
unsplash-1.0.0.pre.rc.2 lib/unsplash/user.rb
unsplash-1.0.0.pre.rc.1 lib/unsplash/user.rb