google-gax 0.3.0 → 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 +4 -4
- data/lib/google/gax.rb +32 -10
- data/lib/google/gax/api_callable.rb +53 -56
- data/lib/google/gax/path_template.rb +4 -4
- data/lib/google/gax/settings.rb +9 -4
- data/lib/google/gax/version.rb +1 -1
- data/spec/google/gax/api_callable_spec.rb +6 -1
- data/spec/google/gax/settings_spec.rb +7 -1
- metadata +4 -4
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: f00dba40d04710327a4348f2b0919f423b81ab3d
         | 
| 4 | 
            +
              data.tar.gz: 16ebb311b89300f865849238f840acedd3aec149
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 128e33ba96e202d5abf7b941d922737fc56115cd3c4d82b9fe3b331beb7639704f9ac1e86980f64757c2169b0fdee8e9668b985d8a81cb2f9c4aee46c3eb1255
         | 
| 7 | 
            +
              data.tar.gz: 234a0c126f754c7db3690f53aeda09a689143cc52e141d787b3cd17259c7bc0db371cca13544a85253a450ed11178a45e8b05c0c06c3c342f84ceabacab465f9
         | 
    
        data/lib/google/gax.rb
    CHANGED
    
    | @@ -49,9 +49,11 @@ module Google | |
| 49 49 | 
             
                #   @return [Object]
         | 
| 50 50 | 
             
                # @!attribute [r] bundle_descriptor
         | 
| 51 51 | 
             
                #   @return [BundleDescriptor]
         | 
| 52 | 
            +
                # @!attribute [r] kwargs
         | 
| 53 | 
            +
                #   @return [Hash]
         | 
| 52 54 | 
             
                class CallSettings
         | 
| 53 55 | 
             
                  attr_reader :timeout, :retry_options, :page_descriptor, :page_token,
         | 
| 54 | 
            -
                              :bundler, :bundle_descriptor
         | 
| 56 | 
            +
                              :bundler, :bundle_descriptor, :kwargs, :errors
         | 
| 55 57 |  | 
| 56 58 | 
             
                  # @param timeout [Numeric] The client-side timeout for API calls. This
         | 
| 57 59 | 
             
                  #   parameter is ignored for retrying calls.
         | 
| @@ -67,14 +69,21 @@ module Google | |
| 67 69 | 
             
                  #   performed.
         | 
| 68 70 | 
             
                  # @param bundle_descriptor [BundleDescriptor] indicates the structure of
         | 
| 69 71 | 
             
                  #   the bundle. If nil, bundling is not performed.
         | 
| 72 | 
            +
                  # @param kwargs [Hash]
         | 
| 73 | 
            +
                  #   Additional keyword argments to be passed to the API call.
         | 
| 74 | 
            +
                  # @param errors [Array<Exception>]
         | 
| 75 | 
            +
                  #   Configures the exceptions to wrap with GaxError.
         | 
| 70 76 | 
             
                  def initialize(timeout: 30, retry_options: nil, page_descriptor: nil,
         | 
| 71 | 
            -
                                 page_token: nil, bundler: nil, bundle_descriptor: nil | 
| 77 | 
            +
                                 page_token: nil, bundler: nil, bundle_descriptor: nil,
         | 
| 78 | 
            +
                                 kwargs: {}, errors: [])
         | 
| 72 79 | 
             
                    @timeout = timeout
         | 
| 73 80 | 
             
                    @retry_options = retry_options
         | 
| 74 81 | 
             
                    @page_descriptor = page_descriptor
         | 
| 75 82 | 
             
                    @page_token = page_token
         | 
| 76 83 | 
             
                    @bundler = bundler
         | 
| 77 84 | 
             
                    @bundle_descriptor = bundle_descriptor
         | 
| 85 | 
            +
                    @kwargs = kwargs
         | 
| 86 | 
            +
                    @errors = errors
         | 
| 78 87 | 
             
                  end
         | 
| 79 88 |  | 
| 80 89 | 
             
                  # @return true when it has retry codes.
         | 
| @@ -98,7 +107,9 @@ module Google | |
| 98 107 | 
             
                                              page_descriptor: @page_descriptor,
         | 
| 99 108 | 
             
                                              page_token: @page_token,
         | 
| 100 109 | 
             
                                              bundler: @bundler,
         | 
| 101 | 
            -
                                              bundle_descriptor: @bundle_descriptor | 
| 110 | 
            +
                                              bundle_descriptor: @bundle_descriptor,
         | 
