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, timeout: { open: nil, read: nil }) ⇒ Object (also: #find)
- #curated(per_page: 15, page: 1, timeout: { open: nil, read: nil }) ⇒ 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, timeout: { open: nil, read: 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, timeout: { open: nil, read: nil }) ⇒ Object Also known as: find
10 11 12 13 14 15 16 |
# File 'lib/pexels/client/photos.rb', line 10 def [](id, timeout: { open: nil, read: nil }) response = @client.request( "#{Pexels.api_version}/photos/#{id}", options: { open_timeout: timeout[:open], read_timeout: timeout[:read] } ) Pexels::Photo.new(response.body) end |
#curated(per_page: 15, page: 1, timeout: { open: nil, read: nil }) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/pexels/client/photos.rb', line 42 def curated(per_page: 15, page: 1, timeout: { open: nil, read: nil }) response = @client.request( "#{Pexels.api_version}/curated", params: { per_page: per_page, page: page }, options: { open_timeout: timeout[:open], read_timeout: timeout[:read] } ) Pexels::PhotoSet.new(response) end |
#search(query, per_page: 15, page: 1, locale: 'en-US', orientation: nil, size: nil, color: nil, timeout: { open: nil, read: nil }) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/pexels/client/photos.rb', line 19 def search(query, per_page: 15, page: 1, locale: 'en-US', orientation: nil, size: nil, color: nil, timeout: { open: nil, read: 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, options: { open_timeout: timeout[:open], read_timeout: timeout[:read] } ) Pexels::PhotoSet.new(response) end |