Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion README.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions lib/serpapi/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/serpapi/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module SerpApi
# Current version of the gem
VERSION = '1.0.1'.freeze
VERSION = '1.0.2'.freeze
end
13 changes: 12 additions & 1 deletion spec/serpapi/client/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -136,4 +147,4 @@
expect(client.socket).to be_nil
expect(client.close).to be_nil
end
end
end
Loading