hexillion 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.md +35 -0
- data/Rakefile +2 -0
- data/hexillion.gemspec +22 -0
- data/lib/hexillion.rb +117 -0
- data/lib/hexillion/version.rb +3 -0
- data/spec/client_spec.rb +126 -0
- data/spec/spec_helper.rb +2 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3f99520faee0f3b877d1f10b01ef5de61b0a0209
|
4
|
+
data.tar.gz: 0232be8e63dca6ac5d6974976dc2565198912658
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 23421ef1f1af30223a3dc14c69b122b3861e0f7d100b83c8a0eaec766b7e32c29cb99db75536005ee9fd76188b71ec96347f4bc0e0ea72fd69f279681946c51b
|
7
|
+
data.tar.gz: 4c25b4a3976b1a41284f4e2daa4190bb379249b45f464b5461040451b8ffa2d2fccce43dd6b841b30571d7065d154db8fd542cafd60873b36d29232d4fce8f38
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Flippa.com Pty. Ltd.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Hexillion API Client Gem for Ruby
|
2
|
+
|
3
|
+
This gem provides a basic Ruby wrapper for the
|
4
|
+
[Hexillion Whois API](http://hexillion.com/whois/).
|
5
|
+
It is largely based on the [Quova gem](http://github.com/d11wtq/quova/) by Chris Corbyn.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
gem install hexillion
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
The core class is `Hexillion::Client`. Create a new instance, passing in your Hexillion API
|
14
|
+
username and password:
|
15
|
+
|
16
|
+
hex = Hexillion::Client.new(:username => 'MYUSERNAME', :password => 'MYPASSWORD')
|
17
|
+
|
18
|
+
Then, use the `whois` method on the instance to query Whois records for a given domain:
|
19
|
+
|
20
|
+
hex.whois('example.com')
|
21
|
+
|
22
|
+
The return value is a hash with all the Whois data returned by the API.
|
23
|
+
|
24
|
+
## Resources
|
25
|
+
|
26
|
+
- [Source](https://github.com/flippa/hexillion)
|
27
|
+
- [Issues](https://github.com/flippa/hexillion/issues)
|
28
|
+
|
29
|
+
## Disclaimer
|
30
|
+
|
31
|
+
The official maintainer of this Gem, Flippa.com is no way affiliated with, nor
|
32
|
+
representative of Hexillion. This code is provided free of charge and shall be used
|
33
|
+
at your own risk.
|
34
|
+
|
35
|
+
Copyright (c) 2011 Flippa.com Pty. Ltd.
|
data/Rakefile
ADDED
data/hexillion.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/hexillion/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Louis Simoneau"]
|
6
|
+
gem.email = ["simoneau.louis@gmail.com"]
|
7
|
+
gem.description = %q{Hexillion WhoIs API Client for Ruby}
|
8
|
+
gem.summary = %q{Provides a simple client for the Hexillion API}
|
9
|
+
gem.homepage = ''
|
10
|
+
|
11
|
+
gem.add_dependency "rest-client", "~> 1.6.3"
|
12
|
+
gem.add_dependency "nokogiri", "~> 1.5.0"
|
13
|
+
|
14
|
+
gem.add_development_dependency "rspec", "~> 2.6"
|
15
|
+
|
16
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
gem.files = `git ls-files`.split("\n")
|
18
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
gem.name = "hexillion"
|
20
|
+
gem.require_paths = ['lib']
|
21
|
+
gem.version = Hexillion::VERSION
|
22
|
+
end
|
data/lib/hexillion.rb
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'rest-client'
|
3
|
+
require 'nokogiri'
|
4
|
+
|
5
|
+
module Hexillion
|
6
|
+
class Client
|
7
|
+
def initialize(options)
|
8
|
+
response = RestClient.post "https://hexillion.com/rf/xml/1.0/auth/", :username => options[:username], :password => options[:password]
|
9
|
+
doc = Nokogiri::XML(response)
|
10
|
+
begin
|
11
|
+
@session_key = doc.at_css('SessionKey').content
|
12
|
+
rescue
|
13
|
+
raise "Authentication failed"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Query the API for a given domain
|
18
|
+
#
|
19
|
+
# @example
|
20
|
+
# client.whois('flippa.com') # => { ... }
|
21
|
+
#
|
22
|
+
#
|
23
|
+
|
24
|
+
def whois(domain)
|
25
|
+
response = RestClient.get "http://hexillion.com/rf/xml/1.0/whois/", :params => {:sessionkey => @session_key, :query => domain}
|
26
|
+
parse_xml(response.body)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def parse_xml(xml)
|
32
|
+
doc = Nokogiri::XML(xml)
|
33
|
+
records = doc.xpath(".//QueryResult[ErrorCode='Success' and FoundMatch='Yes']/WhoisRecord")
|
34
|
+
|
35
|
+
strings = {
|
36
|
+
:registrant_name => "Registrant Name",
|
37
|
+
:registrant_person => "Registrant Person",
|
38
|
+
:registrant_handle => "Registrant Handle",
|
39
|
+
:registrant_address => "Registrant Address",
|
40
|
+
:registrant_city => "Registrant City",
|
41
|
+
:registrant_state_province => "Registrant StateProvince",
|
42
|
+
:registrant_postal_code => "Registrant PostalCode",
|
43
|
+
:registrant_country => "Registrant Country",
|
44
|
+
:registrant_country_code => "Registrant CountryCode",
|
45
|
+
:registrant_email => "Registrant Email",
|
46
|
+
:registrar_name => "Registrar Name",
|
47
|
+
:registrar_whois_server => "Registrar WhoisServer",
|
48
|
+
:registrar_homepage => "Registrar HomePage",
|
49
|
+
:admin_contact_name => "AdminContact Name",
|
50
|
+
:admin_contact_person => "AdminContact Person",
|
51
|
+
:admin_contact_handle => "AdminContact Handle",
|
52
|
+
:admin_contact_address => "AdminContact Address",
|
53
|
+
:admin_contact_state_province => "AdminContact StateProvince",
|
54
|
+
:admin_contact_postal_code => "AdminContact PostalCode",
|
55
|
+
:admin_contact_country_code => "AdminContact CountryCode",
|
56
|
+
:admin_contact_country => "AdminContact Country",
|
57
|
+
:admin_contact_email => "AdminContact Email",
|
58
|
+
:admin_contact_phone => "AdminContact Phone",
|
59
|
+
:admin_contact_fax => "AdminContact Fax",
|
60
|
+
:tech_contact_name => "TechContact Name",
|
61
|
+
:tech_contact_person => "TechContact Person",
|
62
|
+
:tech_contact_handle => "TechContact Handle",
|
63
|
+
:tech_contact_address => "TechContact Address",
|
64
|
+
:tech_contact_state_province => "TechContact StateProvince",
|
65
|
+
:tech_contact_postal_code => "TechContact PostalCode",
|
66
|
+
:tech_contact_country_code => "TechContact CountryCode",
|
67
|
+
:tech_contact_country => "TechContact Country",
|
68
|
+
:tech_contact_email => "TechContact Email",
|
69
|
+
:tech_contact_phone => "TechContact Phone",
|
70
|
+
:tech_contact_fax => "TechContact Fax",
|
71
|
+
:zone_contact_name => "ZoneContact Name",
|
72
|
+
:zone_contact_person => "ZoneContact Person",
|
73
|
+
:zone_contact_handle => "ZoneContact Handle",
|
74
|
+
:zone_contact_address => "ZoneContact Address",
|
75
|
+
:zone_contact_state_province => "ZoneContact StateProvince",
|
76
|
+
:zone_contact_postal_code => "ZoneContact PostalCode",
|
77
|
+
:zone_contact_country_code => "ZoneContact CountryCode",
|
78
|
+
:zone_contact_country => "ZoneContact Country",
|
79
|
+
:zone_contact_email => "ZoneContact Email",
|
80
|
+
:zone_contact_phone => "ZoneContact Phone",
|
81
|
+
:zone_contact_fax => "ZoneContact Fax",
|
82
|
+
:header_text => "HeaderText",
|
83
|
+
:stripped_text => "StrippedText",
|
84
|
+
:raw_text => "RawText"
|
85
|
+
}
|
86
|
+
|
87
|
+
dates = {
|
88
|
+
:created_date => './CreatedDate',
|
89
|
+
:expires_date => './ExpiresDate',
|
90
|
+
:updated_date => './UpdatedDate'
|
91
|
+
}
|
92
|
+
|
93
|
+
result = { :xml_response => xml }
|
94
|
+
|
95
|
+
records.each do |record|
|
96
|
+
result[:nameservers] = record.css('Domain NameServer').map { |x| x.content unless x.content == '' }
|
97
|
+
|
98
|
+
strings.each do | attr, selector |
|
99
|
+
nodes = record.css(selector)
|
100
|
+
next if nodes.empty?
|
101
|
+
if nodes.size == 1 || selector.include?('Email')
|
102
|
+
result[attr] = nodes[0].content unless nodes[0].content == ''
|
103
|
+
else
|
104
|
+
result[attr] = nodes.to_a.reject { |s| s.blank? }.join("\n")
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
dates.each do | attr, selector |
|
109
|
+
next unless node = record.at_xpath(selector)
|
110
|
+
result[attr] = DateTime.parse(node.content) unless node.content == ''
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
result
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
AUTH_RESPONSE = '<?xml version="1.0" encoding="utf-8" ?>
|
4
|
+
<AuthResult>
|
5
|
+
<ErrorCode>Success</ErrorCode>
|
6
|
+
<Message>The service successfully processed your request.</Message>
|
7
|
+
<SessionKey>nOIANdfjL4524ynjlssasjfDFaqe4</SessionKey>
|
8
|
+
</AuthResult>'
|
9
|
+
|
10
|
+
describe Hexillion::Client do
|
11
|
+
describe '#initialize' do
|
12
|
+
it "requests a session key from Hexillion and assigns it as an instance variable" do
|
13
|
+
RestClient
|
14
|
+
.should_receive(:post)
|
15
|
+
.with("https://hexillion.com/rf/xml/1.0/auth/", {:username => "username", :password => "password"})
|
16
|
+
.and_return(AUTH_RESPONSE)
|
17
|
+
hex = Hexillion::Client.new(:username => "username", :password => "password")
|
18
|
+
hex.instance_variable_get('@session_key').should == 'nOIANdfjL4524ynjlssasjfDFaqe4'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#whois" do
|
23
|
+
before(:each) do
|
24
|
+
@response = double()
|
25
|
+
RestClient.stub(:post) { AUTH_RESPONSE }
|
26
|
+
RestClient.stub(:get) { @response }
|
27
|
+
@response.stub(:body) { "" }
|
28
|
+
@hex = Hexillion::Client.new(:username => "username", :password => "password")
|
29
|
+
end
|
30
|
+
|
31
|
+
it "queries the API for the provided domain" do
|
32
|
+
RestClient.should_receive(:get)
|
33
|
+
@hex.whois("example.com")
|
34
|
+
end
|
35
|
+
|
36
|
+
it "concats multiline address fields" do
|
37
|
+
@response.stub(:body) do
|
38
|
+
<<-XML
|
39
|
+
<QueryResult><ErrorCode>Success</ErrorCode><FoundMatch>Yes</FoundMatch><WhoisRecord>
|
40
|
+
<Registrant>
|
41
|
+
<Address>48 Cambridge Street</Address>
|
42
|
+
<Address>Level 3</Address>
|
43
|
+
</Registrant>
|
44
|
+
</WhoisRecord></QueryResult>
|
45
|
+
XML
|
46
|
+
end
|
47
|
+
|
48
|
+
@hex.whois("example.com")[:registrant_address].should == "48 Cambridge Street\nLevel 3"
|
49
|
+
end
|
50
|
+
|
51
|
+
it "provides the registrant email address" do
|
52
|
+
@response.stub(:body) do
|
53
|
+
<<-XML
|
54
|
+
<QueryResult><ErrorCode>Success</ErrorCode><FoundMatch>Yes</FoundMatch><WhoisRecord>
|
55
|
+
<Registrant>
|
56
|
+
<Address>48 Cambridge Street</Address>
|
57
|
+
<Address>Level 3</Address>
|
58
|
+
<Email>me@example.com</Email>
|
59
|
+
</Registrant>
|
60
|
+
</WhoisRecord></QueryResult>
|
61
|
+
XML
|
62
|
+
end
|
63
|
+
|
64
|
+
@hex.whois("example.com")[:registrant_email].should == "me@example.com"
|
65
|
+
end
|
66
|
+
|
67
|
+
it "returns the first email when multiple specified" do
|
68
|
+
@response.stub(:body) do
|
69
|
+
<<-XML
|
70
|
+
<QueryResult><ErrorCode>Success</ErrorCode><FoundMatch>Yes</FoundMatch><WhoisRecord>
|
71
|
+
<AdminContact>
|
72
|
+
<Email>john@example.com</Email>
|
73
|
+
<Email>fred@example.com</Email>
|
74
|
+
</AdminContact>
|
75
|
+
</WhoisRecord></QueryResult>
|
76
|
+
XML
|
77
|
+
end
|
78
|
+
|
79
|
+
@hex.whois("example.com")[:admin_contact_email].should == "john@example.com"
|
80
|
+
end
|
81
|
+
|
82
|
+
it "makes an array of nameservers" do
|
83
|
+
@response.stub(:body) do
|
84
|
+
<<-XML
|
85
|
+
<QueryResult><ErrorCode>Success</ErrorCode><FoundMatch>Yes</FoundMatch><WhoisRecord>
|
86
|
+
<Domain>
|
87
|
+
<NameServer>ns1.registrar.com</NameServer>
|
88
|
+
<NameServer>ns2.registrar.com</NameServer>
|
89
|
+
<NameServer>ns3.registrar.com</NameServer>
|
90
|
+
</Domain>
|
91
|
+
</WhoisRecord></QueryResult>
|
92
|
+
XML
|
93
|
+
end
|
94
|
+
|
95
|
+
@hex.whois("example.com")[:nameservers].should == ['ns1.registrar.com', 'ns2.registrar.com', 'ns3.registrar.com']
|
96
|
+
end
|
97
|
+
|
98
|
+
it "parses date fields" do
|
99
|
+
@response.stub(:body) do
|
100
|
+
<<-XML
|
101
|
+
<QueryResult><ErrorCode>Success</ErrorCode><FoundMatch>Yes</FoundMatch><WhoisRecord>
|
102
|
+
<CreatedDate>1999-10-04T00:00:00Z</CreatedDate>
|
103
|
+
<UpdatedDate>2010-11-25T00:00:00Z</UpdatedDate>
|
104
|
+
<ExpiresDate>2019-10-04T00:00:00Z</ExpiresDate>
|
105
|
+
</WhoisRecord></QueryResult>
|
106
|
+
XML
|
107
|
+
end
|
108
|
+
|
109
|
+
@hex.whois("example.com")[:created_date].should == DateTime::civil(1999,10,4)
|
110
|
+
end
|
111
|
+
|
112
|
+
it "returns the entire xml response as :xml_response" do
|
113
|
+
xml = <<-XML
|
114
|
+
<QueryResult><ErrorCode>Success</ErrorCode><FoundMatch>Yes</FoundMatch><WhoisRecord>
|
115
|
+
<CreatedDate>1999-10-04T00:00:00Z</CreatedDate>
|
116
|
+
<UpdatedDate>2010-11-25T00:00:00Z</UpdatedDate>
|
117
|
+
<ExpiresDate>2019-10-04T00:00:00Z</ExpiresDate>
|
118
|
+
</WhoisRecord></QueryResult>
|
119
|
+
XML
|
120
|
+
|
121
|
+
@response.stub(:body) { xml }
|
122
|
+
|
123
|
+
@hex.whois("example.com")[:xml_response].should == xml
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hexillion
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Louis Simoneau
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.6.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.6.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.5.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.5.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: '2.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.6'
|
55
|
+
description: Hexillion WhoIs API Client for Ruby
|
56
|
+
email:
|
57
|
+
- simoneau.louis@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- hexillion.gemspec
|
68
|
+
- lib/hexillion.rb
|
69
|
+
- lib/hexillion/version.rb
|
70
|
+
- spec/client_spec.rb
|
71
|
+
- spec/spec_helper.rb
|
72
|
+
homepage: ''
|
73
|
+
licenses: []
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.2.2
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: Provides a simple client for the Hexillion API
|
95
|
+
test_files: []
|