Class: Pexels::Client::Photos
- Inherits:
-
Object
- Object
- Pexels::Client::Photos
- Includes:
- SearchFilters
- Defined in:
- lib/pexels/client/photos.rb
Constant Summary
Constants included from SearchFilters
SearchFilters::COLORS, SearchFilters::ORIENTATIONS, SearchFilters::SIZES
Instance Method Summary collapse
- #[](id) ⇒ Object (also: #find)
- #curated(per_page: 15, page: 1) ⇒ Object
-
#initialize(client) ⇒ Photos
constructor
A new instance of Photos.
- #search(query, per_page: 15, page: 1, locale: 'en-US', orientation: nil, size: nil, color: nil) ⇒ Object
Methods included from SearchFilters
#validate_color, #validate_orientation, #validate_size
Constructor Details
#initialize(client) ⇒ Photos
Returns a new instance of Photos.
6 7 8 |
# File 'lib/pexels/client/photos.rb', line 6 def initialize(client) @client = client end |
Instance Method Details
#[](id) ⇒ Object Also known as: find
10 11 12 13 |
# File 'lib/pexels/client/photos.rb', line 10 def [](id) response = @client.request("#{Pexels.api_version}/photos/#{id}") Pexels::Photo.new(response.body) end |
#curated(per_page: 15, page: 1) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/pexels/client/photos.rb', line 35 def curated(per_page: 15, page: 1) response = @client.request( "#{Pexels.api_version}/curated", params: { per_page: per_page, page: page } ) Pexels::PhotoSet.new(response) end |
#search(query, per_page: 15, page: 1, locale: 'en-US', orientation: nil, size: nil, color: nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/pexels/client/photos.rb', line 16 def search(query, per_page: 15, page: 1, locale: 'en-US', orientation: nil, size: nil, color: nil) validate_search_params(orientation, size, color) response = @client.request( "#{Pexels.api_version}/search", params: { query: query, per_page: per_page, page: page, locale: locale, orientation: orientation, size: size, color: color }.compact ) Pexels::PhotoSet.new(response) end |