dnpedia 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/.gitignore +52 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +36 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/dnpedia-rb.gemspec +33 -0
- data/lib/dnpedia.rb +7 -0
- data/lib/dnpedia/api.rb +99 -0
- data/lib/dnpedia/version.rb +5 -0
- metadata +140 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2a41d89dcded99ea4214a60a56cbefac44b30e99342eb9f1ad28b2ff70b3ebee
|
4
|
+
data.tar.gz: 1bd158fea38c62359110b786fb3c620ab8280eab33972dcad76a70bad1fde082
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8b67ccdfc7c5c3bc74d39bb6bffbb6f1a3c8290b231938858625d5e64a08aaff8ec8200357e365f7d2affb308dd13e0acd6620f1ea84cdaca941c3d583fdb9a7
|
7
|
+
data.tar.gz: c7d20262cac6a5358ff79bf951b40e81dbb22d8c5111f7cc9f168f1a5c11ffd9cfc698254a410d69d4b73a6a84ea12dfd71c662ee31e8e99964837c7c555a2bc
|
data/.gitignore
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
## Specific to RubyMotion:
|
17
|
+
.dat*
|
18
|
+
.repl_history
|
19
|
+
build/
|
20
|
+
*.bridgesupport
|
21
|
+
build-iPhoneOS/
|
22
|
+
build-iPhoneSimulator/
|
23
|
+
|
24
|
+
## Specific to RubyMotion (use of CocoaPods):
|
25
|
+
#
|
26
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
27
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
28
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
29
|
+
#
|
30
|
+
# vendor/Pods/
|
31
|
+
|
32
|
+
## Documentation cache and generated files:
|
33
|
+
/.yardoc/
|
34
|
+
/_yardoc/
|
35
|
+
/doc/
|
36
|
+
/rdoc/
|
37
|
+
|
38
|
+
## Environment normalization:
|
39
|
+
/.bundle/
|
40
|
+
/vendor/bundle
|
41
|
+
/lib/bundler/man/
|
42
|
+
|
43
|
+
# for a library or gem, you might want to ignore these files since the code is
|
44
|
+
# intended to run in multiple environments; otherwise, check them in:
|
45
|
+
Gemfile.lock
|
46
|
+
.ruby-version
|
47
|
+
.ruby-gemset
|
48
|
+
|
49
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
50
|
+
.rvmrc
|
51
|
+
|
52
|
+
.rspec_status
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2019 Manabu Niseki
|
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,36 @@
|
|
1
|
+
# dnpedia-rb
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.com/ninoseki/dnpedia-rb.svg?branch=master)](https://travis-ci.com/ninoseki/dnpedia-rb)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/github/ninoseki/dnpedia-rb/badge.svg?branch=master)](https://coveralls.io/github/ninoseki/dnpedia-rb?branch=master)
|
5
|
+
[![CodeFactor](https://www.codefactor.io/repository/github/ninoseki/dnpedia-rb/badge)](https://www.codefactor.io/repository/github/ninoseki/dnpedia-rb)
|
6
|
+
|
7
|
+
[DNPedia](https://dnpedia.com/) domain search API wrapper for Ruby.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
```bash
|
12
|
+
gem install dnpedia
|
13
|
+
```
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
require "dnpedia"
|
19
|
+
|
20
|
+
api = DNPedia::API.new
|
21
|
+
api.search("%apple%")
|
22
|
+
|
23
|
+
# You can pass following parameters to the search method.
|
24
|
+
# - days: default = 2
|
25
|
+
# - mode: default = "added"
|
26
|
+
# - rows: default = 500
|
27
|
+
# - page: default = 1
|
28
|
+
# - sidx: default = "length"
|
29
|
+
# - sord: default = "asc"
|
30
|
+
api.search("%apple%", mode: "deleted")
|
31
|
+
api.search("%apple%", days: 2, rows: 100)
|
32
|
+
```
|
33
|
+
|
34
|
+
## License
|
35
|
+
|
36
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "dnpedia"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/dnpedia-rb.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path("lib", __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require "dnpedia/version"
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "dnpedia"
|
9
|
+
spec.version = DNPedia::VERSION
|
10
|
+
spec.authors = ["Manabu Niseki"]
|
11
|
+
spec.email = ["manabu.niseki@gmail.com"]
|
12
|
+
|
13
|
+
spec.summary = "DNPedia domain search API wrapper for Ruby"
|
14
|
+
spec.description = "DNPedia doamin search API wrapper for Ruby"
|
15
|
+
spec.homepage = "https://github.com/ninoseki/dnpedia-rb"
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
28
|
+
spec.add_development_dependency "coveralls", "~> 0.8"
|
29
|
+
spec.add_development_dependency "rake", "~> 12.3"
|
30
|
+
spec.add_development_dependency "rspec", "~> 3.8"
|
31
|
+
spec.add_development_dependency "vcr", "~> 5.0"
|
32
|
+
spec.add_development_dependency "webmock", "~> 3.7"
|
33
|
+
end
|
data/lib/dnpedia.rb
ADDED
data/lib/dnpedia/api.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "json"
|
4
|
+
require "net/https"
|
5
|
+
require "uri"
|
6
|
+
require "zlib"
|
7
|
+
|
8
|
+
module DNPedia
|
9
|
+
class API
|
10
|
+
HOST = "dnpedia.com"
|
11
|
+
BASE_URL = "https://#{HOST}"
|
12
|
+
|
13
|
+
DEFAULT_HEADERS = {
|
14
|
+
"Accept-Encoding" => "gzip",
|
15
|
+
"Referer" => "https://dnpedia.com/tlds/search.php",
|
16
|
+
"X-Requested-With" => "XMLHttpRequest",
|
17
|
+
}.freeze
|
18
|
+
|
19
|
+
DEFAULT_PARAMS = {
|
20
|
+
cmd: "search",
|
21
|
+
columns: "id,name,zoneid,length,idn,thedate,",
|
22
|
+
ecf: "name",
|
23
|
+
ecv: "",
|
24
|
+
days: 2,
|
25
|
+
mode: "added",
|
26
|
+
_search: false,
|
27
|
+
nd: 1_569_842_920_216,
|
28
|
+
rows: 500,
|
29
|
+
page: 1,
|
30
|
+
sidx: "length",
|
31
|
+
sord: "asc"
|
32
|
+
}.freeze
|
33
|
+
|
34
|
+
def search(word, **params)
|
35
|
+
params = DEFAULT_PARAMS.merge(params).merge(
|
36
|
+
ecv: normalize(word)
|
37
|
+
)
|
38
|
+
|
39
|
+
_get("/tlds/ajax.php", params) { |json| json }
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def normalize(word)
|
45
|
+
return word if word.start_with?("~")
|
46
|
+
return word unless word.include?("%")
|
47
|
+
|
48
|
+
"~#{word}"
|
49
|
+
end
|
50
|
+
|
51
|
+
def url_for(path)
|
52
|
+
URI(BASE_URL + path)
|
53
|
+
end
|
54
|
+
|
55
|
+
def https_options
|
56
|
+
if proxy = ENV["HTTPS_PROXY"] || ENV["https_proxy"]
|
57
|
+
uri = URI(proxy)
|
58
|
+
{
|
59
|
+
proxy_address: uri.hostname,
|
60
|
+
proxy_port: uri.port,
|
61
|
+
proxy_from_env: false,
|
62
|
+
use_ssl: true
|
63
|
+
}
|
64
|
+
else
|
65
|
+
{ use_ssl: true }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def decompress_gzip_body(body)
|
70
|
+
io = StringIO.new(body)
|
71
|
+
gz = Zlib::GzipReader.new(io)
|
72
|
+
gz.read
|
73
|
+
rescue Zlib::GzipFile::Error => e
|
74
|
+
raise Error, e.message
|
75
|
+
end
|
76
|
+
|
77
|
+
def request(req)
|
78
|
+
Net::HTTP.start(HOST, 443, https_options) do |http|
|
79
|
+
response = http.request(req)
|
80
|
+
|
81
|
+
code = response.code.to_i
|
82
|
+
raise Error, "Unsupported response code returned: #{code}" if code != 200
|
83
|
+
|
84
|
+
body = response.body
|
85
|
+
body = decompress_gzip_body(body) if response["content-encoding"] == "gzip"
|
86
|
+
|
87
|
+
yield JSON.parse body
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def _get(path, params = {}, &block)
|
92
|
+
uri = url_for(path)
|
93
|
+
uri.query = URI.encode_www_form(params)
|
94
|
+
get = Net::HTTP::Get.new(uri, DEFAULT_HEADERS)
|
95
|
+
|
96
|
+
request(get, &block)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dnpedia
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Manabu Niseki
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-09-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: coveralls
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.8'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.8'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '12.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '12.3'
|
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.8'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.8'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: vcr
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '5.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '5.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.7'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.7'
|
97
|
+
description: DNPedia doamin search API wrapper for Ruby
|
98
|
+
email:
|
99
|
+
- manabu.niseki@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".travis.yml"
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- bin/console
|
112
|
+
- bin/setup
|
113
|
+
- dnpedia-rb.gemspec
|
114
|
+
- lib/dnpedia.rb
|
115
|
+
- lib/dnpedia/api.rb
|
116
|
+
- lib/dnpedia/version.rb
|
117
|
+
homepage: https://github.com/ninoseki/dnpedia-rb
|
118
|
+
licenses:
|
119
|
+
- MIT
|
120
|
+
metadata: {}
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
requirements: []
|
136
|
+
rubygems_version: 3.0.4
|
137
|
+
signing_key:
|
138
|
+
specification_version: 4
|
139
|
+
summary: DNPedia domain search API wrapper for Ruby
|
140
|
+
test_files: []
|