| 111 | 
            +
                                              kwargs: @kwargs,
         | 
| 112 | 
            +
                                              errors: @errors)
         | 
| 102 113 | 
             
                    end
         | 
| 103 114 |  | 
| 104 115 | 
             
                    timeout = if options.timeout == :OPTION_INHERIT
         | 
| @@ -117,12 +128,17 @@ module Google | |
| 117 128 | 
             
                                   options.page_token
         | 
| 118 129 | 
             
                                 end
         | 
| 119 130 |  | 
| 131 | 
            +
                    kwargs = @kwargs.dup
         | 
| 132 | 
            +
                    kwargs.update(options.kwargs) if options.kwargs != :OPTION_INHERIT
         | 
| 133 | 
            +
             | 
| 120 134 | 
             
                    CallSettings.new(timeout: timeout,
         | 
| 121 135 | 
             
                                     retry_options: retry_options,
         | 
| 122 136 | 
             
                                     page_descriptor: @page_descriptor,
         | 
| 123 137 | 
             
                                     page_token: page_token,
         | 
| 124 138 | 
             
                                     bundler: @bundler,
         | 
| 125 | 
            -
                                     bundle_descriptor: @bundle_descriptor | 
| 139 | 
            +
                                     bundle_descriptor: @bundle_descriptor,
         | 
| 140 | 
            +
                                     kwargs: kwargs,
         | 
| 141 | 
            +
                                     errors: @errors)
         | 
| 126 142 | 
             
                  end
         | 
| 127 143 | 
             
                end
         | 
| 128 144 |  | 
| @@ -133,8 +149,10 @@ module Google | |
| 133 149 | 
             
                #   @return [RetryOptions, :OPTION_INHERIT]
         | 
| 134 150 | 
             
                # @!attribute [r] page_token
         | 
| 135 151 | 
             
                #   @return [Object, :OPTION_INHERIT, :INITIAL_PAGE]
         | 
| 152 | 
            +
                # @!attribute [r] kwargs
         | 
| 153 | 
            +
                #  @return [Hash, :OPTION_INHERIT]
         | 
| 136 154 | 
             
                class CallOptions
         | 
| 137 | 
            -
                  attr_reader :timeout, :retry_options, :page_token
         | 
| 155 | 
            +
                  attr_reader :timeout, :retry_options, :page_token, :kwargs
         | 
| 138 156 |  | 
| 139 157 | 
             
                  # @param timeout [Numeric, :OPTION_INHERIT]
         | 
| 140 158 | 
             
                  #   The client-side timeout for API calls.
         | 
| @@ -144,12 +162,16 @@ module Google | |
| 144 162 | 
             
                  # @param page_token [Object, :OPTION_INHERIT]
         | 
| 145 163 | 
             
                  #   If set and the call is configured for page streaming, page streaming
         | 
| 146 164 | 
             
                  #   is starting with this page_token.
         | 
| 165 | 
            +
                  # @param kwargs [Hash, :OPTION_INHERIT]
         | 
| 166 | 
            +
                  #   Additional keyword argments to be passed to the API call.
         | 
| 147 167 | 
             
                  def initialize(timeout: :OPTION_INHERIT,
         | 
| 148 168 | 
             
                                 retry_options: :OPTION_INHERIT,
         | 
| 149 | 
            -
                                 page_token: :OPTION_INHERIT | 
| 169 | 
            +
                                 page_token: :OPTION_INHERIT,
         | 
| 170 | 
            +
                                 kwargs: :OPTION_INHERIT)
         | 
| 150 171 | 
             
                    @timeout = timeout
         | 
| 151 172 | 
             
                    @retry_options = retry_options
         | 
| 152 173 | 
             
                    @page_token = page_token
         | 
| 174 | 
            +
                    @kwargs = kwargs
         | 
| 153 175 | 
             
                  end
         | 
| 154 176 | 
             
                end
         | 
| 155 177 |  | 
| @@ -243,7 +265,7 @@ module Google | |
| 243 265 | 
             
                                                 :element_count_limit,
         | 
| 244 266 | 
             
                                                 :request_byte_threshold,
         | 
| 245 267 | 
             
                                                 :request_byte_limit,
         | 
| 246 | 
            -
                                                 : | 
| 268 | 
            +
                                                 :delay_threshold_millis)
         | 
| 247 269 | 
             
                  # @!attribute element_count_threshold
         | 
| 248 270 | 
             
                  #   @return [Numeric] the bundled request will be sent once the
         | 
| 249 271 | 
             
                  #     count of outstanding elements in the repeated field
         | 
