zoomeye-rb 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8fb0000a0778a5f22bfa139290c2d117c514548da3a3399d8c9dbd8f5255ad7d
4
+ data.tar.gz: 6571f7f69a6898a28a509603c262d2de56cfd4513aa3484e2eedf63037341c2e
5
+ SHA512:
6
+ metadata.gz: e63100f48bcd4cf82d86e6538c6f0d54d7bfd5e6ba622374cdd4baaa7a62c7e90b9d7c1f9477d6689b3433bb1bbb11babd92d23953cf0b5ed9eb4489b4518e1c
7
+ data.tar.gz: fd724c156cf3c0d6d19fee2bc9a5aee426ce2634b4af2c224cbbc6dd22896e313a4ba18e2c908a17db5d83b3ccb093b9a3940ddce971744fe3a9df8135a20142
@@ -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
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.4
7
+ before_install: gem install bundler -v 2.0.2
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in zoomeye.gemspec
6
+ gemspec
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.
@@ -0,0 +1,44 @@
1
+ # zoomeye-rb
2
+
3
+ [![Build Status](https://travis-ci.com/ninoseki/zoomeye-rb.svg?branch=master)](https://travis-ci.com/ninoseki/zoomeye-rb)
4
+ [![Coverage Status](https://coveralls.io/repos/github/ninoseki/zoomeye-rb/badge.svg?branch=master)](https://coveralls.io/github/ninoseki/zoomeye-rb?branch=master)
5
+ [![CodeFactor](https://www.codefactor.io/repository/github/ninoseki/zoomeye-rb/badge)](https://www.codefactor.io/repository/github/ninoseki/zoomeye-rb)
6
+
7
+ [ZoomEye](https://www.zoomeye.org/) API wrapper for Ruby.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ gem install zoomeye
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```ruby
18
+ require "zoomeye"
19
+
20
+ # when given nothing, it tries to load your usernamem & password via ENV["ZOOMEYE_USERNAME"] and ENV["ZOOMEYE_PASSWORD"]
21
+ api = ZoomEye::API.new
22
+
23
+ # or you can set them manually
24
+ api = ZoomEye::API.new(username: "USERNAME", password: "PASSWORD")
25
+
26
+ # Host search
27
+ api.host.search("port:80 nginx")
28
+ api.host.search("port:80 nginx", page: 7, facets: "app,device")
29
+
30
+ # Web search
31
+ api.web.search("wordpress")
32
+ api.web.search("wordpress", page: 1, facets: "app.os")
33
+
34
+ # Resource info
35
+ api.resource_info.get
36
+ ```
37
+
38
+ ## Contributing
39
+
40
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ninoseki/zoomeye-rb.
41
+
42
+ ## License
43
+
44
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "zoomeye"
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__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "zoomeye/version"
4
+
5
+ require "zoomeye/clients/base"
6
+
7
+ require "zoomeye/clients/host"
8
+ require "zoomeye/clients/resource_info"
9
+ require "zoomeye/clients/user"
10
+ require "zoomeye/clients/web"
11
+
12
+ require "zoomeye/api"
13
+
14
+ module ZoomEye
15
+ class Error < StandardError; end
16
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ZoomEye
4
+ class API
5
+ def initialize(username: ENV["ZOOMEYE_USERNAME"], password: ENV["ZOOMEYE_PASSWORD"])
6
+ @username = username
7
+ raise ArgumentError, "No usernamme has been found or provided!" unless @username
8
+
9
+ @password = password
10
+ raise ArgumentError, "No password has been found or provided!" unless @password
11
+ end
12
+
13
+ def user
14
+ @user ||= Clients::User.new(username: @username, password: @password)
15
+ end
16
+
17
+ def web
18
+ @web ||= Clients::Web.new(access_token: access_token)
19
+ end
20
+
21
+ def host
22
+ @host ||= Clients::Host.new(access_token: access_token)
23
+ end
24
+
25
+ def resource_info
26
+ @resource_info ||= Clients::ResourceInfo.new(access_token: access_token)
27
+ end
28
+
29
+ private
30
+
31
+ def access_token
32
+ @access_token ||= user.access_token
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "net/https"
5
+ require "uri"
6
+
7
+ module ZoomEye
8
+ module Clients
9
+ class Base
10
+ HOST = "api.zoomeye.org"
11
+ BASE_URL = "https://#{HOST}"
12
+
13
+ def initialize(username: nil, password: nil, access_token: nil)
14
+ @username = username
15
+ @password = password
16
+ @access_token = access_token
17
+ end
18
+
19
+ private
20
+
21
+ def url_for(path)
22
+ URI(BASE_URL + path)
23
+ end
24
+
25
+ def https_options
26
+ if proxy = ENV["HTTPS_PROXY"] || ENV["https_proxy"]
27
+ uri = URI(proxy)
28
+ {
29
+ proxy_address: uri.hostname,
30
+ proxy_port: uri.port,
31
+ proxy_from_env: false,
32
+ use_ssl: true
33
+ }
34
+ else
35
+ { use_ssl: true }
36
+ end
37
+ end
38
+
39
+ def make_request(req)
40
+ Net::HTTP.start(HOST, 443, https_options) do |http|
41
+ response = http.request(req)
42
+
43
+ code = response.code.to_i
44
+ body = response.body
45
+ json = JSON.parse(body)
46
+
47
+ case code
48
+ when 200
49
+ yield json
50
+ else
51
+ error = json.dig("message") || body
52
+ raise Error, "Unsupported response code returned: #{code} - #{error}"
53
+ end
54
+ end
55
+ end
56
+
57
+ def token_headers
58
+ {
59
+ Authorization: "JWT #{@access_token}"
60
+ }
61
+ end
62
+
63
+ def build_request(type: "GET", path:, params: {})
64
+ uri = url_for(path)
65
+ uri.query = URI.encode_www_form(params) if type == "GET"
66
+
67
+ headers = path == "/user/login" ? {} : token_headers
68
+
69
+ request = case type
70
+ when "GET"
71
+ Net::HTTP::Get.new(uri, headers)
72
+ when "POST"
73
+ Net::HTTP::Post.new(uri, headers)
74
+ else
75
+ raise ArgumentError, "#{type} HTTP method is not supported"
76
+ end
77
+
78
+ request.body = JSON.generate(params) unless type == "GET"
79
+
80
+ request
81
+ end
82
+
83
+ def _get(path, params = {}, &block)
84
+ request = build_request(type: "GET", path: path, params: params)
85
+ make_request(request, &block)
86
+ end
87
+
88
+ def _post(path, params = {}, &block)
89
+ request = build_request(type: "POST", path: path, params: params)
90
+ make_request(request, &block)
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ZoomEye
4
+ module Clients
5
+ class Host < Base
6
+ #
7
+ # Search the Host devices
8
+ #
9
+ # @param [String] query Query string
10
+ # @param [Integer, nil] page The page number to paging(default:1)
11
+ # @param [String, nil] facets A comma-separated list of properties to get summary information on query
12
+ #
13
+ # @return [Hash]
14
+ #
15
+ def search(query, page: nil, facets: nil)
16
+ params = {
17
+ query: query,
18
+ page: page,
19
+ facets: facets
20
+ }.compact
21
+
22
+ _get("/host/search", params) { |json| json }
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ZoomEye
4
+ module Clients
5
+ class ResourceInfo < Base
6
+ #
7
+ # Resources info for account
8
+ #
9
+ # @return [Hash]
10
+ #
11
+ def get
12
+ _get("/resources-info") { |json| json }
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ZoomEye
4
+ module Clients
5
+ class User < Base
6
+ def access_token
7
+ _post("/user/login", username: @username, password: @password) { |json| json.dig("access_token") }
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ZoomEye
4
+ module Clients
5
+ class Web < Base
6
+ #
7
+ # Search the Web technologies
8
+ #
9
+ # @param [String] query Query string
10
+ # @param [Integer, nil] page The page number to paging(default:1)
11
+ # @param [String, nil] facets A comma-separated list of properties to get summary information on query
12
+ #
13
+ # @return [Hash]
14
+ #
15
+ def search(query, page: nil, facets: nil)
16
+ params = {
17
+ query: query,
18
+ page: page,
19
+ facets: facets
20
+ }.compact
21
+
22
+ _get("/web/search", params) { |json| json }
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ZoomEye
4
+ VERSION = "0.1.1"
5
+ end
@@ -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 "zoomeye/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "zoomeye-rb"
9
+ spec.version = ZoomEye::VERSION
10
+ spec.authors = ["Manabu Niseki"]
11
+ spec.email = ["manabu.niseki@gmail.com"]
12
+
13
+ spec.summary = "ZoomEye API wrapper for Ruby"
14
+ spec.description = "ZoomEye API wrapper for Ruby"
15
+ spec.homepage = "https://github.com/ninoseki/zoomeye-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", "~> 13.0"
30
+ spec.add_development_dependency "rspec", "~> 3.9"
31
+ spec.add_development_dependency "vcr", "~> 5.0"
32
+ spec.add_development_dependency "webmock", "~> 3.7"
33
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zoomeye-rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Manabu Niseki
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-10-17 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: '13.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '13.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.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.9'
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: ZoomEye 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
+ - lib/zoomeye.rb
114
+ - lib/zoomeye/api.rb
115
+ - lib/zoomeye/clients/base.rb
116
+ - lib/zoomeye/clients/host.rb
117
+ - lib/zoomeye/clients/resource_info.rb
118
+ - lib/zoomeye/clients/user.rb
119
+ - lib/zoomeye/clients/web.rb
120
+ - lib/zoomeye/version.rb
121
+ - zoomeye.gemspec
122
+ homepage: https://github.com/ninoseki/zoomeye-rb
123
+ licenses:
124
+ - MIT
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubygems_version: 3.0.6
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: ZoomEye API wrapper for Ruby
145
+ test_files: []