robtex 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cc68c7ebf3b49fcd7ddca414143a4ec3d2fe1bf74bd2dcb125af948359db4cff
4
+ data.tar.gz: 81353e3659171520ed2ae7c6b87b959ed77942112ce7be2b2ef2d219ab533a11
5
+ SHA512:
6
+ metadata.gz: 5ca0a1347572744ced81338de312e08d6d0a15e0f9c6cdfe786649bbc6007918b2c29b064330dcb3898faa5a0dc0a561b46ef845790f542474232616ca177fb3
7
+ data.tar.gz: 7a528fe60d2f6359ab4a9cfccf6f38c4a2f8fd4c7eea272625f6a83868b931667ad03fb15c322944d913d5067db476c7356a38a9c4930c979ca04370f2433268
data/.codeclimate.yml ADDED
@@ -0,0 +1,12 @@
1
+ version: "2"
2
+ prepare:
3
+ fetch:
4
+ - url: "https://raw.githubusercontent.com/janlelis/relaxed.ruby.style/master/.rubocop.yml"
5
+ path: "alternate-rubocop-path.yml"
6
+ plugins:
7
+ rubocop:
8
+ enabled: true
9
+ config:
10
+ file: "alternate-rubocop-path.yml"
11
+ exclude_patterns:
12
+ - "spec/**/*"
data/.gitignore ADDED
@@ -0,0 +1,53 @@
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
53
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ cache: bundler
3
+ rvm:
4
+ - 2.4
5
+ script: bundle exec rake spec
6
+ gemfile:
7
+ - Gemfile
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in robtex-rb.gemspec
6
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 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,31 @@
1
+ # Robtex-rb
2
+
3
+ [![Build Status](https://travis-ci.org/ninoseki/robtex-rb.svg?branch=master)](https://travis-ci.org/ninoseki/robtex-rb)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/b5bba652a09c7ef1aa57/maintainability)](https://codeclimate.com/github/ninoseki/robtex-rb/maintainability)
5
+
6
+ Ruby client for the Robtex API
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'robtex'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install robtex
23
+
24
+ ## Usage
25
+
26
+ TODO: Write usage instructions here
27
+
28
+ ## License
29
+
30
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
31
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "robtex"
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
@@ -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
data/exe/robtex ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "robtex"
4
+
5
+ Robtex::CLI.start
data/lib/robtex.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "robtex/api"
2
+ require "robtex/cli"
3
+ require "robtex/exceptions"
4
+ require "robtex/version"
data/lib/robtex/api.rb ADDED
@@ -0,0 +1,69 @@
1
+ require 'net/https'
2
+ require 'json'
3
+
4
+ module Robtex
5
+ class API
6
+ HOST = "freeapi.robtex.com".freeze
7
+ URL = "https://#{HOST}".freeze
8
+
9
+ def as(q)
10
+ get("/asquery/#{q}") { |body| JSON.parse body }
11
+ end
12
+
13
+ def ip(q)
14
+ get("/ipquery/#{q}") { |body| JSON.parse body }
15
+ end
16
+
17
+ def rpdns(q)
18
+ get("/pdns/reverse/#{q}") do |body|
19
+ body.lines.map { |line| JSON.parse line }
20
+ end
21
+ end
22
+
23
+ def fpdns(q)
24
+ get("/pdns/forward/#{q}") do |body|
25
+ body.lines.map { |line| JSON.parse line }
26
+ end
27
+ end
28
+
29
+ def url_for(path)
30
+ URI(URL + path)
31
+ end
32
+
33
+ def https_options
34
+ if proxy = ENV["HTTPS_PROXY"] || ENV["https_proxy"]
35
+ uri = URI(proxy)
36
+ {
37
+ proxy_address: uri.hostname,
38
+ proxy_port: uri.port,
39
+ proxy_from_env: false,
40
+ use_ssl: true
41
+ }
42
+ else
43
+ { use_ssl: true }
44
+ end
45
+ end
46
+
47
+ def request(req)
48
+ Net::HTTP.start(HOST, 443, https_options) do |http|
49
+ response = http.request(req)
50
+
51
+ case response.code
52
+ when '200' then yield response.body
53
+ when '400' then raise ProcessingError, response.body
54
+ when '401' then raise AuthenticationError, response.body
55
+ when '404' then raise NotFound, response.body
56
+ when '429' then raise RateLimited, response.body
57
+ when '500' then raise InternalServerError, response.body
58
+ else
59
+ raise ResponseError, response.body
60
+ end
61
+ end
62
+ end
63
+
64
+ def get(path, &block)
65
+ get = Net::HTTP::Get.new(url_for(path))
66
+ request(get, &block)
67
+ end
68
+ end
69
+ end
data/lib/robtex/cli.rb ADDED
@@ -0,0 +1,49 @@
1
+ require "thor"
2
+
3
+ module Robtex
4
+ class CLI < Thor
5
+ desc "ip [QUERY]", "Query for IP by [QUERY]"
6
+ def ip(query)
7
+ with_error_handling do
8
+ res = api.ip(query)
9
+ puts JSON.pretty_generate(res)
10
+ end
11
+ end
12
+
13
+ desc "as [QUERY]", "Query for AS by [QUERY]"
14
+ def as(query)
15
+ with_error_handling do
16
+ res = api.as(query)
17
+ puts JSON.pretty_generate(res)
18
+ end
19
+ end
20
+
21
+ desc "rpdns [QUERY]", "Query for reverse PDNS by [QUERY]"
22
+ def rpdns(query)
23
+ with_error_handling do
24
+ res = api.rpdns(query)
25
+ puts JSON.pretty_generate(res)
26
+ end
27
+ end
28
+
29
+ desc "fpdns [QUERY]", "Query for forward PDNS by [QUERY]"
30
+ def fpdns(query)
31
+ with_error_handling do
32
+ res = api.fpdns(query)
33
+ puts JSON.pretty_generate(res)
34
+ end
35
+ end
36
+
37
+ no_commands do
38
+ def api
39
+ API.new
40
+ end
41
+
42
+ def with_error_handling
43
+ yield
44
+ rescue ResponseError => e
45
+ puts "Warning: #{e}"
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,13 @@
1
+ module Robtex
2
+ class ResponseError < StandardError; end
3
+
4
+ class AuthenticationError < ResponseError; end
5
+
6
+ class NotFound < ResponseError; end
7
+
8
+ class ProcessingError < ResponseError; end
9
+
10
+ class RateLimited < ResponseError; end
11
+
12
+ class InternalServerError < ResponseError; end
13
+ end
@@ -0,0 +1,3 @@
1
+ module Robtex
2
+ VERSION = "0.1.0"
3
+ end
data/robtex.gemspec ADDED
@@ -0,0 +1,33 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "robtex/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "robtex"
8
+ spec.version = Robtex::VERSION
9
+ spec.authors = ["ninoseki"]
10
+ spec.email = ["manabu.niseki@gmail.com"]
11
+
12
+ spec.summary = "Ruby client for the Robtex API"
13
+ spec.description = "Ruby client for the Robtex API"
14
+ spec.homepage = "https://github.com/ninoseki/robtex-rb"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.16"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ spec.add_development_dependency "vcr", "~> 4.0"
30
+ spec.add_development_dependency "webmock", "~> 3.4"
31
+
32
+ spec.add_runtime_dependency "thor", "~> 0.20"
33
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: robtex
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ninoseki
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-06-12 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: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: vcr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.4'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.4'
83
+ - !ruby/object:Gem::Dependency
84
+ name: thor
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.20'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.20'
97
+ description: Ruby client for the Robtex API
98
+ email:
99
+ - manabu.niseki@gmail.com
100
+ executables:
101
+ - robtex
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".codeclimate.yml"
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - ".travis.yml"
109
+ - Gemfile
110
+ - LICENSE
111
+ - README.md
112
+ - Rakefile
113
+ - bin/console
114
+ - bin/setup
115
+ - exe/robtex
116
+ - lib/robtex.rb
117
+ - lib/robtex/api.rb
118
+ - lib/robtex/cli.rb
119
+ - lib/robtex/exceptions.rb
120
+ - lib/robtex/version.rb
121
+ - robtex.gemspec
122
+ homepage: https://github.com/ninoseki/robtex-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
+ rubyforge_project:
142
+ rubygems_version: 2.7.6
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: Ruby client for the Robtex API
146
+ test_files: []