Class: Unsplash::User
Overview
Unsplash User operations.
Class Method Summary collapse
-
.current ⇒ Unsplash::User
Get the currently-logged in user.
-
.find(username) ⇒ Unsplash::User
Get a user.
-
.search(query, page = 1, per_page = 10) ⇒ Array
Get a single page of user results for a query.
-
.update_current(params) ⇒ Unsplash::User
Update the current user.
Instance Method Summary collapse
-
#collections(page = 1, per_page = 10) ⇒ Array
Get a list of collections created by the user.
-
#likes(page = 1, per_page = 10) ⇒ Array
Get a list of photos liked by the user.
-
#photos(page = 1, per_page = 10) ⇒ Array
Get a list of photos uploaded by the user.
Methods inherited from Client
#connection, connection, connection=, #initialize, #reload!, #to_h
Constructor Details
This class inherits a constructor from Unsplash::Client
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Unsplash::Client
Class Method Details
.current ⇒ Unsplash::User
Get the currently-logged in user.
17 18 19 |
# File 'lib/unsplash/user.rb', line 17 def current new JSON.parse(connection.get("/me").body) end |
.find(username) ⇒ Unsplash::User
Get a user.
11 12 13 |
# File 'lib/unsplash/user.rb', line 11 def find(username) new JSON.parse(connection.get("/users/#{username}").body) end |
.search(query, page = 1, per_page = 10) ⇒ Array
Get a single page of user results for a query.
33 34 35 36 37 38 39 40 |
# File 'lib/unsplash/user.rb', line 33 def search(query, page = 1, per_page = 10) params = { query: query, page: page, per_page: per_page } Unsplash::Search.search("/search/users", self, params) end |
.update_current(params) ⇒ Unsplash::User
Update the current user.
24 25 26 |
# File 'lib/unsplash/user.rb', line 24 def update_current(params) Unsplash::User.new JSON.parse(connection.put("/me", params).body) end |
Instance Method Details
#collections(page = 1, per_page = 10) ⇒ Array
Get a list of collections created by the user.
80 81 82 83 84 85 86 87 88 89 90 |
# 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) ⇒ Array
Get a list of photos liked by the user.
64 65 66 67 68 69 70 71 72 73 74 |
# 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) ⇒ Array
Get a list of photos uploaded by the user.
48 49 50 51 52 53 54 55 56 57 58 |
# 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 |