Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Changelog
* [Unreleased] Apply the `timeout` option to persistent connections
* [Unreleased] Add Image API support
* [Unreleased] Add Markdown search and archive output support
* [Unreleased] Raise `SerpApiError` for non-200 text responses, including 404 responses from `get('/invalid')`
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ results = client.search(
| `api_key` | None | Your SerpApi API key. Use an environment variable rather than committing it to source control. |
| `engine` | None | The search engine used by default, such as `google` or `google_maps`. |
| `persistent` | `true` | Reuses the HTTP connection between requests. Call `client.close` when finished. |
| `timeout` | `120` | Timeout in seconds for non-persistent HTTP requests. |
| `timeout` | `120` | Timeout in seconds for HTTP requests. |
| `async` | `false` | Submits searches without waiting for them to complete. It can be set on the client or per search. |
| `symbolize_names` | `true` | Returns JSON object keys as symbols. Pass `false` to a search to receive string keys. |

Expand Down
2 changes: 1 addition & 1 deletion README.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ results = client.search(
| `api_key` | None | Your SerpApi API key. Use an environment variable rather than committing it to source control. |
| `engine` | None | The search engine used by default, such as `google` or `google_maps`. |
| `persistent` | `true` | Reuses the HTTP connection between requests. Call `client.close` when finished. |
| `timeout` | `120` | Timeout in seconds for non-persistent HTTP requests. |
| `timeout` | `120` | Timeout in seconds for HTTP requests. |
| `async` | `false` | Submits searches without waiting for them to complete. It can be set on the client or per search. |
| `symbolize_names` | `true` | Returns JSON object keys as symbols. Pass `false` to a search to receive string keys. |

Expand Down
2 changes: 1 addition & 1 deletion lib/serpapi/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def initialize(params = {})
# create connection socket
return unless persistent?

@socket = HTTP.persistent("https://#{BACKEND}")
@socket = HTTP.timeout(timeout).persistent("https://#{BACKEND}")
end

# perform a search using SerpApi.com
Expand Down
4 changes: 4 additions & 0 deletions spec/serpapi/client/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@
expect(client.persistent).to be true
end

it 'applies the timeout to the persistent socket' do
expect(client.socket.default_options.timeout_options).to eq(global_timeout: 10)
end

it 'makes a search request with valid parameters' do
results = client.search(q: 'Coffee', location: 'Austin, TX')
expect(results.size).to be > 5
Expand Down