pexels 0.4.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e749787cf73bb5029e528f9d0232d2ce6c638dc81d13c12c7e91346b8962b2be
4
- data.tar.gz: a531ae402dc483373295381e4fe613e0a169b813081a3964692b81d5af9bbaa4
3
+ metadata.gz: 640a858dfa54cf40bfa1b9130913504974db246d4725330534f1a332eb8031b5
4
+ data.tar.gz: c45f2aedd96b3a9cdee7b61fb284be1de7bb3f7210fab6673eedb5260e7ee507
5
5
  SHA512:
6
- metadata.gz: ad853babd229b319f25253cf036d8fd97b7c9262de26566d36d7fec7ddd4d7a2240038b200f4fca0551e30608038c4de6cc6844594cc3c8720368d26dd49a7e6
7
- data.tar.gz: aeda8080d6ad67c5aa1175081481337a2be0e7f1ed46619f2e5ccbee2944297b83aa7d3e4bae0df8949a04d80356a2e01f325dc539b874d6fa29e9b64f9e8906
6
+ metadata.gz: a118ea1244d6232d6737ec4fcfc9e7dbe342042bad0ffd1319a1174a920837c6a499c7f62f0138c6b29e494c49873cd503ca0722eecc218f27ec8c8db7964751
7
+ data.tar.gz: 8a75b15f26dde2b2146877c5b55471798985ea3caba5db14d5702e6fe14410366af2da7d808eecf26136f878627f8a156b54e41e5dcf64eed81256fa42c43b43
@@ -3,35 +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 featured(per_page: 15, page: 1)
21
+ def featured(per_page: 15, page: 1, timeout: { open: nil, read: nil })
18
22
  response = @client.request(
19
23
  "#{Pexels.api_version}/collections/featured",
20
24
  params: {
21
25
  per_page: per_page,
22
26
  page: page
27
+ },
28
+ options: {
29
+ open_timeout: timeout[:open],
30
+ read_timeout: timeout[:read]
23
31
  })
24
32
 
25
33
  Pexels::CollectionSet.new(response)
26
34
  end
27
35
 
28
- def [](id, type: nil, per_page: 15, page: 1)
36
+ def [](id, type: nil, per_page: 15, page: 1, timeout: { open: nil, read: nil })
29
37
  response = @client.request(
30
38
  "#{Pexels.api_version}/collections/#{id}",
31
39
  params: {
32
40
  per_page: per_page,
33
41
  page: page,
34
42
  type: type
43
+ },
44
+ options: {
45
+ open_timeout: timeout[:open],
46
+ read_timeout: timeout[:read]
35
47
  })
36
48
 
37
49
  Pexels::CollectionMediaSet.new(response)
@@ -7,13 +7,16 @@ module Pexels
7
7
  @client = client
8
8
  end
9
9
 
10
- def [](id)
11
- response = @client.request("#{Pexels.api_version}/photos/#{id}")
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
+ )
12
15
  Pexels::Photo.new(response.body)
13
16
  end
14
17
  alias_method :find, :[]
15
18
 
16
- def search(query, per_page: 15, page: 1, locale: 'en-US', orientation: nil, size: nil, color: nil)
19
+ def search(query, per_page: 15, page: 1, locale: 'en-US', orientation: nil, size: nil, color: nil, timeout: { open: nil, read: nil })
17
20
  validate_search_params(orientation, size, color)
18
21
 
19
22
  response = @client.request(
@@ -26,18 +29,26 @@ module Pexels
26
29
  orientation: orientation,
27
30
  size: size,
28
31
  color: color
29
- }.compact
32
+ }.compact,
33
+ options: {
34
+ open_timeout: timeout[:open],
35
+ read_timeout: timeout[:read]
36
+ }
30
37
  )
31
38
 
32
39
  Pexels::PhotoSet.new(response)
33
40
  end
34
41
 
35
- def curated(per_page: 15, page: 1)
42
+ def curated(per_page: 15, page: 1, timeout: { open: nil, read: nil })
36
43
  response = @client.request(
37
44
  "#{Pexels.api_version}/curated",
38
45
  params: {
39
46
  per_page: per_page,
40
47
  page: page
48
+ },
49
+ options: {
50
+ open_timeout: timeout[:open],
51
+ read_timeout: timeout[:read]
41
52
  }
42
53
  )
43
54
 
@@ -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
 
@@ -7,13 +7,19 @@ module Pexels
7
7
  @client = client
8
8
  end
9
9
 
10
- def [](id)
11
- response = @client.request("/videos/videos/#{id}")
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
+ )
12
18
  Pexels::Video.new(response.body)
13
19
  end
14
20
  alias_method :find, :[]
15
21
 
16
- def search(query, per_page: 15, page: 1, orientation: nil, size: nil)
22
+ def search(query, per_page: 15, page: 1, orientation: nil, size: nil, timeout: { open: nil, read: nil })
17
23
  validate_search_params(orientation, size)
18
24
 
19
25
  response = @client.request(
@@ -24,18 +30,26 @@ module Pexels
24
30
  page: page,
25
31
  orientation: orientation,
26
32
  size: size
27
- }.compact
33
+ }.compact,
34
+ options: {
35
+ open_timeout: timeout[:open],
36
+ read_timeout: timeout[:read]
37
+ }
28
38
  )
29
39
 
30
40
  Pexels::VideoSet.new(response)
31
41
  end
32
42
 
33
- def popular(per_page: 15, page: 1)
43
+ def popular(per_page: 15, page: 1, timeout: { open: nil, read: nil })
34
44
  response = @client.request(
35
45
  '/videos/popular',
36
46
  params: {
37
47
  per_page: per_page,
38
- page: page,
48
+ page: page
49
+ },
50
+ options: {
51
+ open_timeout: timeout[:open],
52
+ read_timeout: timeout[:read]
39
53
  }
40
54
  )
41
55
 
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
@@ -1,3 +1,3 @@
1
1
  module Pexels
2
- VERSION = '0.4.0'
2
+ VERSION = '0.5.0'
3
3
  end
@@ -98,4 +98,52 @@ class TestCollections < Minitest::Test
98
98
  end
99
99
  assert error.message, 'Not Found'
100
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
148
+ end
101
149
  end
data/test/photo_test.rb CHANGED
@@ -107,4 +107,52 @@ class TestPhoto < Minitest::Test
107
107
  assert_kind_of Pexels::PhotoSet, search_result
108
108
  assert search_result.photos.any?
109
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
157
+ end
110
158
  end
data/test/video_test.rb CHANGED
@@ -99,4 +99,52 @@ class TestVideo < Minitest::Test
99
99
  assert_kind_of Pexels::VideoSet, search_result
100
100
  assert search_result.videos.any?
101
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
149
+ end
102
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.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: 2021-08-18 00:00:00.000000000 Z
11
+ date: 2022-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: requests
@@ -83,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  - !ruby/object:Gem::Version
84
84
  version: '0'
85
85
  requirements: []
86
- rubygems_version: 3.0.3
86
+ rubygems_version: 3.0.3.1
87
87
  signing_key:
88
88
  specification_version: 4
89
89
  summary: A simple Ruby wrapper for the Pexels API