client-api-builder 0.6.1 → 0.7.1

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.
@@ -1,46 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'base64'
4
- require 'securerandom'
5
-
6
- BasicAuthExampleClient = Struct.new(
7
- :username,
8
- :password
9
- ) do
10
- include ClientApiBuilder::Router
11
- include ClientApiBuilder::Section
12
-
13
- base_url 'https://www.example.com'
14
-
15
- configure_retries(2)
16
-
17
- header 'Authorization', :basic_authorization
18
- query_param('cache_buster') { (Time.now.to_f * 1000).to_i }
19
-
20
- route :get_apps, '/apps'
21
- route :get_app, '/apps/:app_id'
22
-
23
- section :users do
24
- header 'Authorization', :bearer_authorization
25
-
26
- route :create_user, '/users?z={cache_buster}'
27
- end
28
-
29
- def cache_buster
30
- (Time.now.to_f * 1000).to_i
31
- end
32
-
33
- private
34
-
35
- def auth_token
36
- @auth_token ||= SecureRandom.uuid
37
- end
38
-
39
- def basic_authorization
40
- 'basic ' + Base64.strict_encode64(username + ':' + password)
41
- end
42
-
43
- def bearer_authorization
44
- 'bearer ' + auth_token
45
- end
46
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class IMDBDatesetsClient
4
- include ClientApiBuilder::Router
5
-
6
- base_url 'https://datasets.imdbws.com'
7
-
8
- route :get_name_basics, '/name.basics.tsv.gz', stream: :file
9
- route :get_title_akas, '/title.akas.tsv.gz', stream: :io
10
- route :get_title_basics, '/title.basics.tsv.gz', stream: :block
11
-
12
- def self.stream_to_file
13
- new.get_name_basics(file: 'name.basics.tsv.gz')
14
- end
15
-
16
- def self.stream_to_io
17
- File.open('title.akas.tsv.gz', 'wb') do |io|
18
- new.get_title_akas(io: io)
19
- end
20
- end
21
-
22
- def self.stream_with_block
23
- File.open('title.basics.tsv.gz', 'wb') do |io|
24
- total_read = 0.0
25
- new.get_title_basics do |response, chunk|
26
- total_read += chunk.bytesize
27
- percentage_complete = ((total_read / response.content_length) * 100).to_i
28
- puts "downloading title.basics.tsv.gz completed: #{percentage_complete}%"
29
- io.write chunk
30
- end
31
- end
32
- end
33
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class LoremIpsumClient
4
- include ClientApiBuilder::Router
5
-
6
- # by default it converts the body data to JSON
7
- # to convert the body to query params (x=1&y=2) use the following
8
- # if using active support change this to :to_query
9
- body_builder :query_params
10
-
11
- base_url 'https://www.lipsum.com'
12
-
13
- header 'Content-Type', 'application/x-www-form-urlencoded'
14
- header 'Accept', 'application/json'
15
-
16
- # this creates a method called create_lorem_ipsum with 2 named arguments amont and what
17
- route :create_lorem_ipsum, '/feed/json', body: { amount: :amount, what: :what, start: 'yes', generate: 'Generate Lorem Ipsum' }
18
- end
data/script/console DELETED
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- $LOAD_PATH << File.expand_path('../lib', __dir__)
5
- $LOAD_PATH << File.expand_path('../examples', __dir__)
6
- require 'client-api-builder'
7
- autoload :BasicAuthExampleClient, 'basic_auth_example_client'
8
- autoload :IMDBDatesetsClient, 'imdb_datasets_client'
9
- autoload :LoremIpsumClient, 'lorem_ipsum_client'
10
- require 'logger'
11
- LOG = Logger.new($stdout)
12
- ClientApiBuilder.logger = LOG
13
- ClientApiBuilder::ActiveSupportLogSubscriber.new(LOG).subscribe!
14
- require 'irb'
15
- IRB.start(__FILE__)