client-api-builder 0.2.3 → 0.2.4

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: '01795148989ed0a14c42cb886fd3ce76e3692d82c388f49adf09b7b7229b928f'
4
- data.tar.gz: 4ce828ecc5ee2017e6318ab83e8c1c02e3a557f746a7f3f6fc8d7471cdac2750
3
+ metadata.gz: fe20c0bab4626c805bc2b0c982cdd2bf27ed6b83d601a2b4be3377da74d34d65
4
+ data.tar.gz: c82184aadfac611f12f57060bc315d9790b4bab7238ba4c2942334058b5fdafd
5
5
  SHA512:
6
- metadata.gz: 57b713cda946c263a13f6642d8548442f574eaea1f0374b1e02c7d2f071a3826aeb3e49eaa3a785784eeb7caa671584192f0391e6a508b5dbbd4fff32868063e
7
- data.tar.gz: d41bfea574c3399d534455ab7165a9fc6f91c347fd5c6d6634fa67731bb5198ccc843532e06fea853097316f766522daebf875cce855694b87e67bb0ea6771fb
6
+ metadata.gz: b3df586e352a828dc8423862f425ce0524c4e479c10f4e35b6a514b92412277dc4d0c095afbdaaeb024b5783c38745f3d1fe2bebb31b34f097611b0dca77d7ad
7
+ data.tar.gz: 42c359200e625705ce7960ae88d861d49cf5a83ad7e3dca71ee240f0df36addb88a7488e9da656a6d545b27cafe6075f09b8aab2242363896aa0321fb3399bf5
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'client-api-builder'
5
- s.version = '0.2.3'
5
+ s.version = '0.2.4'
6
6
  s.licenses = ['MIT']
7
7
  s.summary = 'Develop Client API libraries faster'
8
8
  s.description = 'Utility for constructing API clients'
@@ -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.3
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