| @@ -269,7 +291,7 @@ module Google | |
| 269 291 | 
             
                  #     pessimistically approximated by summing the bytesizes of
         | 
| 270 292 | 
             
                  #     the elements in the repeated field, with a buffer applied
         | 
| 271 293 | 
             
                  #     to correspond to the resulting under-approximation.
         | 
| 272 | 
            -
                  # @!attribute  | 
| 294 | 
            +
                  # @!attribute delay_threshold_millis
         | 
| 273 295 | 
             
                  #   @return [Numeric] the bundled request will be sent this
         | 
| 274 296 | 
             
                  #     amount of time after the first element in the bundle was
         | 
| 275 297 | 
             
                  #     added to it.
         | 
| @@ -277,13 +299,13 @@ module Google | |
| 277 299 | 
             
                                 element_count_limit: 0,
         | 
| 278 300 | 
             
                                 request_byte_threshold: 0,
         | 
| 279 301 | 
             
                                 request_byte_limit: 0,
         | 
| 280 | 
            -
                                  | 
| 302 | 
            +
                                 delay_threshold_millis: 0)
         | 
| 281 303 | 
             
                    super(
         | 
| 282 304 | 
             
                      element_count_threshold,
         | 
| 283 305 | 
             
                      element_count_limit,
         | 
| 284 306 | 
             
                      request_byte_threshold,
         | 
| 285 307 | 
             
                      request_byte_limit,
         | 
| 286 | 
            -
                       | 
| 308 | 
            +
                      delay_threshold_millis)
         | 
| 287 309 | 
             
                  end
         | 
| 288 310 | 
             
                end
         | 
| 289 311 | 
             
              end
         | 
| @@ -30,7 +30,6 @@ | |
| 30 30 | 
             
            require 'time'
         | 
| 31 31 |  | 
| 32 32 | 
             
            require 'google/gax/errors'
         | 
| 33 | 
            -
            require 'google/gax/grpc'
         | 
| 34 33 |  | 
| 35 34 | 
             
            # rubocop:disable Metrics/ModuleLength
         | 
| 36 35 |  | 
| @@ -45,16 +44,16 @@ module Google | |
| 45 44 | 
             
                # PagedEnumerable provides the enumerations over the resource data,
         | 
| 46 45 | 
             
                # and also provides the enumerations over the pages themselves.
         | 
| 47 46 | 
             
                #
         | 
| 48 | 
            -
                #  | 
| 47 | 
            +
                # @example normal iteration over resources.
         | 
| 49 48 | 
             
                #   paged_enumerable.each { |resource| puts resource }
         | 
| 50 49 | 
             
                #
         | 
| 51 | 
            -
                #  | 
| 50 | 
            +
                # @example per-page iteration.
         | 
| 52 51 | 
             
                #   paged_enumerable.each_page { |page| puts page }
         | 
| 53 52 | 
             
                #
         | 
| 54 | 
            -
                #  | 
| 53 | 
            +
                # @example Enumerable over pages.
         | 
| 55 54 | 
             
                #   pages = paged_enumerable.enum_for(:each_page).to_a
         | 
| 56 55 | 
             
                #
         | 
| 57 | 
            -
                #  | 
| 56 | 
            +
                # @example more exact operations over pages.
         | 
| 58 57 | 
             
                #   while some_condition()
         | 
| 59 58 | 
             
                #     page = paged_enumerable.page
         | 
| 60 59 | 
             
                #     do_something(page)
         | 
| @@ -120,35 +119,33 @@ module Google | |
| 120 119 | 
             
                  include Enumerable
         | 
| 121 120 | 
             
                  attr_reader :page
         | 
| 122 121 |  | 
| 123 | 
            -
                  # @param a_func [Proc]
         | 
| 124 | 
            -
                  #   A proc to update the response object.
         | 
| 125 122 | 
             
                  # @param request_page_token_field [String]
         | 
| 126 123 | 
             
                  #   The name of the field in request which will have the page token.
         | 
| 127 124 | 
             
                  # @param response_page_token_field [String]
         | 
| 128 125 | 
             
                  #   The name of the field in the response which holds the next page token.
         | 
| 129 126 | 
             
                  # @param resource_field [String]
         | 
| 130 127 | 
             
                  #   The name of the field in the response which holds the resources.
         | 
