Class: Pexels::Client::Videos

Inherits:
Object
  • Object
show all
Includes:
SearchFilters
Defined in:
lib/pexels/client/videos.rb

Constant Summary

Constants included from SearchFilters

SearchFilters::COLORS, SearchFilters::ORIENTATIONS, SearchFilters::SIZES

Instance Method Summary collapse

Methods included from SearchFilters

#validate_color, #validate_orientation, #validate_size

Constructor Details

#initialize(client) ⇒ Videos

Returns a new instance of Videos.



6
7
8
# File 'lib/pexels/client/videos.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
17
18
19
# File 'lib/pexels/client/videos.rb', line 10

def [](id, timeout: { open: nil, read: nil })
  response = @client.request(
    "/videos/videos/#{id}",
    options: {
      open_timeout: timeout[:open],
      read_timeout: timeout[:read]
    }
  )
  Pexels::Video.new(response.body)
end


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/pexels/client/videos.rb', line 43

def popular(per_page: 15, page: 1, timeout: { open: nil, read: nil })
  response = @client.request(
    '/videos/popular',
    params: {
      per_page: per_page,
      page: page
    },
    options: {
      open_timeout: timeout[:open],
      read_timeout: timeout[:read]
    }
  )

  Pexels::VideoSet.new(response)
end

#search(query, per_page: 15, page: 1, orientation: nil, size: nil, timeout: { open: nil, read: nil }) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/pexels/client/videos.rb', line 22

def search(query, per_page: 15, page: 1, orientation: nil, size: nil, timeout: { open: nil, read: nil })
  validate_search_params(orientation, size)

  response = @client.request(
    '/videos/search',
    params: {
      query: query,
      per_page: per_page,
      page: page,
      orientation: orientation,
      size: size
    }.compact,
    options: {
      open_timeout: timeout[:open],
      read_timeout: timeout[:read]
    }
  )

  Pexels::VideoSet.new(response)
end