restool 0.1.7 → 1.0.5
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 +4 -4
 - data/lib/restool.rb +0 -2
 - data/lib/restool/logger/request_logger.rb +11 -3
 - data/lib/restool/service/remote_client.rb +18 -25
 - data/lib/restool/service/restool_service.rb +1 -1
 - data/lib/restool/settings/loader.rb +3 -13
 - data/lib/restool/settings/models.rb +1 -2
 - data/lib/restool/version.rb +1 -1
 - metadata +7 -21
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 05ec555dd4ba0c213f8e83605d1540a6c882e321a36efe26648f2667e84cf09a
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 15e3008576a39d6d1911f0fbd42b9b272feec61dd14960746affe76061a45fab
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: e11f57af7e2bfab4fe7ba87ed3cec7935457a8b8717510aea5d37e7a28e329532befaeb21b07eba47c8933b18234b53e77be1e6607f12131c1d3ac2c2b51553a
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 9b0c9f4955b16048588b071ebf631fcdeeb374bf204cf729d61511c1091b67e18aa0d824d414df9485cd212c92848148293adaf7fea75dc9768a9f9e9fc3ee88
         
     | 
    
        data/lib/restool.rb
    CHANGED
    
    
| 
         @@ -12,6 +12,10 @@ module Restool 
     | 
|
| 
       12 
12 
     | 
    
         
             
                  log_response(response) if log?
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
14 
     | 
    
         
             
                  response
         
     | 
| 
      
 15 
     | 
    
         
            +
                rescue StandardError => e
         
     | 
| 
      
 16 
     | 
    
         
            +
                  log_error(e) if log?
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                  raise
         
     | 
| 
       15 
19 
     | 
    
         
             
                end
         
     | 
| 
       16 
20 
     | 
    
         | 
| 
       17 
21 
     | 
    
         
             
                def logger
         
     | 
| 
         @@ -31,15 +35,19 @@ module Restool 
     | 
|
| 
       31 
35 
     | 
    
         
             
                def log_request(request)
         
     | 
| 
       32 
36 
     | 
    
         
             
                  logger.info  { "Restool Service #{@host}" }
         
     | 
| 
       33 
37 
     | 
    
         
             
                  logger.info  { "#{request.method.upcase} #{request.path}" }
         
     | 
| 
       34 
     | 
    
         
            -
                  logger.info  { format_hash(request.headers) }
         
     | 
| 
       35 
     | 
    
         
            -
                  logger.debug { format_hash(request.params) }
         
     | 
| 
      
 38 
     | 
    
         
            +
                  logger.info  { "Headers: { #{format_hash(request.headers)} }" }
         
     | 
| 
      
 39 
     | 
    
         
            +
                  logger.debug { "Params: { #{format_hash(request.params)} }" }
         
     | 
| 
       36 
40 
     | 
    
         
             
                end
         
     | 
| 
       37 
41 
     | 
    
         | 
| 
       38 
42 
     | 
    
         
             
                def log_response(response)
         
     | 
| 
       39 
     | 
    
         
            -
                  logger.info  { "Restool response (status #{response.code})" }
         
     | 
| 
      
 43 
     | 
    
         
            +
                  logger.info  { "Restool response (status #{response.code}):" }
         
     | 
| 
       40 
44 
     | 
    
         
             
                  logger.debug { response.body }
         
     | 
| 
       41 
45 
     | 
    
         
             
                end
         
     | 
| 
       42 
46 
     | 
    
         | 
| 
      
 47 
     | 
    
         
            +
                def log_error(error)
         
     | 
| 
      
 48 
     | 
    
         
            +
                  logger.error { "Restool error: #{error}" }
         
     | 
| 
      
 49 
     | 
    
         
            +
                end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
       43 
51 
     | 
    
         
             
                def format_hash(headers)
         
     | 
| 
       44 
52 
     | 
    
         
             
                  headers.map { |key, value| "#{key}: #{value}" }.join(", ")
         
     | 
| 
       45 
53 
     | 
    
         
             
                end
         
     | 
| 
         @@ -1,5 +1,5 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require  
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            require "net/http"
         
     | 
| 
      
 2 
     | 
    
         
            +
            require "net/https"
         
     | 
| 
       3 
3 
     | 
    
         
             
            require_relative 'request_utils'
         
     | 
| 
       4 
4 
     | 
    
         
             
            require_relative '../logger/request_logger'
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
         @@ -7,30 +7,9 @@ module Restool 
     | 
|
| 
       7 