| 131 | 
            -
                  def initialize( | 
| 128 | 
            +
                  def initialize(request_page_token_field,
         | 
| 132 129 | 
             
                                 response_page_token_field, resource_field)
         | 
| 133 | 
            -
                    @func = a_func
         | 
| 134 130 | 
             
                    @request_page_token_field = request_page_token_field
         | 
| 135 131 | 
             
                    @page = Page.new(nil, response_page_token_field, resource_field)
         | 
| 136 132 | 
             
                  end
         | 
| 137 133 |  | 
| 138 134 | 
             
                  # Initiate the streaming with the requests and keywords.
         | 
| 139 | 
            -
                  # @param  | 
| 140 | 
            -
                  #    | 
| 135 | 
            +
                  # @param api_call [Proc]
         | 
| 136 | 
            +
                  #   A proc to update the response object.
         | 
| 141 137 | 
             
                  # @param request [Object]
         | 
| 142 138 | 
             
                  #   The initial request object.
         | 
| 143 | 
            -
                  # @param  | 
| 144 | 
            -
                  #    | 
| 139 | 
            +
                  # @param settings [CallSettings]
         | 
| 140 | 
            +
                  #   The call settings to enumerate pages.
         | 
| 145 141 | 
             
                  # @return [PagedEnumerable]
         | 
| 146 142 | 
             
                  #   returning self for further uses.
         | 
| 147 | 
            -
                  def start( | 
| 143 | 
            +
                  def start(api_call, request, settings)
         | 
| 144 | 
            +
                    @func = api_call
         | 
| 148 145 | 
             
                    @request = request
         | 
| 146 | 
            +
                    page_token = settings.page_token
         | 
| 149 147 | 
             
                    @request[@request_page_token_field] = page_token if page_token
         | 
| 150 | 
            -
                    @ | 
| 151 | 
            -
                    @page = @page.dup_with(@func.call(@request, **@kwargs))
         | 
| 148 | 
            +
                    @page = @page.dup_with(@func.call(@request))
         | 
| 152 149 | 
             
                    self
         | 
| 153 150 | 
             
                  end
         | 
| 154 151 |  | 
| @@ -190,7 +187,7 @@ module Google | |
| 190 187 | 
             
                  def next_page
         | 
| 191 188 | 
             
                    return unless next_page?
         | 
| 192 189 | 
             
                    @request[@request_page_token_field] = @page.next_page_token
         | 
| 193 | 
            -
                    @page = @page.dup_with(@func.call(@request | 
| 190 | 
            +
                    @page = @page.dup_with(@func.call(@request))
         | 
| 194 191 | 
             
                  end
         | 
| 195 192 |  | 
| 196 193 | 
             
                  def response
         | 
| @@ -219,47 +216,51 @@ module Google | |
| 219 216 | 
             
                # does the signature change.
         | 
| 220 217 | 
             
                #
         | 
| 221 218 | 
             
                # @param func [Proc] used to make a bare rpc call
         | 
| 222 | 
            -
                # @param settings [CallSettings provides the settings for this call
         | 
| 219 | 
            +
                # @param settings [CallSettings] provides the settings for this call
         | 
| 223 220 | 
             
                # @return [Proc] a bound method on a request stub used to make an rpc call
         | 
| 224 221 | 
             
                # @raise [StandardError] if +settings+ has incompatible values,
         | 
| 225 222 | 
             
                #   e.g, if bundling and page_streaming are both configured
         | 
| 226 223 | 
             
                def create_api_call(func, settings)
         | 
| 227 | 
            -
                   | 
| 228 | 
            -
             | 
| 229 | 
            -
             | 
| 230 | 
            -
                               add_timeout_arg(func, settings.timeout)
         | 
| 231 | 
            -
                             end
         | 
| 224 | 
            +
                  api_caller = proc do |api_call, request|
         | 
| 225 | 
            +
                    api_call.call(request)
         | 
| 226 | 
            +
                  end
         | 
| 232 227 |  | 
| 233 228 | 
             
                  if settings.page_descriptor
         | 
| 234 229 | 
             
                    if settings.bundler?
         | 
| 235 230 | 
             
                      raise 'ApiCallable has incompatible settings: ' \
         | 
| 236 231 | 
             
                          'bundling and page streaming'
         | 
| 237 232 | 
             
                    end
         | 
| 238 | 
            -
                     | 
| 239 | 
            -
             | 
| 240 | 
            -
             | 
| 241 | 
            -
             | 
| 242 | 
            -
             | 
| 243 | 
            -
             | 
| 244 | 
            -
                    )
         | 
| 245 | 
            -
                  end
         | 
| 246 | 
            -
                  if settings.bundler?
         | 
| 247 | 
            -
                    return bundleable(api_call, settings.bundle_descriptor,
         | 
| 248 | 
            -
                                      settings.bundler)
         | 
| 233 | 
            +
                    page_descriptor = settings.page_descriptor
         | 
| 234 | 
            +
                    api_caller = page_streamable(page_descriptor.request_page_token_field,
         | 
| 235 | 
            +
                                                 page_descriptor.response_page_token_field,
         | 
| 236 | 
            +
                                                 page_descriptor.resource_field)
         | 
| 237 | 
            +
                  elsif settings.bundler?
         | 
| 238 | 
            +
                    api_caller = bundleable(settings.bundle_descriptor)
         | 
| 249 239 | 
             
                  end
         | 
| 250 240 |  | 
| 251 | 
            -
                   | 
| 241 | 
            +
                  proc do |request, options = nil|
         | 
| 242 | 
            +
                    this_settings = settings.merge(options)
         | 
| 243 | 
            +
                    api_call = if settings.retry_codes?
         | 
| 244 | 
            +
                                 retryable(func, this_settings.retry_options,
         | 
| 245 | 
            +
                                           this_settings.kwargs)
         | 
| 246 | 
            +
                               else
         | 
| 247 | 
            +
                                 add_timeout_arg(func, this_settings.timeout,
         | 
| 248 | 
            +
                                                 this_settings.kwargs)
         | 
| 249 | 
            +
                               end
         | 
| 250 | 
            +
                    api_call = catch_errors(api_call, settings.errors)
         | 
| 251 | 
            +
                    api_caller.call(api_call, request, this_settings)
         | 
| 252 | 
            +
                  end
         | 
| 252 253 | 
             
                end
         | 
| 253 254 |  | 
| 254 255 | 
             
                # Updates a_func to wrap exceptions with GaxError
         | 
| 255 256 | 
             
                #
         | 
| 256 257 | 
             
                # @param a_func [Proc]
         | 
| 257 258 | 
             
                # @param errors [Array<Exception>] Configures the exceptions to wrap.
         | 
| 258 | 
            -
                # @return [Proc] A proc that will wrap certain exceptions with GaxError
         | 
| 259 | 
            -
                def catch_errors(a_func, errors | 
| 260 | 
            -
                  proc do |request | 
| 259 | 
            +
                # @return [Proc] A proc that will wrap certain exceptions with GaxError.
         | 
| 260 | 
            +
                def catch_errors(a_func, errors)
         | 
| 261 | 
            +
                  proc do |request|
         | 
| 261 262 | 
             
                    begin
         | 
| 262 | 
            -
                      a_func.call(request | 
| 263 | 
            +
                      a_func.call(request)
         | 
| 263 264 | 
             
                    rescue *errors
         | 
| 264 265 | 
             
                      raise GaxError, 'RPC failed'
         | 
| 265 266 | 
             
                    end
         | 
| @@ -281,11 +282,12 @@ module Google | |
| 281 282 | 
             
                # @param bundler orchestrates bundling.
         | 
| 282 283 | 
             
                # @return [Proc] A proc takes the API call's request and returns
         | 
| 283 284 | 
             
                #   an Event object.
         | 
| 284 | 
            -
                def bundleable( | 
| 285 | 
            -
                  proc do |request|
         | 
| 285 | 
            +
                def bundleable(desc)
         | 
| 286 | 
            +
                  proc do |api_call, request, settings|
         | 
| 287 | 
            +
                    return api_call(request) unless settings.bundler
         | 
| 286 288 | 
             
                    the_id = bundling.compute_bundle_id(request,
         | 
| 287 289 | 
             
                                                        desc.request_discriminator_fields)
         | 
| 288 | 
            -
                    return bundler.schedule( | 
| 290 | 
            +
                    return bundler.schedule(api_call, the_id, desc, request)
         | 
| 289 291 | 
             
                  end
         | 
| 290 292 | 
             
                end
         | 
| 291 293 |  | 
| @@ -300,18 +302,13 @@ module Google | |
| 300 302 | 
             
                # @param page_token [Object] The page_token for the first page to be
         | 
| 301 303 | 
             
                #   streamed, or nil.
         | 
| 302 304 | 
             
                # @return [Proc] A proc that returns an iterable over the specified field.
         | 
| 303 | 
            -
                def page_streamable( | 
| 304 | 
            -
                                    request_page_token_field,
         | 
| 305 | 
            +
                def page_streamable(request_page_token_field,
         | 
| 305 306 | 
             
                                    response_page_token_field,
         | 
| 306 | 
            -
                                    resource_field | 
| 307 | 
            -
             | 
| 308 | 
            -
                  enumerable = PagedEnumerable.new(a_func,
         | 
| 309 | 
            -
                                                   request_page_token_field,
         | 
| 307 | 
            +
                                    resource_field)
         | 
| 308 | 
            +
                  enumerable = PagedEnumerable.new(request_page_token_field,
         | 
| 310 309 | 
             
                                                   response_page_token_field,
         | 
| 311 310 | 
             
                                                   resource_field)
         | 
| 312 | 
            -
                   | 
| 313 | 
            -
                    enumerable.start(page_token, request, **kwargs)
         | 
| 314 | 
            -
                  end
         | 
| 311 | 
            +
                  enumerable.method(:start)
         | 
| 315 312 | 
             
                end
         | 
| 316 313 |  | 
| 317 314 | 
             
                # rubocop:disable Metrics/MethodLength
         | 
| @@ -324,7 +321,7 @@ module Google | |
| 324 321 | 
             
                #   upon which the proc should retry, and the parameters to the
         | 
| 325 322 | 
             
                #   exponential backoff retry algorithm.
         | 
| 326 323 | 
             
                # @return [Proc] A proc that will retry on exception.
         | 
| 327 | 
            -
                def retryable(a_func, retry_options)
         | 
| 324 | 
            +
                def retryable(a_func, retry_options, kwargs)
         | 
| 328 325 | 
             
                  delay_mult = retry_options.backoff_settings.retry_delay_multiplier
         | 
| 329 326 | 
             
                  max_delay = (retry_options.backoff_settings.max_retry_delay_millis /
         | 
| 330 327 | 
             
                               MILLIS_PER_SECOND)
         | 
| @@ -334,7 +331,7 @@ module Google | |
| 334 331 | 
             
                  total_timeout = (retry_options.backoff_settings.total_timeout_millis /
         | 
| 335 332 | 
             
                                   MILLIS_PER_SECOND)
         | 
| 336 333 |  | 
| 337 | 
            -
                  proc do |request | 
| 334 | 
            +
                  proc do |request|
         | 
| 338 335 | 
             
                    delay = retry_options.backoff_settings.initial_retry_delay_millis
         | 
| 339 336 | 
             
                    timeout = (retry_options.backoff_settings.initial_rpc_timeout_millis /
         | 
| 340 337 | 
             
                               MILLIS_PER_SECOND)
         | 
| @@ -344,7 +341,7 @@ module Google | |
| 344 341 |  | 
| 345 342 | 
             
                    loop do
         | 
| 346 343 | 
             
                      begin
         | 
| 347 | 
            -
                        result = add_timeout_arg(a_func, timeout).call(request | 
| 344 | 
            +
                        result = add_timeout_arg(a_func, timeout, kwargs).call(request)
         | 
| 348 345 | 
             
                        break
         | 
| 349 346 | 
             
                      rescue => exception
         | 
| 350 347 | 
             
                        unless exception.respond_to?(:code) &&
         | 
| @@ -374,8 +371,8 @@ module Google | |
| 374 371 | 
             
                # @param timeout [Numeric] to be added to the original proc as it
         | 
| 375 372 | 
             
                #   final positional arg.
         | 
| 376 373 | 
             
                # @return [Proc] the original proc updated to the timeout arg
         | 
| 377 | 
            -
                def add_timeout_arg(a_func, timeout)
         | 
| 378 | 
            -
                  proc do |request | 
| 374 | 
            +
                def add_timeout_arg(a_func, timeout, kwargs)
         | 
| 375 | 
            +
                  proc do |request|
         | 
| 379 376 | 
             
                    kwargs[:timeout] = timeout
         | 
| 380 377 | 
             
                    a_func.call(request, **kwargs)
         | 
| 381 378 | 
             
                  end
         | 
| @@ -80,13 +80,13 @@ module Google | |
| 80 80 | 
             
                  rule 'bound_segments : bound_segment FORWARD_SLASH bound_segments
         | 
| 81 81 | 
             
                                       | bound_segment' do |segs, a_seg, _, more_segs|
         | 
| 82 82 | 
             
                    segs.value = a_seg.value
         | 
| 83 | 
            -
                    segs.value. | 
| 83 | 
            +
                    segs.value.concat(more_segs.value) unless more_segs.nil?
         | 
| 84 84 | 
             
                  end
         | 
| 85 85 |  | 
| 86 86 | 
             
                  rule 'unbound_segments : unbound_terminal FORWARD_SLASH unbound_segments
         | 
| 87 87 | 
             
                                         | unbound_terminal' do |segs, a_term, _, more_segs|
         | 
| 88 88 | 
             
                    segs.value = a_term.value
         | 
| 89 | 
            -
                    segs.value. | 
| 89 | 
            +
                    segs.value.concat(more_segs.value) unless more_segs.nil?
         | 
| 90 90 | 
             
                  end
         | 
| 91 91 |  | 
| 92 92 | 
             
                  rule 'bound_segment : bound_terminal
         | 
| @@ -118,7 +118,7 @@ module Google | |
| 118 118 | 
             
                                 | LEFT_BRACE LITERAL RIGHT_BRACE' do |variable, *args|
         | 
| 119 119 | 
             
                    variable.value = [Segment.new(BINDING, args[1].value)]
         | 
| 120 120 | 
             
                    if args.size > 3
         | 
| 121 | 
            -
                      variable.value. | 
| 121 | 
            +
                      variable.value.concat(args[3].value)
         | 
| 122 122 | 
             
                    else
         | 
| 123 123 | 
             
                      variable.value.push(Segment.new(TERMINAL, '*'))
         | 
| 124 124 | 
             
                      @segment_count += 1
         | 
| @@ -178,7 +178,7 @@ module Google | |
| 178 178 | 
             
                          msg = "Value for key #{segment.literal} is not provided"
         | 
| 179 179 | 
             
                          raise(ArgumentError, msg)
         | 
| 180 180 | 
             
                        end
         | 
| 181 | 
            -
                        out. | 
| 181 | 
            +
                        out.concat(PathTemplate.new(bindings[literal_sym]).segments)
         | 
| 182 182 | 
             
                        binding = true
         | 
| 183 183 | 
             
                      elsif segment.kind == END_BINDING
         | 
| 184 184 | 
             
                        binding = false
         | 
    
        data/lib/google/gax/settings.rb
    CHANGED
    
    | @@ -183,11 +183,15 @@ module Google | |
| 183 183 | 
             
                # @param page_descriptors [Hash{String => PageDescriptor}] A
         | 
| 184 184 | 
             
                #   dictionary of method names to PageDescriptor objects for
         | 
| 185 185 | 
             
                #   methods that are page streaming-enabled.
         | 
| 186 | 
            +
                # @param kwargs [Hash]
         | 
| 187 | 
            +
                #   Additional keyword argments to be passed to the API call.
         | 
| 188 | 
            +
                # @param errors [Array<Exception>]
         | 
| 189 | 
            +
                #   Configures the exceptions to wrap with GaxError.
         | 
| 186 190 | 
             
                # @return [CallSettings, nil] A CallSettings, or nil if the
         | 
| 187 191 | 
             
                #   service is not found in the config.
         | 
| 188 192 | 
             
                def construct_settings(service_name, client_config, config_overrides,
         | 
| 189 193 | 
             
                                       retry_names, timeout, bundle_descriptors: {},
         | 
| 190 | 
            -
                                       page_descriptors: {})
         | 
| 194 | 
            +
                                       page_descriptors: {}, kwargs: {}, errors: [])
         | 
| 191 195 | 
             
                  defaults = {}
         | 
| 192 196 |  | 
| 193 197 | 
             
                  service_config = client_config.fetch('interfaces', {})[service_name]
         | 
| @@ -220,9 +224,10 @@ module Google | |
| 220 224 | 
             
                                        retry_names)
         | 
| 221 225 | 
             
                      ),
         | 
| 222 226 | 
             
                      page_descriptor: page_descriptors[snake_name],
         | 
| 223 | 
            -
                      bundler: construct_bundling(bundling_config,
         | 
| 224 | 
            -
             | 
| 225 | 
            -
                       | 
| 227 | 
            +
                      bundler: construct_bundling(bundling_config, bundle_descriptor),
         | 
| 228 | 
            +
                      bundle_descriptor: bundle_descriptor,
         | 
| 229 | 
            +
                      kwargs: kwargs,
         | 
| 230 | 
            +
                      errors: errors
         | 
| 226 231 | 
             
                    )
         | 
| 227 232 | 
             
                  end
         | 
| 228 233 |  | 
    
        data/lib/google/gax/version.rb
    CHANGED
    
    
| @@ -56,6 +56,11 @@ describe Google::Gax do | |
| 56 56 | 
             
                  my_callable = Google::Gax.create_api_call(func, settings)
         | 
| 57 57 | 
             
                  expect(my_callable.call(nil)).to eq(42)
         | 
| 58 58 | 
             
                  expect(timeout_arg).to_not be_nil
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                  new_timeout = timeout_arg + 20
         | 
| 61 | 
            +
                  options = Google::Gax::CallOptions.new(timeout: new_timeout)
         | 
| 62 | 
            +
                  expect(my_callable.call(nil, options)).to eq(42)
         | 
| 63 | 
            +
                  expect(timeout_arg).to eq(new_timeout)
         | 
| 59 64 | 
             
                end
         | 
| 60 65 | 
             
              end
         | 
| 61 66 |  | 
| @@ -112,7 +117,7 @@ describe Google::Gax do | |
| 112 117 |  | 
| 113 118 | 
             
              describe 'failures without retry' do
         | 
| 114 119 | 
             
                it 'simply fails' do
         | 
| 115 | 
            -
                  settings = CallSettings.new
         | 
| 120 | 
            +
                  settings = CallSettings.new(errors: [GRPC::Cancelled])
         | 
| 116 121 | 
             
                  timeout_arg = nil
         | 
| 117 122 | 
             
                  call_count = 0
         | 
| 118 123 | 
             
                  func = proc do |timeout: nil|
         | 
| @@ -90,7 +90,9 @@ describe Google::Gax do | |
| 90 90 | 
             
                defaults = Google::Gax.construct_settings(
         | 
| 91 91 | 
             
                  SERVICE_NAME, A_CONFIG, {}, RETRY_DICT, 30,
         | 
| 92 92 | 
             
                  bundle_descriptors: BUNDLE_DESCRIPTORS,
         | 
| 93 | 
            -
                  page_descriptors: PAGE_DESCRIPTORS
         | 
| 93 | 
            +
                  page_descriptors: PAGE_DESCRIPTORS,
         | 
| 94 | 
            +
                  kwargs: { 'key' => 'value' },
         | 
| 95 | 
            +
                  errors: [StandardError]
         | 
| 94 96 | 
             
                )
         | 
| 95 97 | 
             
                settings = defaults['bundling_method']
         | 
| 96 98 | 
             
                expect(settings.timeout).to be(30)
         | 
| @@ -103,6 +105,8 @@ describe Google::Gax do | |
| 103 105 | 
             
                expect(settings.retry_options.backoff_settings).to be_a(
         | 
| 104 106 | 
             
                  Google::Gax::BackoffSettings
         | 
| 105 107 | 
             
                )
         | 
| 108 | 
            +
                expect(settings.kwargs).to match('key' => 'value')
         | 
| 109 | 
            +
                expect(settings.errors).to match_array([StandardError])
         | 
| 106 110 |  | 
| 107 111 | 
             
                settings = defaults['page_streaming_method']
         | 
| 108 112 | 
             
                expect(settings.timeout).to be(30)
         | 
| @@ -114,6 +118,8 @@ describe Google::Gax do | |
| 114 118 | 
             
                expect(settings.retry_options.backoff_settings).to be_a(
         | 
| 115 119 | 
             
                  Google::Gax::BackoffSettings
         | 
| 116 120 | 
             
                )
         | 
| 121 | 
            +
                expect(settings.kwargs).to match('key' => 'value')
         | 
| 122 | 
            +
                expect(settings.errors).to match_array([StandardError])
         | 
| 117 123 | 
             
              end
         | 
| 118 124 |  | 
| 119 125 | 
             
              it 'overrides settings' do
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: google-gax
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.4.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Google API Authors
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2016- | 
| 11 | 
            +
            date: 2016-07-13 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: googleauth
         | 
| @@ -30,14 +30,14 @@ dependencies: | |
| 30 30 | 
             
                requirements:
         | 
| 31 31 | 
             
                - - "~>"
         | 
| 32 32 | 
             
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            -
                    version: 0. | 
| 33 | 
            +
                    version: 0.14.1
         | 
| 34 34 | 
             
              type: :runtime
         | 
| 35 35 | 
             
              prerelease: false
         | 
| 36 36 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 37 | 
             
                requirements:
         | 
| 38 38 | 
             
                - - "~>"
         | 
| 39 39 | 
             
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            -
                    version: 0. | 
| 40 | 
            +
                    version: 0.14.1
         | 
| 41 41 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 42 42 | 
             
              name: rly
         | 
| 43 43 | 
             
              requirement: !ruby/object:Gem::Requirement
         |