searchdata_sdk 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +16 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +72 -0
- data/LICENSE.txt +21 -0
- data/README.md +62 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/env/local.env.sample +1 -0
- data/env/local.env.sample-win +1 -0
- data/examples/bing_demo.rb +16 -0
- data/examples/google_demo.rb +16 -0
- data/examples/yandex_demo.rb +16 -0
- data/lib/searchdata_sdk/bing_search.rb +13 -0
- data/lib/searchdata_sdk/google_search.rb +133 -0
- data/lib/searchdata_sdk/searchdata_api_search.rb +104 -0
- data/lib/searchdata_sdk/version.rb +5 -0
- data/lib/searchdata_sdk/yandex_search.rb +17 -0
- data/lib/searchdata_sdk.rb +13 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9c80f3bf14784e0989c1d681c4f0edcbb4366b2b5cfca4c2c106bac15943d0fa
|
4
|
+
data.tar.gz: b84576343678e405d33eac61b90eec6242bde9206bfe8f356bb2ae291c1e1764
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b7154224ce28f92411e79b90c76a9ad8a2ef3240dfd65fc215a44ee603e16fc192627d332551174a6803011dd971304deab57ff156aa276a433ab7a3dbdc19bc
|
7
|
+
data.tar.gz: 678f215a41361afb05360753cbaeb6a7d3d7ea3963a3008f8e583f1a23e23426ea33a8187a23cc1b7bdca81952fda8be37c86db53116db306b9f6f65a332706e
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 3.0
|
3
|
+
|
4
|
+
Style/EndOfLine:
|
5
|
+
EnforcedStyle: lf
|
6
|
+
|
7
|
+
Style/StringLiterals:
|
8
|
+
Enabled: true
|
9
|
+
EnforcedStyle: double_quotes
|
10
|
+
|
11
|
+
Style/StringLiteralsInInterpolation:
|
12
|
+
Enabled: true
|
13
|
+
EnforcedStyle: double_quotes
|
14
|
+
|
15
|
+
Layout/LineLength:
|
16
|
+
Max: 120
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in searchdata_sdk.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem "dotenv", "~> 2.7.6"
|
9
|
+
gem "json", "~> 2.5.1"
|
10
|
+
gem "open-uri", "~> 0.1.0"
|
11
|
+
gem "rake", "~> 13.0"
|
12
|
+
gem "rubocop", "~> 1.20"
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
searchdata_sdk (0.1.0)
|
5
|
+
dotenv (~> 2.7.6)
|
6
|
+
json (~> 2.5.1)
|
7
|
+
open-uri (~> 0.1.0)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
ast (2.4.2)
|
13
|
+
date (3.1.0)
|
14
|
+
diff-lcs (1.4.4)
|
15
|
+
dotenv (2.7.6)
|
16
|
+
json (2.5.1)
|
17
|
+
open-uri (0.1.0)
|
18
|
+
stringio
|
19
|
+
time
|
20
|
+
uri
|
21
|
+
parallel (1.20.1)
|
22
|
+
parser (3.0.2.0)
|
23
|
+
ast (~> 2.4.1)
|
24
|
+
rainbow (3.0.0)
|
25
|
+
rake (13.0.6)
|
26
|
+
regexp_parser (2.1.1)
|
27
|
+
rexml (3.2.5)
|
28
|
+
rspec (3.10.0)
|
29
|
+
rspec-core (~> 3.10.0)
|
30
|
+
rspec-expectations (~> 3.10.0)
|
31
|
+
rspec-mocks (~> 3.10.0)
|
32
|
+
rspec-core (3.10.1)
|
33
|
+
rspec-support (~> 3.10.0)
|
34
|
+
rspec-expectations (3.10.1)
|
35
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
36
|
+
rspec-support (~> 3.10.0)
|
37
|
+
rspec-mocks (3.10.2)
|
38
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
+
rspec-support (~> 3.10.0)
|
40
|
+
rspec-support (3.10.2)
|
41
|
+
rubocop (1.20.0)
|
42
|
+
parallel (~> 1.10)
|
43
|
+
parser (>= 3.0.0.0)
|
44
|
+
rainbow (>= 2.2.2, < 4.0)
|
45
|
+
regexp_parser (>= 1.8, < 3.0)
|
46
|
+
rexml
|
47
|
+
rubocop-ast (>= 1.9.1, < 2.0)
|
48
|
+
ruby-progressbar (~> 1.7)
|
49
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
50
|
+
rubocop-ast (1.11.0)
|
51
|
+
parser (>= 3.0.1.1)
|
52
|
+
ruby-progressbar (1.11.0)
|
53
|
+
stringio (3.0.0)
|
54
|
+
time (0.1.0)
|
55
|
+
date
|
56
|
+
unicode-display_width (2.0.0)
|
57
|
+
uri (0.10.1)
|
58
|
+
|
59
|
+
PLATFORMS
|
60
|
+
x64-mingw32
|
61
|
+
|
62
|
+
DEPENDENCIES
|
63
|
+
dotenv (~> 2.7.6)
|
64
|
+
json (~> 2.5.1)
|
65
|
+
open-uri (~> 0.1.0)
|
66
|
+
rake (~> 13.0)
|
67
|
+
rspec (~> 3.2)
|
68
|
+
rubocop (~> 1.20)
|
69
|
+
searchdata_sdk!
|
70
|
+
|
71
|
+
BUNDLED WITH
|
72
|
+
2.2.27
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2021 SearchDataAPI
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# SearchData Ruby SDK
|
2
|
+
|
3
|
+
[SearchData](https://www.searchdata.io/) is an API that allows scraping various search engines such as Google, Bing, Yandex, etc. while using rotating proxies to prevent bans. This SDK for Ruby makes the usage of the API easier to implement in any project you have.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
You must have modern Ruby already installed.
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'searchdata_sdk'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install searchdata_sdk
|
22
|
+
|
23
|
+
### API Key
|
24
|
+
|
25
|
+
To use the API and the SDK you will need an API Key. You can get one by registering at [SearchData](https://app.searchdata.io/register).
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
Use the following code to get started with the SDK:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
require "searchdata_sdk"
|
33
|
+
|
34
|
+
params = {
|
35
|
+
api_key: "{API_KEY}", # copy the API_KEY from your Dashboard
|
36
|
+
engine: "google",
|
37
|
+
q: "coffee"
|
38
|
+
}
|
39
|
+
|
40
|
+
client = GoogleSearch.new(params)
|
41
|
+
result = client.get_json
|
42
|
+
|
43
|
+
pp result
|
44
|
+
puts "Google demo passed."
|
45
|
+
exit 0
|
46
|
+
```
|
47
|
+
|
48
|
+
Alternatively, check the [examples](https://github.com/SearchDataAPI/ruby-sdk/tree/main/examples) folder for more code samples, including Yandex and Bing classes.
|
49
|
+
|
50
|
+
For a better understanding of the parameters, please check out our [documentation](https://app.searchdata.io/documentation/getting-started).
|
51
|
+
|
52
|
+
## Development
|
53
|
+
|
54
|
+
After checking out the repo, run `bin/setup` or `bundle install` to install dependencies.
|
55
|
+
|
56
|
+
Then, run `rake spec` or `bundle exec rake` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
57
|
+
|
58
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
59
|
+
|
60
|
+
## Contributing
|
61
|
+
|
62
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/SearchDataAPI/ruby-sdk.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "searchdata_sdk"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
API_KEY=
|
@@ -0,0 +1 @@
|
|
1
|
+
export API_KEY=
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "searchdata_sdk"
|
4
|
+
|
5
|
+
params = {
|
6
|
+
api_key: "{API_KEY}",
|
7
|
+
engine: "bing",
|
8
|
+
q: "coffee"
|
9
|
+
}
|
10
|
+
|
11
|
+
client = BingSearch.new(params)
|
12
|
+
result = client.get_json
|
13
|
+
|
14
|
+
pp result
|
15
|
+
puts "Bing demo passed."
|
16
|
+
exit 0
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "searchdata_sdk"
|
4
|
+
|
5
|
+
params = {
|
6
|
+
api_key: "{API_KEY}",
|
7
|
+
engine: "google",
|
8
|
+
q: "coffee"
|
9
|
+
}
|
10
|
+
|
11
|
+
client = GoogleSearch.new(params)
|
12
|
+
result = client.get_json
|
13
|
+
|
14
|
+
pp result
|
15
|
+
puts "Google demo passed."
|
16
|
+
exit 0
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "searchdata_sdk"
|
4
|
+
|
5
|
+
params = {
|
6
|
+
api_key: "{API_KEY}",
|
7
|
+
engine: "yandex",
|
8
|
+
text: "coffee"
|
9
|
+
}
|
10
|
+
|
11
|
+
client = YandexSearch.new(params)
|
12
|
+
result = client.get_json
|
13
|
+
|
14
|
+
pp result
|
15
|
+
puts "Yandex demo passed."
|
16
|
+
exit 0
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "searchdata_api_search"
|
4
|
+
|
5
|
+
# Bing Search Result powered by SearchData API
|
6
|
+
# Check code samples at examples/bing_demo.rb
|
7
|
+
# Docs: https://app.searchdata.io/documentation/bing-search
|
8
|
+
class BingSearch < SearchDataAPISearch
|
9
|
+
def initialize(params = {})
|
10
|
+
super(params, BING_ENGINE)
|
11
|
+
check_params(%i[q engine])
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "searchdata_api_search"
|
4
|
+
|
5
|
+
# Google Search Result powered by SearchData API
|
6
|
+
# Check code samples at examples/google_demo.ro
|
7
|
+
# Docs: https://app.searchdata.io/documentation/google-search
|
8
|
+
class GoogleSearch < SearchDataAPISearch
|
9
|
+
def initialize(params = {})
|
10
|
+
super(params, GOOGLE_ENGINE)
|
11
|
+
check_params(%i[q engine])
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# Google Maps API Result powered by SearchData API
|
16
|
+
# Check code samples at examples/google_demo.ro
|
17
|
+
# Docs: https://app.searchdata.io/documentation/google-maps-api
|
18
|
+
class GoogleMapsAPI < SearchDataAPISearch
|
19
|
+
def initialize(params = {})
|
20
|
+
super(params, GOOGLE_MAPS_ENGINE)
|
21
|
+
check_params(%i[q engine type])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Google Maps Reviews API Result powered by SearchData API
|
26
|
+
# Check code samples at examples/google_demo.ro
|
27
|
+
# Docs: https://app.searchdata.io/documentation/google-maps-reviews-api
|
28
|
+
class GoogleMapsReviewsAPI < SearchDataAPISearch
|
29
|
+
def initialize(params = {})
|
30
|
+
super(params, GOOGLE_MAPS_REVIEWS_ENGINE)
|
31
|
+
check_params(%i[q engine])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Google Autocomplete API Result powered by SearchData API
|
36
|
+
# Check code samples at examples/google_demo.ro
|
37
|
+
# Docs: https://app.searchdata.io/documentation/google-autocomplete-api
|
38
|
+
class GoogleAutocompleteAPI < SearchDataAPISearch
|
39
|
+
def initialize(params = {})
|
40
|
+
super(params, GOOGLE_AUTOCOMPLETE_ENGINE)
|
41
|
+
check_params(%i[q engine])
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Google Scholar API Result powered by SearchData API
|
46
|
+
# Check code samples at examples/google_demo.ro
|
47
|
+
# Docs: https://app.searchdata.io/documentation/google-scholar-api
|
48
|
+
class GoogleScholarAPI < SearchDataAPISearch
|
49
|
+
def initialize(params = {})
|
50
|
+
super(params, GOOGLE_SCHOLAR_ENGINE)
|
51
|
+
check_params(%i[q engine])
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# Google Scholar Profiles API Result powered by SearchData API
|
56
|
+
# Check code samples at examples/google_demo.ro
|
57
|
+
# Docs: https://app.searchdata.io/documentation/google-scholar-profiles-api
|
58
|
+
class GoogleScholarProfilesAPI < SearchDataAPISearch
|
59
|
+
def initialize(params = {})
|
60
|
+
super(params, GOOGLE_SCHOLAR_PROFILES_ENGINE)
|
61
|
+
check_params(%i[mauthors engine])
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# Google Scholar Author API Result powered by SearchData API
|
66
|
+
# Check code samples at examples/google_demo.ro
|
67
|
+
# Docs: https://app.searchdata.io/documentation/google-scholar-author-api
|
68
|
+
class GoogleScholarAuthorAPI < SearchDataAPISearch
|
69
|
+
def initialize(params = {})
|
70
|
+
super(params, GOOGLE_SCHOLAR_AUTHOR_ENGINE)
|
71
|
+
check_params(%i[author_id engine])
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Google Scholar Cite API Result powered by SearchData API
|
76
|
+
# Check code samples at examples/google_demo.ro
|
77
|
+
# Docs: https://app.searchdata.io/documentation/google-scholar-cite-api
|
78
|
+
class GoogleScholarCiteAPI < SearchDataAPISearch
|
79
|
+
def initialize(params = {})
|
80
|
+
super(params, GOOGLE_SCHOLAR_CITE_ENGINE)
|
81
|
+
check_params(%i[q engine])
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# Google Product API Result powered by SearchData API
|
86
|
+
# Check code samples at examples/google_demo.ro
|
87
|
+
# Docs: https://app.searchdata.io/documentation/google-product-api
|
88
|
+
class GoogleProductAPI < SearchDataAPISearch
|
89
|
+
def initialize(params = {})
|
90
|
+
super(params, GOOGLE_PRODUCT_ENGINE)
|
91
|
+
check_params(%i[product_id engine])
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# Google Reverse Image API Result powered by SearchData API
|
96
|
+
# Check code samples at examples/google_demo.ro
|
97
|
+
# Docs: https://app.searchdata.io/documentation/google-reverse-image-api
|
98
|
+
class GoogleReverseImageAPI < SearchDataAPISearch
|
99
|
+
def initialize(params = {})
|
100
|
+
super(params, GOOGLE_REVERSE_IMAGE_ENGINE)
|
101
|
+
check_params(%i[image_url engine])
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
# Google Jobs API Result powered by SearchData API
|
106
|
+
# Check code samples at examples/google_demo.ro
|
107
|
+
# Docs: https://app.searchdata.io/documentation/google-jobs-api
|
108
|
+
class GoogleJobsAPI < SearchDataAPISearch
|
109
|
+
def initialize(params = {})
|
110
|
+
super(params, GOOGLE_JOBS_ENGINE)
|
111
|
+
check_params(%i[q engine])
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
# Google Jobs Listing API Result powered by SearchData API
|
116
|
+
# Check code samples at examples/google_demo.ro
|
117
|
+
# Docs: https://app.searchdata.io/documentation/google-jobs-listing-api
|
118
|
+
class GoogleJobsListingAPI < SearchDataAPISearch
|
119
|
+
def initialize(params = {})
|
120
|
+
super(params, GOOGLE_JOBS_LISTING_ENGINE)
|
121
|
+
check_params(%i[q engine])
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
# Google Events API Result powered by SearchData API
|
126
|
+
# Check code samples at examples/google_demo.ro
|
127
|
+
# Docs: https://app.searchdata.io/documentation/google-events-api
|
128
|
+
class GoogleEventsAPI < SearchDataAPISearch
|
129
|
+
def initialize(params = {})
|
130
|
+
super(params, GOOGLE_EVENTS_ENGINE)
|
131
|
+
check_params(%i[q engine])
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "open-uri"
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
GOOGLE_ENGINE = "google"
|
7
|
+
GOOGLE_MAPS_ENGINE = "google_maps"
|
8
|
+
GOOGLE_MAPS_REVIEWS_ENGINE = "google_maps_reviews"
|
9
|
+
GOOGLE_AUTOCOMPLETE_ENGINE = "google_autocomplete"
|
10
|
+
GOOGLE_SCHOLAR_ENGINE = "google_scholar"
|
11
|
+
GOOGLE_SCHOLAR_PROFILES_ENGINE = "google_scholar_profiles"
|
12
|
+
GOOGLE_SCHOLAR_AUTHOR_ENGINE = "google_scholar_author"
|
13
|
+
GOOGLE_SCHOLAR_CITE_ENGINE = "google_scholar_cite"
|
14
|
+
GOOGLE_PRODUCT_ENGINE = "google_product"
|
15
|
+
GOOGLE_REVERSE_IMAGE_ENGINE = "google_reverse_image"
|
16
|
+
GOOGLE_JOBS_ENGINE = "google_jobs"
|
17
|
+
GOOGLE_JOBS_LISTING_ENGINE = "google_jobs_listing"
|
18
|
+
GOOGLE_EVENTS_ENGINE = "google_events"
|
19
|
+
BING_ENGINE = "bing"
|
20
|
+
YANDEX_ENGINE = "yandex"
|
21
|
+
|
22
|
+
# Abstract HTTP client for api.searchdata.io
|
23
|
+
class SearchDataAPISearch
|
24
|
+
MAIN_API = "api.searchdata.io"
|
25
|
+
MAIN_API_PATH = "/v1"
|
26
|
+
LOCATIONS_API = "locations.searchdata.io"
|
27
|
+
|
28
|
+
attr_accessor :params
|
29
|
+
|
30
|
+
def initialize(params, engine = nil)
|
31
|
+
@params = params
|
32
|
+
@params[:engine] ||= engine
|
33
|
+
raise "`engine` must be defined in params or a second argument" if @params[:engine].nil?
|
34
|
+
end
|
35
|
+
|
36
|
+
def check_params(keys = [])
|
37
|
+
return if @params.keys == [:engine]
|
38
|
+
raise "keys must be a list of String or Symbol" unless keys.instance_of?(Array)
|
39
|
+
|
40
|
+
missing = []
|
41
|
+
keys.each do |key|
|
42
|
+
case key.class.to_s
|
43
|
+
when "String"
|
44
|
+
missing << key.to_s if @params[key].nil? && @params[key.to_sym].nil?
|
45
|
+
when "Symbol"
|
46
|
+
missing << key.to_s if @params[key].nil? && @params[key.to_s].nil?
|
47
|
+
else
|
48
|
+
raise "keys must contains Symbol or String"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
raise "missing required keys in params.\n #{missing.join(",")}" unless missing.empty?
|
53
|
+
end
|
54
|
+
|
55
|
+
def get_location
|
56
|
+
@params.delete(:engine)
|
57
|
+
@params.delete(:api_key)
|
58
|
+
JSON.parse(get_results(LOCATIONS_API, ""))
|
59
|
+
end
|
60
|
+
|
61
|
+
def get_json
|
62
|
+
get_results(MAIN_API, MAIN_API_PATH)
|
63
|
+
end
|
64
|
+
|
65
|
+
def get_hash
|
66
|
+
JSON.parse(get_json)
|
67
|
+
end
|
68
|
+
|
69
|
+
def get_results(api, path)
|
70
|
+
url = construct_url(api, path)
|
71
|
+
URI(url).open(read_timeout: 600).read
|
72
|
+
rescue OpenURI::HTTPError => e
|
73
|
+
error = JSON.parse(e.io.read)["error"]
|
74
|
+
if error
|
75
|
+
puts "server returns error from url : #{url}"
|
76
|
+
raise error
|
77
|
+
else
|
78
|
+
puts "fail: fetch url: #{url}"
|
79
|
+
end
|
80
|
+
rescue StandardError => e
|
81
|
+
puts "fail: fetch url: #{url}"
|
82
|
+
raise e
|
83
|
+
end
|
84
|
+
|
85
|
+
def construct_url(api, path)
|
86
|
+
@params[:api_key] = $searchdata_api_key unless $searchdata_api_key.nil?
|
87
|
+
|
88
|
+
@params.delete_if { |_, value| value.nil? }
|
89
|
+
|
90
|
+
URI::HTTPS.build(host: api, path: path, query: URI.encode_www_form(@params))
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.searchdata_api_key=(api_key)
|
94
|
+
self.api_key = api_key
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.api_key=(api_key)
|
98
|
+
$searchdata_api_key = api_key
|
99
|
+
end
|
100
|
+
|
101
|
+
def api_key
|
102
|
+
@params[:api_key] || @params[:searchdata_api_key] || $searchdata_api_key
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "searchdata_api_search"
|
4
|
+
|
5
|
+
# Yandex Search Result powered by SearchData API
|
6
|
+
# Check code samples at examples/yandex_demo.ro
|
7
|
+
# Docs: https://app.searchdata.io/documentation/yandex
|
8
|
+
class YandexSearch < SearchDataAPISearch
|
9
|
+
def initialize(params = {})
|
10
|
+
super(params, YANDEX_ENGINE)
|
11
|
+
check_params(%i[text engine])
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_location
|
15
|
+
raise "`location` is not supported by #{YANDEX_ENGINE}"
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Main module which acts as a namespace for all our classes
|
4
|
+
module SearchdataSdk
|
5
|
+
require_relative "searchdata_sdk/version"
|
6
|
+
require_relative "searchdata_sdk/searchdata_api_search"
|
7
|
+
require_relative "searchdata_sdk/google_search"
|
8
|
+
require_relative "searchdata_sdk/bing_search"
|
9
|
+
require_relative "searchdata_sdk/yandex_search"
|
10
|
+
|
11
|
+
class Error < StandardError; end
|
12
|
+
# Your code goes here...
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: searchdata_sdk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Raluca Penciuc
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-09-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: dotenv
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.7.6
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.7.6
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.5.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.5.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: open-uri
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.1.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.1.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.2'
|
69
|
+
description: SearchData is a REST API that collects any kind of data from search engines
|
70
|
+
and transforms it into a complete data toolkit for every team in your company. This
|
71
|
+
SDK for Ruby makes the usage of the API easier to implement in any project you have.
|
72
|
+
email:
|
73
|
+
- penciuc.raluca@yahoo.com
|
74
|
+
executables: []
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- ".rspec"
|
79
|
+
- ".rubocop.yml"
|
80
|
+
- CHANGELOG.md
|
81
|
+
- Gemfile
|
82
|
+
- Gemfile.lock
|
83
|
+
- LICENSE.txt
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- bin/console
|
87
|
+
- bin/setup
|
88
|
+
- env/local.env.sample
|
89
|
+
- env/local.env.sample-win
|
90
|
+
- examples/bing_demo.rb
|
91
|
+
- examples/google_demo.rb
|
92
|
+
- examples/yandex_demo.rb
|
93
|
+
- lib/searchdata_sdk.rb
|
94
|
+
- lib/searchdata_sdk/bing_search.rb
|
95
|
+
- lib/searchdata_sdk/google_search.rb
|
96
|
+
- lib/searchdata_sdk/searchdata_api_search.rb
|
97
|
+
- lib/searchdata_sdk/version.rb
|
98
|
+
- lib/searchdata_sdk/yandex_search.rb
|
99
|
+
homepage: https://github.com/SearchDataAPI/searchdata_sdk
|
100
|
+
licenses:
|
101
|
+
- MIT
|
102
|
+
metadata:
|
103
|
+
homepage_uri: https://github.com/SearchDataAPI/searchdata_sdk
|
104
|
+
source_code_uri: https://github.com/SearchDataAPI/searchdata_sdk
|
105
|
+
changelog_uri: https://github.com/SearchDataAPI/searchdata_sdk/blob/main/CHANGELOG.md
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: 3.0.0
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubygems_version: 3.2.22
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: Ruby SDK for SearchData API.
|
125
|
+
test_files: []
|