pexels 0.2.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGES.md +7 -0
- data/README.md +17 -0
- data/lib/pexels/client/collections.rb +25 -2
- data/lib/pexels/client/photos.rb +61 -32
- data/lib/pexels/client/request.rb +5 -3
- data/lib/pexels/client/search_filters.rb +31 -0
- data/lib/pexels/client/videos.rb +61 -31
- data/lib/pexels/client.rb +2 -2
- data/lib/pexels/photo.rb +3 -2
- data/lib/pexels/version.rb +1 -1
- data/lib/pexels.rb +1 -0
- data/test/collection_test.rb +71 -5
- data/test/photo_test.rb +87 -5
- data/test/video_test.rb +72 -5
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 640a858dfa54cf40bfa1b9130913504974db246d4725330534f1a332eb8031b5
|
4
|
+
data.tar.gz: c45f2aedd96b3a9cdee7b61fb284be1de7bb3f7210fab6673eedb5260e7ee507
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a118ea1244d6232d6737ec4fcfc9e7dbe342042bad0ffd1319a1174a920837c6a499c7f62f0138c6b29e494c49873cd503ca0722eecc218f27ec8c8db7964751
|
7
|
+
data.tar.gz: 8a75b15f26dde2b2146877c5b55471798985ea3caba5db14d5702e6fe14410366af2da7d808eecf26136f878627f8a156b54e41e5dcf64eed81256fa42c43b43
|
data/CHANGES.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
+
## 0.4.0
|
4
|
+
* Add support for returning featured collections.
|
5
|
+
|
6
|
+
## 0.3.0
|
7
|
+
* Add support for photo and video search with filters.
|
8
|
+
* Added `avg_color` attribute to `Photo` object.
|
9
|
+
|
3
10
|
## 0.2.1
|
4
11
|
* Added `type`, `photo?` and `video?` helper methods to `Photo` and `Video` classes.
|
5
12
|
|
data/README.md
CHANGED
@@ -30,6 +30,12 @@ client = Pexels::Client.new('your-access-key')
|
|
30
30
|
client.photos.search('Cloud')
|
31
31
|
```
|
32
32
|
|
33
|
+
### Search for photos with filters
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
client.photos.search('Dog', color: :yellow, size: :large, orientation: :square)
|
37
|
+
```
|
38
|
+
|
33
39
|
### Find a specific photo
|
34
40
|
|
35
41
|
```ruby
|
@@ -50,6 +56,12 @@ client.photos.curated
|
|
50
56
|
client.videos.search('waves')
|
51
57
|
```
|
52
58
|
|
59
|
+
### Search for videos with filters
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
client.videos.search('Beach', size: :medium, orientation: :landscape)
|
63
|
+
```
|
64
|
+
|
53
65
|
### Find a specific photo
|
54
66
|
|
55
67
|
```ruby
|
@@ -71,6 +83,11 @@ Note: this is limited to collections belonging to the API user.
|
|
71
83
|
```ruby
|
72
84
|
client.collections.all
|
73
85
|
```
|
86
|
+
### List all featured collections.
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
client.collections.featured.all
|
90
|
+
```
|
74
91
|
|
75
92
|
### Get all media for a collection
|
76
93
|
|
@@ -3,24 +3,47 @@ class Pexels::Client::Collections
|
|
3
3
|
@client = client
|
4
4
|
end
|
5
5
|
|
6
|
-
def all(per_page: 15, page: 1)
|
6
|
+
def all(per_page: 15, page: 1, timeout: { open: nil, read: nil })
|
7
7
|
response = @client.request(
|
8
8
|
"#{Pexels.api_version}/collections",
|
9
9
|
params: {
|
10
10
|
per_page: per_page,
|
11
11
|
page: page
|
12
|
+
},
|
13
|
+
options: {
|
14
|
+
open_timeout: timeout[:open],
|
15
|
+
read_timeout: timeout[:read]
|
12
16
|
})
|
13
17
|
|
14
18
|
Pexels::CollectionSet.new(response)
|
15
19
|
end
|
16
20
|
|
17
|
-
def
|
21
|
+
def featured(per_page: 15, page: 1, timeout: { open: nil, read: nil })
|
22
|
+
response = @client.request(
|
23
|
+
"#{Pexels.api_version}/collections/featured",
|
24
|
+
params: {
|
25
|
+
per_page: per_page,
|
26
|
+
page: page
|
27
|
+
},
|
28
|
+
options: {
|
29
|
+
open_timeout: timeout[:open],
|
30
|
+
read_timeout: timeout[:read]
|
31
|
+
})
|
32
|
+
|
33
|
+
Pexels::CollectionSet.new(response)
|
34
|
+
end
|
35
|
+
|
36
|
+
def [](id, type: nil, per_page: 15, page: 1, timeout: { open: nil, read: nil })
|
18
37
|
response = @client.request(
|
19
38
|
"#{Pexels.api_version}/collections/#{id}",
|
20
39
|
params: {
|
21
40
|
per_page: per_page,
|
22
41
|
page: page,
|
23
42
|
type: type
|
43
|
+
},
|
44
|
+
options: {
|
45
|
+
open_timeout: timeout[:open],
|
46
|
+
read_timeout: timeout[:read]
|
24
47
|
})
|
25
48
|
|
26
49
|
Pexels::CollectionMediaSet.new(response)
|
data/lib/pexels/client/photos.rb
CHANGED
@@ -1,38 +1,67 @@
|
|
1
|
-
|
1
|
+
module Pexels
|
2
|
+
class Client
|
3
|
+
class Photos
|
4
|
+
include SearchFilters
|
2
5
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
+
def initialize(client)
|
7
|
+
@client = client
|
8
|
+
end
|
6
9
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
10
|
+
def [](id, timeout: { open: nil, read: nil })
|
11
|
+
response = @client.request(
|
12
|
+
"#{Pexels.api_version}/photos/#{id}",
|
13
|
+
options: { open_timeout: timeout[:open], read_timeout: timeout[:read] }
|
14
|
+
)
|
15
|
+
Pexels::Photo.new(response.body)
|
16
|
+
end
|
17
|
+
alias_method :find, :[]
|
18
|
+
|
19
|
+
def search(query, per_page: 15, page: 1, locale: 'en-US', orientation: nil, size: nil, color: nil, timeout: { open: nil, read: nil })
|
20
|
+
validate_search_params(orientation, size, color)
|
21
|
+
|
22
|
+
response = @client.request(
|
23
|
+
"#{Pexels.api_version}/search",
|
24
|
+
params: {
|
25
|
+
query: query,
|
26
|
+
per_page: per_page,
|
27
|
+
page: page,
|
28
|
+
locale: locale,
|
29
|
+
orientation: orientation,
|
30
|
+
size: size,
|
31
|
+
color: color
|
32
|
+
}.compact,
|
33
|
+
options: {
|
34
|
+
open_timeout: timeout[:open],
|
35
|
+
read_timeout: timeout[:read]
|
36
|
+
}
|
37
|
+
)
|
38
|
+
|
39
|
+
Pexels::PhotoSet.new(response)
|
40
|
+
end
|
41
|
+
|
42
|
+
def curated(per_page: 15, page: 1, timeout: { open: nil, read: nil })
|
43
|
+
response = @client.request(
|
44
|
+
"#{Pexels.api_version}/curated",
|
45
|
+
params: {
|
46
|
+
per_page: per_page,
|
47
|
+
page: page
|
48
|
+
},
|
49
|
+
options: {
|
50
|
+
open_timeout: timeout[:open],
|
51
|
+
read_timeout: timeout[:read]
|
52
|
+
}
|
53
|
+
)
|
54
|
+
|
55
|
+
Pexels::PhotoSet.new(response)
|
56
|
+
end
|
26
57
|
|
27
|
-
|
28
|
-
response = @client.request(
|
29
|
-
"#{Pexels.api_version}/curated",
|
30
|
-
params: {
|
31
|
-
per_page: per_page,
|
32
|
-
page: page,
|
33
|
-
}
|
34
|
-
)
|
58
|
+
private
|
35
59
|
|
36
|
-
|
60
|
+
def validate_search_params(orientation, size, color)
|
61
|
+
validate_orientation(orientation) &&
|
62
|
+
validate_size(size) &&
|
63
|
+
validate_color(color)
|
64
|
+
end
|
65
|
+
end
|
37
66
|
end
|
38
67
|
end
|
@@ -3,13 +3,14 @@ require 'requests'
|
|
3
3
|
module Pexels
|
4
4
|
class Client
|
5
5
|
class Request
|
6
|
-
attr_reader :api_key, :path, :method, :params
|
6
|
+
attr_reader :api_key, :path, :method, :params, :options
|
7
7
|
|
8
|
-
def initialize(api_key, path, method, params)
|
8
|
+
def initialize(api_key, path, method, params, options)
|
9
9
|
@api_key = api_key
|
10
10
|
@path = path
|
11
11
|
@method = method
|
12
12
|
@params = params
|
13
|
+
@options = options
|
13
14
|
end
|
14
15
|
|
15
16
|
def call
|
@@ -28,7 +29,8 @@ module Pexels
|
|
28
29
|
method,
|
29
30
|
url,
|
30
31
|
params: params,
|
31
|
-
headers: headers
|
32
|
+
headers: headers,
|
33
|
+
options: options
|
32
34
|
)
|
33
35
|
end
|
34
36
|
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Pexels
|
2
|
+
class Client
|
3
|
+
module SearchFilters
|
4
|
+
ORIENTATIONS = %w(portrait landscape square).freeze
|
5
|
+
SIZES = %w(small medium large).freeze
|
6
|
+
COLORS = %w(red orange yellow green turquoise blue violet pink brown black gray white).freeze
|
7
|
+
|
8
|
+
def validate_orientation(orientation)
|
9
|
+
return true unless orientation
|
10
|
+
return true if ORIENTATIONS.include?(orientation.to_s)
|
11
|
+
|
12
|
+
raise ArgumentError, "`orientation` must be one of #{ORIENTATIONS.join(', ')}."
|
13
|
+
end
|
14
|
+
|
15
|
+
def validate_size(size)
|
16
|
+
return true unless size
|
17
|
+
return true if SIZES.include?(size.to_s)
|
18
|
+
|
19
|
+
raise ArgumentError, "`size` must be one of #{SIZES.join(', ')}."
|
20
|
+
end
|
21
|
+
|
22
|
+
def validate_color(color)
|
23
|
+
return true unless color
|
24
|
+
return true if COLORS.include?(color.to_s)
|
25
|
+
return true if color.to_s =~ /\A#?(?:[0-9a-f]{3}){1,2}\z/i
|
26
|
+
|
27
|
+
raise ArgumentError, "`color` must be one of #{COLORS.join(', ')} or a valid hex code."
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/pexels/client/videos.rb
CHANGED
@@ -1,37 +1,67 @@
|
|
1
|
-
|
1
|
+
module Pexels
|
2
|
+
class Client
|
3
|
+
class Videos
|
4
|
+
include SearchFilters
|
2
5
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
+
def initialize(client)
|
7
|
+
@client = client
|
8
|
+
end
|
6
9
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
10
|
+
def [](id, timeout: { open: nil, read: nil })
|
11
|
+
response = @client.request(
|
12
|
+
"/videos/videos/#{id}",
|
13
|
+
options: {
|
14
|
+
open_timeout: timeout[:open],
|
15
|
+
read_timeout: timeout[:read]
|
16
|
+
}
|
17
|
+
)
|
18
|
+
Pexels::Video.new(response.body)
|
19
|
+
end
|
20
|
+
alias_method :find, :[]
|
21
|
+
|
22
|
+
def search(query, per_page: 15, page: 1, orientation: nil, size: nil, timeout: { open: nil, read: nil })
|
23
|
+
validate_search_params(orientation, size)
|
24
|
+
|
25
|
+
response = @client.request(
|
26
|
+
'/videos/search',
|
27
|
+
params: {
|
28
|
+
query: query,
|
29
|
+
per_page: per_page,
|
30
|
+
page: page,
|
31
|
+
orientation: orientation,
|
32
|
+
size: size
|
33
|
+
}.compact,
|
34
|
+
options: {
|
35
|
+
open_timeout: timeout[:open],
|
36
|
+
read_timeout: timeout[:read]
|
37
|
+
}
|
38
|
+
)
|
39
|
+
|
40
|
+
Pexels::VideoSet.new(response)
|
41
|
+
end
|
42
|
+
|
43
|
+
def popular(per_page: 15, page: 1, timeout: { open: nil, read: nil })
|
44
|
+
response = @client.request(
|
45
|
+
'/videos/popular',
|
46
|
+
params: {
|
47
|
+
per_page: per_page,
|
48
|
+
page: page
|
49
|
+
},
|
50
|
+
options: {
|
51
|
+
open_timeout: timeout[:open],
|
52
|
+
read_timeout: timeout[:read]
|
53
|
+
}
|
54
|
+
)
|
55
|
+
|
56
|
+
Pexels::VideoSet.new(response)
|
57
|
+
end
|
25
58
|
|
26
|
-
|
27
|
-
response = @client.request(
|
28
|
-
'/videos/popular',
|
29
|
-
params: {
|
30
|
-
per_page: per_page,
|
31
|
-
page: page,
|
32
|
-
}
|
33
|
-
)
|
59
|
+
private
|
34
60
|
|
35
|
-
|
61
|
+
def validate_search_params(orientation, size)
|
62
|
+
validate_orientation(orientation) &&
|
63
|
+
validate_size(size)
|
64
|
+
end
|
65
|
+
end
|
36
66
|
end
|
37
67
|
end
|
data/lib/pexels/client.rb
CHANGED
@@ -19,8 +19,8 @@ module Pexels
|
|
19
19
|
@collections ||= Pexels::Client::Collections.new(self)
|
20
20
|
end
|
21
21
|
|
22
|
-
def request(path, method: 'GET', params: {})
|
23
|
-
request = Request.new(api_key, path, method, params)
|
22
|
+
def request(path, method: 'GET', params: {}, options: {})
|
23
|
+
request = Request.new(api_key, path, method, params, options)
|
24
24
|
request.call.tap do |response|
|
25
25
|
@ratelimit_remaining = response.ratelimit_remaining
|
26
26
|
end
|
data/lib/pexels/photo.rb
CHANGED
@@ -4,8 +4,8 @@ class Pexels::Photo
|
|
4
4
|
:height,
|
5
5
|
:url,
|
6
6
|
:user,
|
7
|
-
:src
|
8
|
-
|
7
|
+
:src,
|
8
|
+
:avg_color
|
9
9
|
|
10
10
|
def initialize(attrs)
|
11
11
|
@id = attrs.fetch('id')
|
@@ -18,6 +18,7 @@ class Pexels::Photo
|
|
18
18
|
url: attrs.fetch('photographer_url')
|
19
19
|
)
|
20
20
|
@src = attrs.fetch('src')
|
21
|
+
@avg_color = attrs.fetch('avg_color')
|
21
22
|
|
22
23
|
rescue KeyError => exception
|
23
24
|
raise Pexels::MalformedAPIResponseError.new(exception)
|
data/lib/pexels/version.rb
CHANGED
data/lib/pexels.rb
CHANGED
@@ -25,6 +25,7 @@ end
|
|
25
25
|
require_relative 'pexels/client'
|
26
26
|
require_relative 'pexels/client/request'
|
27
27
|
require_relative 'pexels/client/response'
|
28
|
+
require_relative 'pexels/client/search_filters'
|
28
29
|
require_relative 'pexels/client/collections'
|
29
30
|
require_relative 'pexels/client/photos'
|
30
31
|
require_relative 'pexels/client/videos'
|
data/test/collection_test.rb
CHANGED
@@ -27,6 +27,25 @@ class TestCollections < Minitest::Test
|
|
27
27
|
assert_kind_of Pexels::CollectionSet, collection_with_params.prev_page
|
28
28
|
end
|
29
29
|
|
30
|
+
def test_featured
|
31
|
+
collection = @client.collections.featured
|
32
|
+
|
33
|
+
assert_kind_of Pexels::CollectionSet, collection
|
34
|
+
assert_equal collection.per_page, 15
|
35
|
+
assert_equal collection.page, 1
|
36
|
+
|
37
|
+
assert collection.collections.is_a? Array
|
38
|
+
assert collection.collections.any?
|
39
|
+
assert collection.first.is_a? Pexels::Collection
|
40
|
+
|
41
|
+
collection_with_params = @client.collections.featured(per_page: 1, page: 2)
|
42
|
+
assert_equal collection_with_params.per_page, 1
|
43
|
+
assert_equal collection_with_params.page, 2
|
44
|
+
assert_equal collection_with_params.collections.length, 1
|
45
|
+
assert_kind_of Pexels::CollectionSet, collection_with_params.next_page
|
46
|
+
assert_kind_of Pexels::CollectionSet, collection_with_params.prev_page
|
47
|
+
end
|
48
|
+
|
30
49
|
def test_get_collection_media
|
31
50
|
collection = @client.collections[@collection.id]
|
32
51
|
assert_kind_of Pexels::CollectionMediaSet, collection
|
@@ -74,10 +93,57 @@ class TestCollections < Minitest::Test
|
|
74
93
|
end
|
75
94
|
|
76
95
|
def test_invalid_get_collection
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
assert
|
81
|
-
|
96
|
+
error = assert_raises(Pexels::APIError) do
|
97
|
+
@client.collections['this-is-not-a-valid-id']
|
98
|
+
end
|
99
|
+
assert error.message, 'Not Found'
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_get_collection_open_timeout
|
103
|
+
error = assert_raises Pexels::APIError do
|
104
|
+
@client.collections[@collection.id, timeout: { open: 0.0000001 }]
|
105
|
+
end
|
106
|
+
|
107
|
+
assert_equal 'execution expired', error.message
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_get_collection_read_timeout
|
111
|
+
error = assert_raises Pexels::APIError do
|
112
|
+
@client.collections[@collection.id, timeout: { read: 0.0000001 }]
|
113
|
+
end
|
114
|
+
|
115
|
+
assert_equal 'Net::ReadTimeout', error.message
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_all_open_timeout
|
119
|
+
error = assert_raises Pexels::APIError do
|
120
|
+
@client.collections.all(timeout: { open: 0.0000001 })
|
121
|
+
end
|
122
|
+
|
123
|
+
assert_equal 'execution expired', error.message
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_all_read_timeout
|
127
|
+
error = assert_raises Pexels::APIError do
|
128
|
+
@client.collections.all(timeout: { read: 0.0000001 })
|
129
|
+
end
|
130
|
+
|
131
|
+
assert_equal 'Net::ReadTimeout', error.message
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_featured_open_timeout
|
135
|
+
error = assert_raises Pexels::APIError do
|
136
|
+
@client.collections.featured(timeout: { open: 0.0000001 })
|
137
|
+
end
|
138
|
+
|
139
|
+
assert_equal 'execution expired', error.message
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_featured_read_timeout
|
143
|
+
error = assert_raises Pexels::APIError do
|
144
|
+
@client.collections.featured(timeout: { read: 0.0000001 })
|
145
|
+
end
|
146
|
+
|
147
|
+
assert_equal 'Net::ReadTimeout', error.message
|
82
148
|
end
|
83
149
|
end
|
data/test/photo_test.rb
CHANGED
@@ -60,6 +60,7 @@ class TestPhoto < Minitest::Test
|
|
60
60
|
assert_equal photo.user.url, @photo.user.url
|
61
61
|
assert_equal photo.user.id, @photo.user.id
|
62
62
|
assert_equal photo.src, @photo.src
|
63
|
+
assert_equal photo.avg_color, @photo.avg_color
|
63
64
|
|
64
65
|
assert photo.photo?
|
65
66
|
assert_equal photo.type, 'Photo'
|
@@ -67,10 +68,91 @@ class TestPhoto < Minitest::Test
|
|
67
68
|
end
|
68
69
|
|
69
70
|
def test_invalid_get_photo
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
71
|
+
error = assert_raises(Pexels::APIError) do
|
72
|
+
@client.photos['this-is-not-a-valid-id']
|
73
|
+
end
|
74
|
+
assert_equal 'Not Found', error.message
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_invalid_orientation
|
78
|
+
error = assert_raises(ArgumentError) do
|
79
|
+
@client.photos.search('dog', orientation: 'foo')
|
80
|
+
end
|
81
|
+
assert_match '`orientation` must be one of', error.message
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_invalid_size
|
85
|
+
error = assert_raises(ArgumentError) do
|
86
|
+
@client.photos.search('dog', size: 'foo')
|
87
|
+
end
|
88
|
+
assert_match '`size` must be one of', error.message
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_invalid_color
|
92
|
+
error = assert_raises(ArgumentError) do
|
93
|
+
@client.photos.search('dog', color: 'foo')
|
94
|
+
end
|
95
|
+
assert_match '`color` must be one of', error.message
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_invalid_color_hex
|
99
|
+
error = assert_raises(ArgumentError) do
|
100
|
+
@client.photos.search('dog', color: '#gggggg')
|
101
|
+
end
|
102
|
+
assert_match '`color` must be one of', error.message
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_search_filters
|
106
|
+
search_result = @client.photos.search('dog', color: '#FF0000', size: :large, orientation: :square)
|
107
|
+
assert_kind_of Pexels::PhotoSet, search_result
|
108
|
+
assert search_result.photos.any?
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_get_photo_open_timeout
|
112
|
+
error = assert_raises Pexels::APIError do
|
113
|
+
@client.photos[@photo.id, timeout: { open: 0.0000001 }]
|
114
|
+
end
|
115
|
+
|
116
|
+
assert_equal 'execution expired', error.message
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_get_photo_read_timeout
|
120
|
+
error = assert_raises Pexels::APIError do
|
121
|
+
@client.photos[@photo.id, timeout: { read: 0.0000001 }]
|
122
|
+
end
|
123
|
+
|
124
|
+
assert_equal 'Net::ReadTimeout', error.message
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_search_open_timeout
|
128
|
+
error = assert_raises Pexels::APIError do
|
129
|
+
@client.photos.search('test', timeout: { open: 0.0000001 })
|
130
|
+
end
|
131
|
+
|
132
|
+
assert_equal 'execution expired', error.message
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_search_read_timeout
|
136
|
+
error = assert_raises Pexels::APIError do
|
137
|
+
@client.photos.search('test', timeout: { read: 0.0000001 })
|
138
|
+
end
|
139
|
+
|
140
|
+
assert_equal 'Net::ReadTimeout', error.message
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_curated_open_timeout
|
144
|
+
error = assert_raises Pexels::APIError do
|
145
|
+
@client.photos.curated(timeout: { open: 0.0000001 })
|
146
|
+
end
|
147
|
+
|
148
|
+
assert_equal 'execution expired', error.message
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_curated_read_timeout
|
152
|
+
error = assert_raises Pexels::APIError do
|
153
|
+
@client.photos.curated(timeout: { read: 0.0000001 })
|
154
|
+
end
|
155
|
+
|
156
|
+
assert_equal 'Net::ReadTimeout', error.message
|
75
157
|
end
|
76
158
|
end
|
data/test/video_test.rb
CHANGED
@@ -74,10 +74,77 @@ class TestVideo < Minitest::Test
|
|
74
74
|
end
|
75
75
|
|
76
76
|
def test_invalid_get_video
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
77
|
+
error = assert_raises(Pexels::APIError) do
|
78
|
+
@client.videos['this-is-not-a-valid-id']
|
79
|
+
end
|
80
|
+
assert_equal 'Not Found', error.message
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_invalid_orientation
|
84
|
+
error = assert_raises(ArgumentError) do
|
85
|
+
@client.photos.search('dog', orientation: 'foo')
|
86
|
+
end
|
87
|
+
assert_match '`orientation` must be one of', error.message
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_invalid_size
|
91
|
+
error = assert_raises(ArgumentError) do
|
92
|
+
@client.photos.search('dog', size: 'foo')
|
93
|
+
end
|
94
|
+
assert_match '`size` must be one of', error.message
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_search_filters
|
98
|
+
search_result = @client.videos.search('cat', size: :medium, orientation: :square)
|
99
|
+
assert_kind_of Pexels::VideoSet, search_result
|
100
|
+
assert search_result.videos.any?
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_get_video_open_timeout
|
104
|
+
error = assert_raises Pexels::APIError do
|
105
|
+
@client.videos[@video.id, timeout: { open: 0.0000001 }]
|
106
|
+
end
|
107
|
+
|
108
|
+
assert_equal 'execution expired', error.message
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_get_video_read_timeout
|
112
|
+
error = assert_raises Pexels::APIError do
|
113
|
+
@client.videos[@video.id, timeout: { read: 0.0000001 }]
|
114
|
+
end
|
115
|
+
|
116
|
+
assert_equal 'Net::ReadTimeout', error.message
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_search_open_timeout
|
120
|
+
error = assert_raises Pexels::APIError do
|
121
|
+
@client.videos.search('cat', timeout: { open: 0.0000001 })
|
122
|
+
end
|
123
|
+
|
124
|
+
assert_equal 'execution expired', error.message
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_search_read_timeout
|
128
|
+
error = assert_raises Pexels::APIError do
|
129
|
+
@client.videos.search('cat', timeout: { read: 0.0000001 })
|
130
|
+
end
|
131
|
+
|
132
|
+
assert_equal 'Net::ReadTimeout', error.message
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_featured_open_timeout
|
136
|
+
error = assert_raises Pexels::APIError do
|
137
|
+
@client.videos.popular(timeout: { open: 0.0000001 })
|
138
|
+
end
|
139
|
+
|
140
|
+
assert_equal 'execution expired', error.message
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_featured_read_timeout
|
144
|
+
error = assert_raises Pexels::APIError do
|
145
|
+
@client.videos.popular(timeout: { read: 0.0000001 })
|
146
|
+
end
|
147
|
+
|
148
|
+
assert_equal 'Net::ReadTimeout', error.message
|
82
149
|
end
|
83
150
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pexels
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pexels dev team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: requests
|
@@ -44,6 +44,7 @@ files:
|
|
44
44
|
- lib/pexels/client/photos.rb
|
45
45
|
- lib/pexels/client/request.rb
|
46
46
|
- lib/pexels/client/response.rb
|
47
|
+
- lib/pexels/client/search_filters.rb
|
47
48
|
- lib/pexels/client/videos.rb
|
48
49
|
- lib/pexels/collection.rb
|
49
50
|
- lib/pexels/collection_media_set.rb
|
@@ -82,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
83
|
- !ruby/object:Gem::Version
|
83
84
|
version: '0'
|
84
85
|
requirements: []
|
85
|
-
rubygems_version: 3.0.3
|
86
|
+
rubygems_version: 3.0.3.1
|
86
87
|
signing_key:
|
87
88
|
specification_version: 4
|
88
89
|
summary: A simple Ruby wrapper for the Pexels API
|