7 
     | 
    
         
             
              module Service
         
     | 
| 
       8 
8 
     | 
    
         
             
                class RemoteClient
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
     | 
    
         
            -
                  def initialize(host, verify_ssl,  
     | 
| 
      
 10 
     | 
    
         
            +
                  def initialize(host, verify_ssl, timeout, opts)
         
     | 
| 
       11 
11 
     | 
    
         
             
                    @request_logger = Restool::RequestLogger.new(host, opts)
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
                    @connection = if persistent_connection
         
     | 
| 
       14 
     | 
    
         
            -
                                    PersistentHTTP.new(
         
     | 
| 
       15 
     | 
    
         
            -
                                      pool_size:    persistent_connection.pool_size,
         
     | 
| 
       16 
     | 
    
         
            -
                                      pool_timeout: timeout,
         
     | 
| 
       17 
     | 
    
         
            -
                                      warn_timeout: persistent_connection.warn_timeout,
         
     | 
| 
       18 
     | 
    
         
            -
                                      force_retry:  persistent_connection.force_retry,
         
     | 
| 
       19 
     | 
    
         
            -
                                      url:          host,
         
     | 
| 
       20 
     | 
    
         
            -
                                      read_timeout: timeout,
         
     | 
| 
       21 
     | 
    
         
            -
                                      open_timeout: timeout,
         
     | 
| 
       22 
     | 
    
         
            -
                                      verify_mode: verify_ssl?(verify_ssl)
         
     | 
| 
       23 
     | 
    
         
            -
                                    )
         
     | 
| 
       24 
     | 
    
         
            -
                                  else
         
     | 
| 
       25 
     | 
    
         
            -
                                    uri               = URI.parse(host)
         
     | 
| 
       26 
     | 
    
         
            -
                                    http              = Net::HTTP.new(uri.host, uri.port)
         
     | 
| 
       27 
     | 
    
         
            -
                                    http.use_ssl      = uri.is_a?(URI::HTTPS)
         
     | 
| 
       28 
     | 
    
         
            -
                                    http.verify_mode  = verify_ssl?(verify_ssl)
         
     | 
| 
       29 
     | 
    
         
            -
                                    http.read_timeout = timeout
         
     | 
| 
       30 
     | 
    
         
            -
                                    http.open_timeout = timeout
         
     | 
| 
       31 
     | 
    
         
            -
                                    http.set_debug_output($stdout) if opts[:debug]
         
     | 
| 
       32 
     | 
    
         
            -
                                    http
         
     | 
| 
       33 
     | 
    
         
            -
                                  end
         
     | 
| 
      
 12 
     | 
    
         
            +
                    @connection = build_connection(host, verify_ssl, timeout, opts)
         
     | 
| 
       34 
13 
     | 
    
         
             
                  end
         
     | 
| 
       35 
14 
     | 
    
         | 
| 
       36 
15 
     | 
    
         
             
                  def make_request(path, method, request_params, headers, basic_auth)
         
     | 
| 
         @@ -43,6 +22,20 @@ module Restool 
     | 
|
| 
       43 
22 
     | 
    
         | 
| 
       44 
23 
     | 
    
         
             
                  private
         
     | 
| 
       45 
24 
     | 
    
         | 
| 
      
 25 
     | 
    
         
            +
                  def build_connection(host, verify_ssl, timeout, opts)
         
     | 
| 
      
 26 
     | 
    
         
            +
                    uri = URI.parse(host)
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                    connection = Net::HTTP.new(uri.host, uri.port)
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                    connection.use_ssl      = uri.is_a?(URI::HTTPS)
         
     | 
| 
      
 31 
     | 
    
         
            +
                    connection.verify_mode  = verify_ssl?(verify_ssl)
         
     | 
| 
      
 32 
     | 
    
         
            +
                    connection.read_timeout = timeout
         
     | 
| 
      
 33 
     | 
    
         
            +
                    connection.open_timeout = timeout
         
     | 
| 
      
 34 
     | 
    
         
            +
                    connection.set_debug_output($stdout) if opts[:debug]
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                    connection
         
     | 
| 
      
 37 
     | 
    
         
            +
                  end
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
       46 
39 
     | 
    
         
             
                  def verify_ssl?(verify_ssl_setting)
         
     | 
| 
       47 
40 
     | 
    
         
             
                    verify_ssl_setting ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE
         
     | 
| 
       48 
41 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -11,7 +11,7 @@ module Restool 
     | 
|
| 
       11 
11 
     | 
    
         
             
                    @service_config = service_config
         
     | 
| 
       12 
12 
     | 
    
         
             
                    @response_handler = response_handler
         
     | 
| 
       13 
13 
     | 
    
         
             
                    @remote_client = Restool::Service::RemoteClient.new(service_config.host, service_config.verify_ssl,
         
     | 
| 
       14 
     | 
    
         
            -
                                                                        service_config. 
     | 
| 
      
 14 
     | 
    
         
            +
                                                                        service_config.timeout, service_config.opts)
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
16 
     | 
    
         
             
                    define_operations(
         
     | 
| 
       17 
17 
     | 
    
         
             
                      @service_config, method(:make_request), method(:make_request_with_uri_params)
         
     | 
| 
         @@ -11,9 +11,9 @@ module Restool 
     | 
|
| 
       11 
11 
     | 
    
         
             
                  DEFAULT_SSL_VERIFY = false
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
                  def self.load(service_name, opts)
         
     | 
| 
      
 14 
     | 
    
         
            +
                  def self.load(service_name, opts = {})
         
     | 
| 
       15 
15 
     | 
    
         
             
                    service_config = config['services'].detect do |service|
         
     | 
| 
       16 
     | 
    
         
            -
                      service['name'] == service_name
         
     | 
| 
      
 16 
     | 
    
         
            +
                      service['name'] == service_name.to_s
         
     | 
| 
       17 
17 
     | 
    
         
             
                    end
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
19 
     | 
    
         
             
                    raise "Service #{service_name} not found in configuration" unless service_config
         
     | 
| 
         @@ -30,18 +30,9 @@ module Restool 
     | 
|
| 
       30 
30 
     | 
    
         
             
                                        []
         
     | 
| 
       31 
31 
     | 
    
         
             
                                      end
         
     | 
| 
       32 
32 
     | 
    
         | 
| 
       33 
     | 
    
         
            -
                    basic_auth = service_config['basic_auth'] || service_config['basic_authentication']
         
     | 
| 
      
 33 
     | 
    
         
            +
                    basic_auth = opts['basic_auth'] || opts['basic_authentication'] || service_config['basic_auth'] || service_config['basic_authentication']
         
     | 
| 
       34 
34 
     | 
    
         
             
                    basic_auth = BasicAuthentication.new(basic_auth['user'], basic_auth['password']) if basic_auth
         
     | 
| 
       35 
35 
     | 
    
         | 
| 
       36 
     | 
    
         
            -
                    persistent_connection = service_config['persistent']
         
     | 
| 
       37 
     | 
    
         
            -
                    persistent_connection = if persistent_connection
         
     | 
| 
       38 
     | 
    
         
            -
                                              PersistentConnection.new(
         
     | 
| 
       39 
     | 
    
         
            -
                                                persistent_connection['pool_size'],
         
     | 
| 
       40 
     | 
    
         
            -
                                                persistent_connection['warn_timeout'],
         
     | 
| 
       41 
     | 
    
         
            -
                                                persistent_connection['force_retry'],
         
     | 
| 
       42 
     | 
    
         
            -
                                              )
         
     | 
| 
       43 
     | 
    
         
            -
                                            end
         
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
36 
     | 
    
         
             
                    # Support host + common path in url config, e.g. api.com/v2/
         
     | 
| 
       46 
37 
     | 
    
         
             
                    paths_prefix_in_host = URI(service_config['url']).path
         
     | 
| 
       47 
38 
     | 
    
         | 
| 
         @@ -49,7 +40,6 @@ module Restool 
     | 
|
| 
       49 
40 
     | 
    
         
             
                      service_config['name'],
         
     | 
| 
       50 
41 
     | 
    
         
             
                      service_config['url'],
         
     | 
| 
       51 
42 
     | 
    
         
             
                      service_config['operations'].map { |operation| build_operation(operation, paths_prefix_in_host) },
         
     | 
| 
       52 
     | 
    
         
            -
                      persistent_connection,
         
     | 
| 
       53 
43 
     | 
    
         
             
                      service_config['timeout'] || DEFAULT_TIMEOUT,
         
     | 
| 
       54 
44 
     | 
    
         
             
                      representations,
         
     | 
| 
       55 
45 
     | 
    
         
             
                      basic_auth,
         
     | 
| 
         @@ -4,11 +4,10 @@ module Restool 
     | 
|
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
                  Operation = Struct.new(:name, :path, :method, :uri_params, :response)
         
     | 
| 
       6 
6 
     | 
    
         
             
                  OperationResponse = Struct.new(:fields)
         
     | 
| 
       7 
     | 
    
         
            -
                  Service = Struct.new(:name, :host, :operations, : 
     | 
| 
      
 7 
     | 
    
         
            +
                  Service = Struct.new(:name, :host, :operations, :timeout, :representations, :basic_auth, :verify_ssl, :opts)
         
     | 
| 
       8 
8 
     | 
    
         
             
                  Representation = Struct.new(:name, :fields)
         
     | 
| 
       9 
9 
     | 
    
         
             
                  RepresentationField = Struct.new(:key, :metonym, :type)
         
     | 
| 
       10 
10 
     | 
    
         
             
                  BasicAuthentication = Struct.new(:user, :password)
         
     | 
| 
       11 
     | 
    
         
            -
                  PersistentConnection = Struct.new(:respool_size, :want_timeout, :force_retry)
         
     | 
| 
       12 
11 
     | 
    
         
             
                  OperationResponsField = RepresentationField
         
     | 
| 
       13 
12 
     | 
    
         | 
| 
       14 
13 
     | 
    
         
             
                end
         
     | 
    
        data/lib/restool/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,29 +1,15 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: restool
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.0.5
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Juan Andres Zeni
         
     | 
| 
       8 
     | 
    
         
            -
            autorequire: 
     | 
| 
      
 8 
     | 
    
         
            +
            autorequire:
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date:  
     | 
| 
       12 
     | 
    
         
            -
            dependencies:
         
     | 
| 
       13 
     | 
    
         
            -
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
     | 
    
         
            -
              name: persistent_http
         
     | 
| 
       15 
     | 
    
         
            -
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
       16 
     | 
    
         
            -
                requirements:
         
     | 
| 
       17 
     | 
    
         
            -
                - - ">="
         
     | 
| 
       18 
     | 
    
         
            -
                  - !ruby/object:Gem::Version
         
     | 
| 
       19 
     | 
    
         
            -
                    version: '0'
         
     | 
| 
       20 
     | 
    
         
            -
              type: :runtime
         
     | 
| 
       21 
     | 
    
         
            -
              prerelease: false
         
     | 
| 
       22 
     | 
    
         
            -
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       23 
     | 
    
         
            -
                requirements:
         
     | 
| 
       24 
     | 
    
         
            -
                - - ">="
         
     | 
| 
       25 
     | 
    
         
            -
                  - !ruby/object:Gem::Version
         
     | 
| 
       26 
     | 
    
         
            -
                    version: '0'
         
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2021-03-09 00:00:00.000000000 Z
         
     | 
| 
      
 12 
     | 
    
         
            +
            dependencies: []
         
     | 
| 
       27 
13 
     | 
    
         
             
            description: Make HTTP requests and handle its responses using simple method calls.
         
     | 
| 
       28 
14 
     | 
    
         
             
              Restool turns your HTTP API and its responses into Ruby interfaces.
         
     | 
| 
       29 
15 
     | 
    
         
             
            email:
         
     | 
| 
         @@ -51,7 +37,7 @@ homepage: https://github.com/jzeni/restool 
     | 
|
| 
       51 
37 
     | 
    
         
             
            licenses:
         
     | 
| 
       52 
38 
     | 
    
         
             
            - MIT
         
     | 
| 
       53 
39 
     | 
    
         
             
            metadata: {}
         
     | 
| 
       54 
     | 
    
         
            -
            post_install_message: 
     | 
| 
      
 40 
     | 
    
         
            +
            post_install_message:
         
     | 
| 
       55 
41 
     | 
    
         
             
            rdoc_options: []
         
     | 
| 
       56 
42 
     | 
    
         
             
            require_paths:
         
     | 
| 
       57 
43 
     | 
    
         
             
            - lib
         
     | 
| 
         @@ -66,8 +52,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       66 
52 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       67 
53 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       68 
54 
     | 
    
         
             
            requirements: []
         
     | 
| 
       69 
     | 
    
         
            -
            rubygems_version: 3.0.1
         
     | 
| 
       70 
     | 
    
         
            -
            signing_key: 
     | 
| 
      
 55 
     | 
    
         
            +
            rubygems_version: 3.2.0.rc.1
         
     | 
| 
      
 56 
     | 
    
         
            +
            signing_key:
         
     | 
| 
       71 
57 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       72 
58 
     | 
    
         
             
            summary: Turn your API and its responses into Ruby interfaces.
         
     | 
| 
       73 
59 
     | 
    
         
             
            test_files: []
         
     |