Skip to content

Commit 033beac

Browse files
committed
Seperate development guide from README
1 parent adae9d2 commit 033beac

File tree

3 files changed

+50
-163
lines changed

3 files changed

+50
-163
lines changed

DEVELOPMENT.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Developer Guide
2+
3+
## Key goals
4+
5+
- Brand centric instead of search engine based
6+
- No hard-coded logic per search engine
7+
- Simple HTTP client (lightweight, reduced dependency)
8+
- No magic default values
9+
- Thread safe
10+
- Easy extension
11+
- Defensive code style (raise a custom exception)
12+
- TDD - Test driven development
13+
- Best API coding practice per platform
14+
- KiSS principles
15+
16+
## Inspirations
17+
18+
This project source code and coding style was inspired by the most awesome Ruby Gems:
19+
- [bcrypt](https://github.com/bcrypt-ruby/bcrypt-ruby)
20+
- [Nokogiri](https://nokogiri.org)
21+
- [Cloudfare](https://rubygems.org/gems/cloudflare/versions/2.1.0)
22+
- [rest-client](https://rubygems.org/gems/rest-client)
23+
- [stripe](https://rubygems.org/gems/stripe)
24+
25+
## Code quality expectations
26+
27+
- 0 lint offense: `rake lint`
28+
- 100% tests passing: `rake test`
29+
- 100% code coverage: `rake coverage` (simple-cov)

README.md

Lines changed: 3 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,79 +1099,10 @@ Ruby versions validated by Github Actions:
10991099
- 3.4
11001100
* doc: [Github Actions.](https://github.com/serpapi/serpapi-ruby/actions/workflows/ci.yml)
11011101

1102-
## Developer Guide
1103-
### Key goals
1104-
- Brand centric instead of search engine based
1105-
- No hard-coded logic per search engine
1106-
- Simple HTTP client (lightweight, reduced dependency)
1107-
- No magic default values
1108-
- Thread safe
1109-
- Easy extension
1110-
- Defensive code style (raise a custom exception)
1111-
- TDD - Test driven development
1112-
- Best API coding practice per platform
1113-
- KiSS principles
1114-
1115-
### Inspirations
1116-
This project source code and coding style was inspired by the most awesome Ruby Gems:
1117-
- [bcrypt](https://github.com/bcrypt-ruby/bcrypt-ruby)
1118-
- [Nokogiri](https://nokogiri.org)
1119-
- [Cloudfare](https://rubygems.org/gems/cloudflare/versions/2.1.0)
1120-
- [rest-client](https://rubygems.org/gems/rest-client)
1121-
- [stripe](https://rubygems.org/gems/stripe)
1122-
1123-
### Code quality expectations
1124-
- 0 lint offense: `rake lint`
1125-
- 100% tests passing: `rake test`
1126-
- 100% code coverage: `rake coverage` (simple-cov)
1127-
1128-
# Developer Guide
1129-
## Design : UML diagram
1130-
### Class diagram
1131-
```mermaid
1132-
classDiagram
1133-
Application *-- serpapi
1134-
serpapi *-- Client
1135-
class Client {
1136-
engine String
1137-
api_key String
1138-
params Hash
1139-
search() Hash
1140-
html() String
1141-
location() String
1142-
search_archive() Hash
1143-
account() Hash
1144-
}
1145-
openuri <.. Client
1146-
json <.. Client
1147-
Ruby <.. openuri
1148-
Ruby <.. json
1149-
```
1150-
### search() : Sequence diagram
1151-
```mermaid
1152-
sequenceDiagram
1153-
Client->>SerpApi.com: search() : http request
1154-
SerpApi.com-->>SerpApi.com: query search engine
1155-
SerpApi.com-->>SerpApi.com: parse HTML into JSON
1156-
SerpApi.com-->>Client: JSON string payload
1157-
Client-->>Client: decode JSON into Hash
1158-
```
1159-
where:
1160-
- The end user implements the application.
1161-
- Client refers to SerpApi:Client.
1162-
- SerpApi.com is the backend HTTP / REST service.
1163-
- Engine refers to Google, Baidu, Bing, and more.
1164-
1165-
The SerpApi.com service (backend)
1166-
- executes a scalable search on `engine: "google"` using the search query: `q: "coffee"`.
1167-
- parses the messy HTML responses from Google on the backend.
1168-
- returns a standardized JSON response.
1169-
The class SerpApi::Client (client side / ruby):
1170-
- Format the request to SerpApi.com server.
1171-
- Execute HTTP Get request.
1172-
- Parse JSON into Ruby Hash using a standard JSON library.
1173-
Et voila!
1102+
## Development
11741103

1104+
Contributions are welcome. Make sure to read our [development guide](./DEVELOPMENT.md).
1105+
11751106
## Continuous integration
11761107
We love [continuous integration](https://en.wikipedia.org/wiki/Continuous_integration) (CI) and [Test-Driven Development](https://en.wikipedia.org/wiki/Test-driven_development) (TDD) at SerpApi.
11771108
We use RSpec and Github Actions to test our infrastructure around the clock, and that includes all changes to our clients.

README.md.erb

Lines changed: 18 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<%-
2-
def snippet(format, path, demo = false)
2+
def snippet(format, path, demo = false)
33
lines = File.new(path).readlines
44
if demo
55
# skip comment
@@ -20,13 +20,13 @@ end
2020
-%>
2121
# SerpApi Ruby Library
2222

23-
[![serpapi-ruby](https://github.com/serpapi/serpapi-ruby/actions/workflows/ci.yml/badge.svg)](https://github.com/serpapi/serpapi-ruby/actions/workflows/ci.yml) [![Gem Version](https://badge.fury.io/rb/serpapi.svg)](https://badge.fury.io/rb/serpapi)
23+
[![serpapi-ruby](https://github.com/serpapi/serpapi-ruby/actions/workflows/ci.yml/badge.svg)](https://github.com/serpapi/serpapi-ruby/actions/workflows/ci.yml) [![Gem Version](https://badge.fury.io/rb/serpapi.svg)](https://badge.fury.io/rb/serpapi)
2424

25-
Integrate search data into your AI workflow, RAG / fine-tuning, or Ruby application using this official wrapper for [SerpApi](https://serpapi.com).
25+
Integrate search data into your AI workflow, RAG / fine-tuning, or Ruby application using this official wrapper for [SerpApi](https://serpapi.com).
2626

27-
SerpApi supports Google, Google Maps, Google Shopping, Baidu, Yandex, Yahoo, eBay, App Stores, and [more](https://serpapi.com).
27+
SerpApi supports Google, Google Maps, Google Shopping, Baidu, Yandex, Yahoo, eBay, App Stores, and [more](https://serpapi.com).
2828

29-
Query a vast range of data at scale, including web search results, flight schedules, stock market data, news headlines, and [more](https://serpapi.com).
29+
Query a vast range of data at scale, including web search results, flight schedules, stock market data, news headlines, and [more](https://serpapi.com).
3030

3131
## Features
3232
* `persistent` → Keep socket connection open to save on SSL handshake / reconnection (2x faster). [Search at scale](#Search-At-Scale)
@@ -45,7 +45,7 @@ Other versions, such as Ruby 1.9, Ruby 2.x, and JRuby, are compatible with [lega
4545
gem 'serpapi', '~> 1.0', '>= 1.0.3'
4646
```
4747

48-
### Gem
48+
### Gem
4949
```bash
5050
$ gem install serpapi
5151
```
@@ -139,7 +139,7 @@ Search API enables `async` search.
139139
- Non-blocking (`async=true`) : the development is more complex, but this allows handling many simultaneous connections.
140140
- Blocking (`async=false`) : it is easy to write the code but more compute-intensive when the parent process needs to hold many connections.
141141

142-
Here is an example of asynchronous searches using Ruby
142+
Here is an example of asynchronous searches using Ruby
143143
```ruby
144144
require 'serpapi'
145145

@@ -204,9 +204,9 @@ end
204204
responses = threads.map(&:value)
205205
```
206206

207-
The code aims to demonstrate how thread pools can be used to
208-
improve performance by executing multiple tasks concurrently. In
209-
this case, it makes multiple HTTP requests to an API endpoint using
207+
The code aims to demonstrate how thread pools can be used to
208+
improve performance by executing multiple tasks concurrently. In
209+
this case, it makes multiple HTTP requests to an API endpoint using
210210
a thread pool of persistent connections.
211211

212212
Note: `gem install connection_pool` to run this example.
@@ -228,7 +228,7 @@ benchmark: (demo/demo_thread_pool.rb)
228228
| 3.4.8 | 0.018644 | 4 | 0.004661 |
229229
| 4.0.0 | 0.017302 | 4 | 0.004326 |
230230

231-
Ruby 4.0.0 shows a slight improvement over Ruby 3.4.8, but the difference is not significant using thread.
231+
Ruby 4.0.0 shows a slight improvement over Ruby 3.4.8, but the difference is not significant using thread.
232232
Ractor could be considered for a more efficient use of resources but it's still in the experimental stage.
233233

234234
Note: in this benchmark, `thread == HTTP connections`.
@@ -508,25 +508,25 @@ see: [https://serpapi.com/yelp-search-api](https://serpapi.com/yelp-search-api)
508508
4. **SerpApi Optimization**: Shows consistent ~2.2x improvement with persistent connections regardless of Ruby version
509509
5. **Ruby 4.0.0 Performance**: Shows mixed results with some regressions compared to 3.4.4, particularly for HTTP.rb persistent connections. Ruby 4.0.0 was just released for Christmas 2025, and HTTP.rb has not been optimized for it yet.
510510

511-
The older library (google-search-results-ruby) was performing at 55 req/s on Ruby 2.7.8, which is 2x slower than the current version (serpapi-ruby) on Ruby 3.4.4 or 4.0.0.
511+
The older library (google-search-results-ruby) was performing at 55 req/s on Ruby 2.7.8, which is 2x slower than the current version (serpapi-ruby) on Ruby 3.4.4 or 4.0.0.
512512

513-
**Context** This benchmark was performed on warmup search results using a MacBook Pro 2025 connected via Wi-Fi 6.0 home network on AT&T fiber from Austin, TX (no network optimization).
513+
**Context** This benchmark was performed on warmup search results using a MacBook Pro 2025 connected via Wi-Fi 6.0 home network on AT&T fiber from Austin, TX (no network optimization).
514514

515515
## Migration quick guide
516516

517517
If you were already using [google-search-results-ruby gem](https://github.com/serpapi/google-search-results-ruby), here are the changes.
518518

519519
```
520520
# load library
521-
# old way
521+
# old way
522522
require 'google_search_results'
523523
# new way
524524
require 'serpapi'
525525

526526
# define a search
527527
# old way to describe the search
528528
search = GoogleSearch.new(search_params)
529-
# new way
529+
# new way
530530
default_parameter = {api_key: "secret_key", engine: "google"}
531531
client = SerpApi::Client.new(default_parameter)
532532
# an instance of the serpapi client is created
@@ -553,7 +553,7 @@ raw_html = client.html(params)
553553
hash_results = search.get_hash
554554
# new way
555555
results = client.search(params)
556-
# where params is the search parameters (override the default search parameters in the constructor).
556+
# where params is the search parameters (override the default search parameters in the constructor).
557557

558558
# search as raw JSON format
559559
# old way
@@ -585,86 +585,13 @@ Ruby versions validated by Github Actions:
585585
* [2025-07-18] 1.0.1 Add support for old Ruby versions (2.7, 3.0)
586586
* [2025-07-01] 1.0.0 Full API support
587587

588-
## Developer Guide
589-
### Key goals
590-
- Brand centric instead of search engine based
591-
- No hard-coded logic per search engine
592-
- Simple HTTP client (lightweight, reduced dependency)
593-
- No magic default values
594-
- Thread safe
595-
- Easy extension
596-
- Defensive code style (raise a custom exception)
597-
- TDD - Test driven development
598-
- Best API coding practice per platform
599-
- KiSS principles
600-
601-
### Inspirations
602-
This project source code and coding style was inspired by the most awesome Ruby Gems:
603-
- [bcrypt](https://github.com/bcrypt-ruby/bcrypt-ruby)
604-
- [Nokogiri](https://nokogiri.org)
605-
- [Cloudfare](https://rubygems.org/gems/cloudflare/versions/2.1.0)
606-
- [rest-client](https://rubygems.org/gems/rest-client)
607-
- [stripe](https://rubygems.org/gems/stripe)
608-
609-
### Code quality expectations
610-
- 0 lint offense: `rake lint`
611-
- 100% tests passing: `rake test`
612-
- 100% code coverage: `rake coverage` (simple-cov)
613-
614-
# Developer Guide
615-
## Design : UML diagram
616-
### Class diagram
617-
```mermaid
618-
classDiagram
619-
Application *-- serpapi
620-
serpapi *-- Client
621-
class Client {
622-
engine String
623-
api_key String
624-
params Hash
625-
search() Hash
626-
html() String
627-
location() String
628-
search_archive() Hash
629-
account() Hash
630-
}
631-
openuri <.. Client
632-
json <.. Client
633-
Ruby <.. openuri
634-
Ruby <.. json
635-
```
636-
### search() : Sequence diagram
637-
```mermaid
638-
sequenceDiagram
639-
Client->>SerpApi.com: search() : http request
640-
SerpApi.com-->>SerpApi.com: query search engine
641-
SerpApi.com-->>SerpApi.com: parse HTML into JSON
642-
SerpApi.com-->>Client: JSON string payload
643-
Client-->>Client: decode JSON into Hash
644-
```
645-
where:
646-
- The end user implements the application.
647-
- Client refers to SerpApi:Client.
648-
- SerpApi.com is the backend HTTP / REST service.
649-
- Engine refers to Google, Baidu, Bing, and more.
650-
651-
The SerpApi.com service (backend)
652-
- executes a scalable search on `engine: "google"` using the search query: `q: "coffee"`.
653-
- parses the messy HTML responses from Google on the backend.
654-
- returns a standardized JSON response.
655-
The class SerpApi::Client (client side / ruby):
656-
- Format the request to SerpApi.com server.
657-
- Execute HTTP Get request.
658-
- Parse JSON into Ruby Hash using a standard JSON library.
659-
Et voila!
660-
661588
## Continuous integration
662-
We love [continuous integration](https://en.wikipedia.org/wiki/Continuous_integration) (CI) and [Test-Driven Development](https://en.wikipedia.org/wiki/Test-driven_development) (TDD) at SerpApi.
589+
We love [continuous integration](https://en.wikipedia.org/wiki/Continuous_integration) (CI) and [Test-Driven Development](https://en.wikipedia.org/wiki/Test-driven_development) (TDD) at SerpApi.
663590
We use RSpec and Github Actions to test our infrastructure around the clock, and that includes all changes to our clients.
664591

665592
The directory spec/ includes specification which serves the dual purposes of examples and functional tests.
666593

667-
Set your secret API key in your shell before running a test.
594+
Set your secret API key in your shell before running a test.
668595
The SerpApi key can be obtained from [serpapi.com/signup](https://serpapi.com/users/sign_up?plan=free).
669596
```bash
670597
export SERPAPI_KEY="your_secret_key"

0 commit comments

Comments
 (0)