client-api-builder 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/client-api-builder.gemspec +1 -1
- data/examples/imdb_datasets_client.rb +31 -0
- data/lib/client_api_builder/net_http_request.rb +2 -2
- data/lib/client_api_builder/router.rb +3 -2
- data/script/console +3 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe20c0bab4626c805bc2b0c982cdd2bf27ed6b83d601a2b4be3377da74d34d65
|
4
|
+
data.tar.gz: c82184aadfac611f12f57060bc315d9790b4bab7238ba4c2942334058b5fdafd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3df586e352a828dc8423862f425ce0524c4e479c10f4e35b6a514b92412277dc4d0c095afbdaaeb024b5783c38745f3d1fe2bebb31b34f097611b0dca77d7ad
|
7
|
+
data.tar.gz: 42c359200e625705ce7960ae88d861d49cf5a83ad7e3dca71ee240f0df36addb88a7488e9da656a6d545b27cafe6075f09b8aab2242363896aa0321fb3399bf5
|
data/client-api-builder.gemspec
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
class IMDBDatesetsClient
|
2
|
+
include ClientApiBuilder::Router
|
3
|
+
|
4
|
+
base_url 'https://datasets.imdbws.com'
|
5
|
+
|
6
|
+
route :get_name_basics, '/name.basics.tsv.gz', stream: :file
|
7
|
+
route :get_title_akas, '/title.akas.tsv.gz', stream: :io
|
8
|
+
route :get_title_basics, '/title.basics.tsv.gz', stream: :block
|
9
|
+
|
10
|
+
def self.stream_to_file
|
11
|
+
new.get_name_basics(file: 'name.basics.tsv.gz')
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.stream_to_io
|
15
|
+
File.open('title.akas.tsv.gz', 'wb') do |io|
|
16
|
+
new.get_title_akas(io: io)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.stream_with_block
|
21
|
+
File.open('title.basics.tsv.gz', 'wb') do |io|
|
22
|
+
total_read = 0.0
|
23
|
+
new.get_title_basics do |response, chunk|
|
24
|
+
total_read += chunk.bytesize
|
25
|
+
percentage_complete = ((total_read / response.content_length) * 100).to_i
|
26
|
+
puts "downloading title.basics.tsv.gz completed: #{percentage_complete}%"
|
27
|
+
io.write chunk
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -37,13 +37,13 @@ module ClientApiBuilder
|
|
37
37
|
def stream(method:, uri:, body:, headers:, connection_options:)
|
38
38
|
request(method: method, uri: uri, body: body, headers: headers, connection_options: connection_options) do |response|
|
39
39
|
response.read_body do |chunk|
|
40
|
-
yield chunk
|
40
|
+
yield response, chunk
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
45
|
def stream_to_io(method:, uri:, body:, headers:, connection_options:, io:)
|
46
|
-
stream(method: method, uri: uri, body: body, headers: headers, connection_options: connection_options) do |chunk|
|
46
|
+
stream(method: method, uri: uri, body: body, headers: headers, connection_options: connection_options) do |_, chunk|
|
47
47
|
io.write chunk
|
48
48
|
end
|
49
49
|
end
|
@@ -220,9 +220,10 @@ module ClientApiBuilder
|
|
220
220
|
|
221
221
|
case options[:stream]
|
222
222
|
when true,
|
223
|
-
:file
|
224
|
-
:io
|
223
|
+
:file
|
225
224
|
code += " @response = stream_to_file(**@request_options)\n"
|
225
|
+
when :io
|
226
|
+
code += " @response = stream_to_io(**@request_options)\n"
|
226
227
|
when :block
|
227
228
|
code += " @response = stream(**@request_options, &block)\n"
|
228
229
|
else
|
data/script/console
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
$LOAD_PATH << File.expand_path('../lib', __dir__)
|
5
|
+
$LOAD_PATH << File.expand_path('../examples', __dir__)
|
5
6
|
require 'client-api-builder'
|
7
|
+
autoload :BasicAuthExampleClient, 'basic_auth_example_client'
|
8
|
+
autoload :IMDBDatesetsClient, 'imdb_datasets_client'
|
6
9
|
require 'irb'
|
7
10
|
IRB.start(__FILE__)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: client-api-builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Doug Youch
|
@@ -25,6 +25,7 @@ files:
|
|
25
25
|
- README.md
|
26
26
|
- client-api-builder.gemspec
|
27
27
|
- examples/basic_auth_example_client.rb
|
28
|
+
- examples/imdb_datasets_client.rb
|
28
29
|
- lib/client-api-builder.rb
|
29
30
|
- lib/client_api_builder/net_http_request.rb
|
30
31
|
- lib/client_api_builder/query_params.rb
|