diff --git a/README.md b/README.md index 7936864..b1d0247 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Other versions, such as Ruby 1.9, Ruby 2.x, and JRuby, are compatible with [lega ### Bundler ```ruby -gem 'serpapi', '~> 1.0', '>= 1.0.1' +gem 'serpapi', '~> 1.0', '>= 1.0.2' ``` ### Gem @@ -1085,6 +1085,7 @@ Ruby versions validated by Github Actions: * doc: [Github Actions.](https://github.com/serpapi/serpapi-ruby/actions/workflows/ci.yml) ## Change logs + * [2025-11-17] 1.0.2 Implement `inspect` functions for client * [2025-07-18] 1.0.1 Add support for old Ruby versions (2.7, 3.0) * [2025-07-01] 1.0.0 Full API support diff --git a/README.md.erb b/README.md.erb index 13b0ba5..625e08d 100644 --- a/README.md.erb +++ b/README.md.erb @@ -42,7 +42,7 @@ Other versions, such as Ruby 1.9, Ruby 2.x, and JRuby, are compatible with [lega ### Bundler ```ruby -gem 'serpapi', '~> 1.0', '>= 1.0.1' +gem 'serpapi', '~> 1.0', '>= 1.0.2' ``` ### Gem @@ -566,6 +566,7 @@ Ruby versions validated by Github Actions: * doc: [Github Actions.](https://github.com/serpapi/serpapi-ruby/actions/workflows/ci.yml) ## Change logs + * [2025-11-17] 1.0.2 Implement `inspect` functions for client * [2025-07-18] 1.0.1 Add support for old Ruby versions (2.7, 3.0) * [2025-07-01] 1.0.0 Full API support diff --git a/lib/serpapi/client.rb b/lib/serpapi/client.rb index ff1e583..ec5fe76 100644 --- a/lib/serpapi/client.rb +++ b/lib/serpapi/client.rb @@ -181,6 +181,11 @@ def close @socket.close if @socket end + def inspect + masked_key = api_key && (api_key.length > 8 ? "#{api_key[..3]}****#{api_key[-4..]}" : '****') + "#<#{self.class} @engine=#{engine} @timeout=#{timeout} @persistent=#{persistent} api_key=#{masked_key}>" + end + private # @param [Hash] params to merge with default parameters provided to the constructor. diff --git a/lib/serpapi/version.rb b/lib/serpapi/version.rb index 6f56435..954b930 100644 --- a/lib/serpapi/version.rb +++ b/lib/serpapi/version.rb @@ -1,4 +1,4 @@ module SerpApi # Current version of the gem - VERSION = '1.0.1'.freeze + VERSION = '1.0.2'.freeze end diff --git a/spec/serpapi/client/client_spec.rb b/spec/serpapi/client/client_spec.rb index a5f395c..52f1c5c 100644 --- a/spec/serpapi/client/client_spec.rb +++ b/spec/serpapi/client/client_spec.rb @@ -95,6 +95,17 @@ raise("wrong exception: #{e}") end end + + it 'should not expose api_key via inspect' do + inspect_str = client.inspect + expect(inspect_str).to_not include(ENV['SERPAPI_KEY']) + end + + it 'should gracefully handle api_key values shorter than 8 characters' do + short_key_client = SerpApi::Client.new(engine: 'google', api_key: 'abcdef', timeout: 10) + inspect_str = short_key_client.inspect + expect(inspect_str).to_not include('abcdef') + end end describe 'SerpApi client with persitency enable' do @@ -136,4 +147,4 @@ expect(client.socket).to be_nil expect(client.close).to be_nil end -end \ No newline at end of file +end