Skip to content

Commit a09b2a6

Browse files
victor Benarbiavictor Benarbia
authored andcommitted
first commit
0 parents  commit a09b2a6

29 files changed

+686
-0
lines changed

.gitignore

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Prerequisites
2+
*.d
3+
4+
# Compiled Object files
5+
*.slo
6+
*.lo
7+
*.o
8+
*.obj
9+
10+
# Precompiled Headers
11+
*.gch
12+
*.pch
13+
14+
# Compiled Dynamic libraries
15+
*.so
16+
*.dylib
17+
*.dll
18+
19+
# Fortran module files
20+
*.mod
21+
*.smod
22+
23+
# Compiled Static libraries
24+
*.lai
25+
*.la
26+
*.a
27+
*.lib
28+
29+
# Executables
30+
*.exe
31+
*.out
32+
*.app

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 SerpApi
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
file_set=$(wildcard *.cpp)
2+
app_name=main
3+
4+
.PHONY: build
5+
6+
all: build run
7+
8+
build:
9+
meson compile -C build -v
10+
11+
run:
12+
./build/serpapi-search-cpp
13+
14+
# tested on AARCH64 and x86
15+
install_linux:
16+
sudo apt-get install -f libcurl4-openssl-dev libjsoncpp-dev
17+
brew curl jsoncpp
18+
19+
# tested on Apple M1 aarch64
20+
install_apple:
21+
brew install meson pkg-config curl cmake meson ninja rapidjson
22+
23+
reset:
24+
-rm -rf build/
25+
meson setup build

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# serpapi-search-cpp
2+
3+
Extension to search on Google, Bing, HomeDepot, Baidu, Yandex and more using SerpApi written in C++.
4+
The backend is powered by serpapi.com and required an account
5+
6+
Current Status: `draft`
7+
8+
## Get started.
9+
- Set an environment API_KEY=<secret>
10+
- Install dependency either apple or linux tested.
11+
- `make install_apple`
12+
- `make install_linux`
13+
- Initialize the project: `make reset`
14+
- Compile `make` or `make build run`
15+
- Edit main.cpp for testing.
16+
17+
#### To modify the *Search classes
18+
- edit sooglesearch.cpp/hpp
19+
- update all files using `rake`
20+
21+
## TODO
22+
23+
- [ ] Add unit test
24+
- [ ] Customize classes
25+
- [ ] Package as a library
26+
- [ ] Create OOBT test
27+
- [ ] Publish library online
28+
- [ ] Add REPL.it example
29+
- [ ] Add integration documentation on serpapi.com
30+
- [ ] Write a full README to match serpapi-search-results-dotnet

Rakefile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
require 'erb'
2+
3+
task :default do
4+
puts 'automatic class creation'
5+
files = [
6+
'googlesearch.cpp',
7+
'googlesearch.hpp',
8+
]
9+
source = 'google'
10+
names = %w(bing baidu homedepot yahoo yandex wallmart youtube linkedin)
11+
names.each do |name|
12+
files.each do |fn|
13+
buf = File.read(fn)
14+
buf.gsub!(source, name)
15+
buf.gsub!(source.capitalize, name.capitalize)
16+
buf.gsub!(source.upcase, name.upcase)
17+
fout = fn.gsub(source, name)
18+
puts "save: " + fout
19+
File.write(fout, buf)
20+
end
21+
end
22+
23+
puts 'usage:'
24+
names.each do |name|
25+
puts "#include <#{name}search.cpp>"
26+
end
27+
names.each do |name|
28+
puts "serpapi::#{name.capitalize}Search search(parameter, apiKey);"
29+
end
30+
end

baidusearch.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <serpapisearch.hpp>
2+
#include <baidusearch.hpp>
3+
4+
namespace serpapi
5+
{
6+
using namespace std;
7+
BaiduSearch::BaiduSearch(map<string,string> parameter, string apiKey): SerpApiSearch(parameter, apiKey, "baidu")
8+
{
9+
};
10+
}

baidusearch.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef SERPAPI_BAIDU_SEARCH
2+
#define SERPAPI_BAIDU_SEARCH
3+
4+
#include <iostream>
5+
#include <string>
6+
#include <map>
7+
#include <serpapisearch.hpp>
8+
9+
namespace serpapi
10+
{
11+
using namespace std;
12+
class BaiduSearch : public SerpApiSearch
13+
{
14+
public:
15+
BaiduSearch(map<string,string> parameter, string apiKey);
16+
};
17+
}
18+
#endif

bingsearch.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <serpapisearch.hpp>
2+
#include <bingsearch.hpp>
3+
4+
namespace serpapi
5+
{
6+
using namespace std;
7+
BingSearch::BingSearch(map<string,string> parameter, string apiKey): SerpApiSearch(parameter, apiKey, "bing")
8+
{
9+
};
10+
}

bingsearch.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef SERPAPI_BING_SEARCH
2+
#define SERPAPI_BING_SEARCH
3+
4+
#include <iostream>
5+
#include <string>
6+
#include <map>
7+
#include <serpapisearch.hpp>
8+
9+
namespace serpapi
10+
{
11+
using namespace std;
12+
class BingSearch : public SerpApiSearch
13+
{
14+
public:
15+
BingSearch(map<string,string> parameter, string apiKey);
16+
};
17+
}
18+
#endif

callback.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <cstdint>
2+
#include <iostream>
3+
#include <memory>
4+
#include <string>
5+
6+
using namespace std;
7+
8+
namespace serpapi
9+
{
10+
size_t callback(const char* in, size_t size, size_t num, string* out)
11+
{
12+
const size_t totalBytes(size*num);
13+
out->append(in, totalBytes);
14+
return totalBytes;
15+
}
16+
}

0 commit comments

Comments
 (0)