client-api-builder 0.3.1 → 0.4.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: 06500a9c514d0979b01f672ae5bdac70c5dfc7b23b3633f0662a71c4a057a01b
4
- data.tar.gz: c3a00f73d888ad6a19b98a9a0c172685fd5299b61fa99b41931c427db8d73470
3
+ metadata.gz: c22eb6c8362909af90380e2513875c7a82c4bd67028e5a601694c1d604fc599d
4
+ data.tar.gz: e6ad4f872b67a07563b88f3880bbd1f3375ed2d628a4c15cdedb0734fc9723a3
5
5
  SHA512:
6
- metadata.gz: 2263f684643292a86895f23906e2d566043d914704b92db919a1f23e1d47c1f5371ef7ea344257a63b234aac6ce8e5f293d4cf16b20e08248c7859fb8b692448
7
- data.tar.gz: 0a2508597031c861ea8ba44ac00f9fcd3596b040bde9df1d3724afdb4c5a0d4b4b463d19e75b0360a2987ba1ad7375bff8c25572cb6fced4e194a560bb6f927e
6
+ metadata.gz: 5bbe4fe12d3ea5ca240b445630360346a0a1628c340c9ce602efbacfb185ad23c7215233dcb84cb245ff5d3961b0695e8d177a15c39f87e9f6f6b4c0d030e60c
7
+ data.tar.gz: 44c82d195b80ad34205af3fa256523fa0a3a1e7249bd857ac7cc0cece431d9d75906f26a5714914075e0b9291d84ad5649704add740c099d960ad2e60ad3e2ee
data/README.md CHANGED
@@ -1,2 +1,33 @@
1
1
  # client-api-builder
2
- Utility for creating methods to make api calls
2
+
3
+ Utility for creating API clients through configuration
4
+
5
+ Example:
6
+
7
+ ```
8
+ class LoremIpsumClient
9
+ include ClientApiBuilder::Router
10
+
11
+ # by default it converts the body data to JSON
12
+ # to convert the body to query params (x=1&y=2) use the following
13
+ # if using active support change this to :to_query
14
+ body_builder :query_params
15
+
16
+ base_url 'https://www.lipsum.com'
17
+
18
+ header 'Content-Type', 'application/x-www-form-urlencoded'
19
+ header 'Accept', 'application/json'
20
+
21
+ # this creates a method called create_lorem_ipsum with 2 named arguments amont and what
22
+ route :create_lorem_ipsum, '/feed/json', body: {amount: :amount, what: :what, start: 'yes', generate: 'Generate Lorem Ipsum'}
23
+ end
24
+ ```
25
+
26
+ How to use:
27
+
28
+ ```
29
+ client = LoremIpsumClient.new
30
+ payload = client.create_lorem_ipsum(amount: 10, what: 'words')
31
+ puts payload.dig('feed', 'lipsum')
32
+ # outputs: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam at.
33
+ ```
@@ -2,10 +2,10 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'client-api-builder'
5
- s.version = '0.3.1'
5
+ s.version = '0.4.0'
6
6
  s.licenses = ['MIT']
7
- s.summary = 'Develop Client API libraries faster'
8
- s.description = 'Utility for constructing API clients'
7
+ s.summary = 'Utility for creating API clients through configuration'
8
+ s.description = 'Create API clients through configuration with complete transparency'
9
9
  s.authors = ['Doug Youch']
10
10
  s.email = 'dougyouch@gmail.com'
11
11
  s.homepage = 'https://github.com/dougyouch/client-api-builder'
@@ -0,0 +1,16 @@
1
+ class LoremIpsumClient
2
+ include ClientApiBuilder::Router
3
+
4
+ # by default it converts the body data to JSON
5
+ # to convert the body to query params (x=1&y=2) use the following
6
+ # if using active support change this to :to_query
7
+ body_builder :query_params
8
+
9
+ base_url 'https://www.lipsum.com'
10
+
11
+ header 'Content-Type', 'application/x-www-form-urlencoded'
12
+ header 'Accept', 'application/json'
13
+
14
+ # this creates a method called create_lorem_ipsum with 2 named arguments amont and what
15
+ route :create_lorem_ipsum, '/feed/json', body: {amount: :amount, what: :what, start: 'yes', generate: 'Generate Lorem Ipsum'}
16
+ end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  require 'inheritance-helper'
3
+ require 'json'
3
4
 
4
5
  module ClientApiBuilder
5
6
  module Router
@@ -9,7 +10,7 @@ module ClientApiBuilder
9
10
  base.include ::ClientApiBuilder::Section
10
11
  base.include ::ClientApiBuilder::NetHTTP::Request
11
12
  base.include(::ClientApiBuilder::ActiveSupportNotifications) if defined?(ActiveSupport)
12
- base.send(:attr_reader, :response, :request_options, :total_request_time, :retry_attempts)
13
+ base.send(:attr_reader, :response, :request_options, :total_request_time, :request_attempts)
13
14
  end
14
15
 
15
16
  module ClassMethods
data/script/console CHANGED
@@ -6,6 +6,7 @@ $LOAD_PATH << File.expand_path('../examples', __dir__)
6
6
  require 'client-api-builder'
7
7
  autoload :BasicAuthExampleClient, 'basic_auth_example_client'
8
8
  autoload :IMDBDatesetsClient, 'imdb_datasets_client'
9
+ autoload :LoremIpsumClient, 'lorem_ipsum_client'
9
10
  require 'logger'
10
11
  LOG = Logger.new(STDOUT)
11
12
  ClientApiBuilder.logger = LOG
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.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Doug Youch
@@ -24,7 +24,7 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.2.5
27
- description: Utility for constructing API clients
27
+ description: Create API clients through configuration with complete transparency
28
28
  email: dougyouch@gmail.com
29
29
  executables: []
30
30
  extensions: []
@@ -40,6 +40,7 @@ files:
40
40
  - client-api-builder.gemspec
41
41
  - examples/basic_auth_example_client.rb
42
42
  - examples/imdb_datasets_client.rb
43
+ - examples/lorem_ipsum_client.rb
43
44
  - lib/client-api-builder.rb
44
45
  - lib/client_api_builder/active_support_log_subscriber.rb
45
46
  - lib/client_api_builder/active_support_notifications.rb
@@ -71,5 +72,5 @@ requirements: []
71
72
  rubygems_version: 3.3.3
72
73
  signing_key:
73
74
  specification_version: 4
74
- summary: Develop Client API libraries faster
75
+ summary: Utility for creating API clients through configuration
75
76
  test_files: []