hexillion 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a9e568653299f167d50a5b6101f844cb237e42f9
4
- data.tar.gz: 95fcf1bbe848f96430cb3d787725ad0c4e5bd210
3
+ metadata.gz: 4e8cfd9597be0f53d98aa7a46153a7ed32a1f66d
4
+ data.tar.gz: 5b64a7a7bebd0b67f082c3d19d9ffa2e689b995c
5
5
  SHA512:
6
- metadata.gz: 9e9f64c0257fe716ab970a9f2513d19ce95beff433f99f278c63eac4fc9404b1558f80fa940dda8cd7d80a18c7129fd908a3522345ddea5cfce75e1717cb569c
7
- data.tar.gz: bdb8ba56779d42b04c7e45e6ab3880f5c267fcf672163fb6995318b52b5343392ce39f8e7a22ea2eb5d47901bd1f5e9040723227a0d4eb5478fa0b903bc7dbfc
6
+ metadata.gz: 3f8f4e9d592aae5b187a176aa637decbb211fc555d1d22b2cc3998adb45b2f77f04b221da0fc5e4065a18a464496287c983754d9f0d23ea020ee76f7186cdd4f
7
+ data.tar.gz: 9a17946de7e3c0eb7f5fe10f71a04db3aafcca1534878588cd0b06fbe5912a069f667826fa23a0037991dc11c069f61c9a2802f4c931a3fc8fae01a1167095e3
@@ -1,6 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - '1.9.3'
4
- - '2.0.0'
5
3
  - '2.1.0'
6
4
  - '2.2.0'
5
+ - '2.3.0'
6
+ - '2.4.0'
@@ -1,3 +1,8 @@
1
+ # 1.3.0
2
+
3
+ * Replace rest-client usage with net/http.
4
+ * End support for Ruby < 2.1.
5
+
1
6
  # 1.2.0
2
7
 
3
8
  * Loosen nokogiri dependency version to >= 1.5.
@@ -2,16 +2,15 @@
2
2
  require File.expand_path('../lib/hexillion/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
- gem.authors = ["Louis Simoneau"]
6
- gem.email = ["simoneau.louis@gmail.com"]
5
+ gem.authors = ["Flippa Developers"]
6
+ gem.email = ["developers@flippa.com"]
7
7
  gem.description = %q{Hexillion WhoIs API Client for Ruby}
8
8
  gem.summary = %q{Provides a simple client for the Hexillion API}
9
- gem.homepage = ''
9
+ gem.homepage = 'https://github.com/flippa/hexillion'
10
10
 
11
- gem.add_dependency "rest-client", "~> 1.7"
12
- gem.add_dependency "nokogiri", ">= 1.5"
11
+ gem.add_dependency "nokogiri", ">= 1.5"
13
12
 
14
- gem.add_development_dependency "rspec", "~> 2.6"
13
+ gem.add_development_dependency "rspec", "~> 3.6"
15
14
  gem.add_development_dependency "rake"
16
15
 
17
16
  gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
@@ -1,99 +1,118 @@
1
1
  require 'date'
2
- require 'rest-client'
2
+ require 'net/http'
3
3
  require 'nokogiri'
4
+ require 'openssl'
5
+ require 'uri'
4
6
 
5
7
  module Hexillion
6
8
  class Client
9
+ AUTH_ENDPOINT = "https://hexillion.com/rf/xml/1.0/auth/".freeze
10
+ DATA_ENDPOINT = "http://hexillion.com/rf/xml/1.0/whois/".freeze
11
+
7
12
  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
13
+ @session_key = fetch_session_key(options)
14
+ rescue
15
+ raise "Authentication failed"
15
16
  end
16
17
 
17
18
  # Query the API for a given domain
18
19
  #
19
20
  # @example
20
- # client.whois('flippa.com', {optional_param: value, ...}) # => { ... }
21
+ # client.whois('flippa.com', {optional_param: value, ...})
21
22
  #
22
23
  #
23
24
 
24
25
  def whois(domain, extra_params = {})
25
- base_params = {:sessionkey => @session_key, :query => domain}
26
- params = base_params.merge(extra_params)
26
+ params = {sessionkey: @session_key, query: domain}.merge(extra_params)
27
+
28
+ uri = URI(DATA_ENDPOINT)
29
+ uri.query = URI.encode_www_form(params)
27
30
 
28
- response = RestClient.get "http://hexillion.com/rf/xml/1.0/whois/", :params => params
31
+ response = Net::HTTP.get_response(uri)
29
32
  parse_xml(response.body)
30
33
  end
31
34
 
32
35
  private
33
36
 
37
+ def fetch_session_key(options = {})
38
+ uri = URI(AUTH_ENDPOINT)
39
+
40
+ http = Net::HTTP.new(uri.host, uri.port).tap do |http|
41
+ http.use_ssl = true
42
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
43
+ end
44
+
45
+ request = Net::HTTP::Post.new(uri.request_uri)
46
+ request.set_form_data(username: options[:username], password: options[:password])
47
+ response = http.request(request)
48
+
49
+ doc = Nokogiri::XML(response.body)
50
+ doc.at_css('SessionKey').content
51
+ end
52
+
34
53
  def parse_xml(xml)
35
54
  doc = Nokogiri::XML(xml)
36
55
  records = doc.xpath(".//QueryResult[ErrorCode='Success' and FoundMatch='Yes']/WhoisRecord")
37
56
 
38
57
  strings = {
39
- :registrant_name => "Registrant Name",
40
- :registrant_person => "Registrant Person",
41
- :registrant_handle => "Registrant Handle",
42
- :registrant_address => "Registrant Address",
43
- :registrant_city => "Registrant City",
44
- :registrant_state_province => "Registrant StateProvince",
45
- :registrant_postal_code => "Registrant PostalCode",
46
- :registrant_country => "Registrant Country",
47
- :registrant_country_code => "Registrant CountryCode",
48
- :registrant_email => "Registrant Email",
49
- :registrar_name => "Registrar Name",
50
- :registrar_whois_server => "Registrar WhoisServer",
51
- :registrar_homepage => "Registrar HomePage",
52
- :admin_contact_name => "AdminContact Name",
53
- :admin_contact_person => "AdminContact Person",
54
- :admin_contact_handle => "AdminContact Handle",
55
- :admin_contact_address => "AdminContact Address",
56
- :admin_contact_state_province => "AdminContact StateProvince",
57
- :admin_contact_postal_code => "AdminContact PostalCode",
58
- :admin_contact_country_code => "AdminContact CountryCode",
59
- :admin_contact_country => "AdminContact Country",
60
- :admin_contact_email => "AdminContact Email",
61
- :admin_contact_phone => "AdminContact Phone",
62
- :admin_contact_fax => "AdminContact Fax",
63
- :tech_contact_name => "TechContact Name",
64
- :tech_contact_person => "TechContact Person",
65
- :tech_contact_handle => "TechContact Handle",
66
- :tech_contact_address => "TechContact Address",
67
- :tech_contact_state_province => "TechContact StateProvince",
68
- :tech_contact_postal_code => "TechContact PostalCode",
69
- :tech_contact_country_code => "TechContact CountryCode",
70
- :tech_contact_country => "TechContact Country",
71
- :tech_contact_email => "TechContact Email",
72
- :tech_contact_phone => "TechContact Phone",
73
- :tech_contact_fax => "TechContact Fax",
74
- :zone_contact_name => "ZoneContact Name",
75
- :zone_contact_person => "ZoneContact Person",
76
- :zone_contact_handle => "ZoneContact Handle",
77
- :zone_contact_address => "ZoneContact Address",
78
- :zone_contact_state_province => "ZoneContact StateProvince",
79
- :zone_contact_postal_code => "ZoneContact PostalCode",
80
- :zone_contact_country_code => "ZoneContact CountryCode",
81
- :zone_contact_country => "ZoneContact Country",
82
- :zone_contact_email => "ZoneContact Email",
83
- :zone_contact_phone => "ZoneContact Phone",
84
- :zone_contact_fax => "ZoneContact Fax",
85
- :header_text => "HeaderText",
86
- :stripped_text => "StrippedText",
87
- :raw_text => "RawText"
58
+ registrant_name: "Registrant Name",
59
+ registrant_person: "Registrant Person",
60
+ registrant_handle: "Registrant Handle",
61
+ registrant_address: "Registrant Address",
62
+ registrant_city: "Registrant City",
63
+ registrant_state_province: "Registrant StateProvince",
64
+ registrant_postal_code: "Registrant PostalCode",
65
+ registrant_country: "Registrant Country",
66
+ registrant_country_code: "Registrant CountryCode",
67
+ registrant_email: "Registrant Email",
68
+ registrar_name: "Registrar Name",
69
+ registrar_whois_server: "Registrar WhoisServer",
70
+ registrar_homepage: "Registrar HomePage",
71
+ admin_contact_name: "AdminContact Name",
72
+ admin_contact_person: "AdminContact Person",
73
+ admin_contact_handle: "AdminContact Handle",
74
+ admin_contact_address: "AdminContact Address",
75
+ admin_contact_state_province: "AdminContact StateProvince",
76
+ admin_contact_postal_code: "AdminContact PostalCode",
77
+ admin_contact_country_code: "AdminContact CountryCode",
78
+ admin_contact_country: "AdminContact Country",
79
+ admin_contact_email: "AdminContact Email",
80
+ admin_contact_phone: "AdminContact Phone",
81
+ admin_contact_fax: "AdminContact Fax",
82
+ tech_contact_name: "TechContact Name",
83
+ tech_contact_person: "TechContact Person",
84
+ tech_contact_handle: "TechContact Handle",
85
+ tech_contact_address: "TechContact Address",
86
+ tech_contact_state_province: "TechContact StateProvince",
87
+ tech_contact_postal_code: "TechContact PostalCode",
88
+ tech_contact_country_code: "TechContact CountryCode",
89
+ tech_contact_country: "TechContact Country",
90
+ tech_contact_email: "TechContact Email",
91
+ tech_contact_phone: "TechContact Phone",
92
+ tech_contact_fax: "TechContact Fax",
93
+ zone_contact_name: "ZoneContact Name",
94
+ zone_contact_person: "ZoneContact Person",
95
+ zone_contact_handle: "ZoneContact Handle",
96
+ zone_contact_address: "ZoneContact Address",
97
+ zone_contact_state_province: "ZoneContact StateProvince",
98
+ zone_contact_postal_code: "ZoneContact PostalCode",
99
+ zone_contact_country_code: "ZoneContact CountryCode",
100
+ zone_contact_country: "ZoneContact Country",
101
+ zone_contact_email: "ZoneContact Email",
102
+ zone_contact_phone: "ZoneContact Phone",
103
+ zone_contact_fax: "ZoneContact Fax",
104
+ header_text: "HeaderText",
105
+ stripped_text: "StrippedText",
106
+ raw_text: "RawText",
88
107
  }
89
108
 
90
109
  dates = {
91
- :created_date => './CreatedDate',
92
- :expires_date => './ExpiresDate',
93
- :updated_date => './UpdatedDate'
110
+ created_date: './CreatedDate',
111
+ expires_date: './ExpiresDate',
112
+ updated_date: './UpdatedDate',
94
113
  }
95
114
 
96
- result = { :xml_response => xml }
115
+ result = { xml_response: xml }
97
116
 
98
117
  records.each do |record|
99
118
  result[:nameservers] = record.css('Domain NameServer').map { |x| x.content unless x.content == '' }
@@ -1,3 +1,3 @@
1
1
  module Hexillion
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -10,60 +10,66 @@ AUTH_RESPONSE = '<?xml version="1.0" encoding="utf-8" ?>
10
10
  describe Hexillion::Client do
11
11
  describe '#initialize' do
12
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)
13
+ http = double(Net::HTTP, :'use_ssl=' => 1, :'verify_mode=' => 1)
14
+ post = double(Net::HTTP::Post, 'set_form_data' => 1)
15
+ resp = double(body: AUTH_RESPONSE)
16
+
17
+ allow(Net::HTTP).to receive(:new) { http }
18
+ allow(Net::HTTP::Post).to receive(:new) { post }
19
+
20
+ expect(http).to receive(:request).with(post).and_return(resp)
21
+
17
22
  hex = Hexillion::Client.new(:username => "username", :password => "password")
18
- hex.instance_variable_get('@session_key').should == 'nOIANdfjL4524ynjlssasjfDFaqe4'
23
+ expect(hex.instance_variable_get('@session_key')).to eq('nOIANdfjL4524ynjlssasjfDFaqe4')
19
24
  end
20
25
  end
21
26
 
22
27
  describe "#whois" do
23
28
  before(:each) do
24
- @response = double()
25
- RestClient.stub(:post) { AUTH_RESPONSE }
26
- RestClient.stub(:get) { @response }
27
- @response.stub(:body) { "" }
29
+ allow_any_instance_of(Net::HTTP)
30
+ .to receive(:request)
31
+ .with(an_instance_of(Net::HTTP::Post))
32
+ .and_return(double(body: AUTH_RESPONSE))
33
+
34
+ @response_body = ""
35
+
36
+ allow(@response).to receive(:body) { @response_body }
37
+ allow(Net::HTTP).to receive(:get_response) { @response }
38
+
28
39
  @hex = Hexillion::Client.new(:username => "username", :password => "password")
29
40
  end
30
41
 
31
42
  it "queries the API and passes all the params to the endpoint" do
32
43
  domain_name = "example.com"
33
44
  extra_params = {:data => "awesome", :more_data => "awesomer"}
34
- endpoint_url = kind_of(String)
35
- sessionkey = kind_of(String)
36
-
37
- payload = [
38
- endpoint_url,
39
- :params => {
40
- :sessionkey => sessionkey,
41
- :query => domain_name
42
- }.merge(extra_params)
43
- ]
44
-
45
- expect(RestClient).to receive(:get).with(*payload)
45
+
46
+ request_uri = URI([
47
+ "http://hexillion.com/rf/xml/1.0/whois/",
48
+ "?sessionkey=nOIANdfjL4524ynjlssasjfDFaqe4",
49
+ "&query=#{domain_name}",
50
+ "&data=#{extra_params[:data]}",
51
+ "&more_data=#{extra_params[:more_data]}",
52
+ ].join)
53
+
54
+ expect(Net::HTTP).to receive(:get_response).with(request_uri)
46
55
  @hex.whois(domain_name, extra_params)
47
56
  end
48
57
 
49
58
  it "concats multiline address fields" do
50
- @response.stub(:body) do
51
- <<-XML
59
+ @response_body = <<-XML
52
60
  <QueryResult><ErrorCode>Success</ErrorCode><FoundMatch>Yes</FoundMatch><WhoisRecord>
53
61
  <Registrant>
54
62
  <Address>48 Cambridge Street</Address>
55
63
  <Address>Level 3</Address>
56
64
  </Registrant>
57
65
  </WhoisRecord></QueryResult>
58
- XML
59
- end
66
+ XML
60
67
 
61
- @hex.whois("example.com")[:registrant_address].should == "48 Cambridge Street\nLevel 3"
68
+ expect(@hex.whois("example.com")[:registrant_address]).to eq("48 Cambridge Street\nLevel 3")
62
69
  end
63
70
 
64
71
  it "provides the registrant email address" do
65
- @response.stub(:body) do
66
- <<-XML
72
+ @response_body = <<-XML
67
73
  <QueryResult><ErrorCode>Success</ErrorCode><FoundMatch>Yes</FoundMatch><WhoisRecord>
68
74
  <Registrant>
69
75
  <Address>48 Cambridge Street</Address>
@@ -71,30 +77,26 @@ describe Hexillion::Client do
71
77
  <Email>me@example.com</Email>
72
78
  </Registrant>
73
79
  </WhoisRecord></QueryResult>
74
- XML
75
- end
80
+ XML
76
81
 
77
- @hex.whois("example.com")[:registrant_email].should == "me@example.com"
82
+ expect(@hex.whois("example.com")[:registrant_email]).to eq("me@example.com")
78
83
  end
79
84
 
80
85
  it "returns the first email when multiple specified" do
81
- @response.stub(:body) do
82
- <<-XML
86
+ @response_body = <<-XML
83
87
  <QueryResult><ErrorCode>Success</ErrorCode><FoundMatch>Yes</FoundMatch><WhoisRecord>
84
88
  <AdminContact>
85
89
  <Email>john@example.com</Email>
86
90
  <Email>fred@example.com</Email>
87
91
  </AdminContact>
88
92
  </WhoisRecord></QueryResult>
89
- XML
90
- end
93
+ XML
91
94
 
92
- @hex.whois("example.com")[:admin_contact_email].should == "john@example.com"
95
+ expect(@hex.whois("example.com")[:admin_contact_email]).to eq("john@example.com")
93
96
  end
94
97
 
95
98
  it "makes an array of nameservers" do
96
- @response.stub(:body) do
97
- <<-XML
99
+ @response_body = <<-XML
98
100
  <QueryResult><ErrorCode>Success</ErrorCode><FoundMatch>Yes</FoundMatch><WhoisRecord>
99
101
  <Domain>
100
102
  <NameServer>ns1.registrar.com</NameServer>
@@ -102,24 +104,21 @@ describe Hexillion::Client do
102
104
  <NameServer>ns3.registrar.com</NameServer>
103
105
  </Domain>
104
106
  </WhoisRecord></QueryResult>
105
- XML
106
- end
107
+ XML
107
108
 
108
- @hex.whois("example.com")[:nameservers].should == ['ns1.registrar.com', 'ns2.registrar.com', 'ns3.registrar.com']
109
+ expect(@hex.whois("example.com")[:nameservers]).to eq(['ns1.registrar.com', 'ns2.registrar.com', 'ns3.registrar.com'])
109
110
  end
110
111
 
111
112
  it "parses date fields" do
112
- @response.stub(:body) do
113
- <<-XML
113
+ @response_body = <<-XML
114
114
  <QueryResult><ErrorCode>Success</ErrorCode><FoundMatch>Yes</FoundMatch><WhoisRecord>
115
115
  <CreatedDate>1999-10-04T00:00:00Z</CreatedDate>
116
116
  <UpdatedDate>2010-11-25T00:00:00Z</UpdatedDate>
117
117
  <ExpiresDate>2019-10-04T00:00:00Z</ExpiresDate>
118
118
  </WhoisRecord></QueryResult>
119
- XML
120
- end
119
+ XML
121
120
 
122
- @hex.whois("example.com")[:created_date].should == DateTime::civil(1999,10,4)
121
+ expect(@hex.whois("example.com")[:created_date]).to eq(DateTime::civil(1999,10,4))
123
122
  end
124
123
 
125
124
  it "returns the entire xml response as :xml_response" do
@@ -129,11 +128,11 @@ describe Hexillion::Client do
129
128
  <UpdatedDate>2010-11-25T00:00:00Z</UpdatedDate>
130
129
  <ExpiresDate>2019-10-04T00:00:00Z</ExpiresDate>
131
130
  </WhoisRecord></QueryResult>
132
- XML
131
+ XML
133
132
 
134
- @response.stub(:body) { xml }
133
+ @response_body = xml
135
134
 
136
- @hex.whois("example.com")[:xml_response].should == xml
135
+ expect(@hex.whois("example.com")[:xml_response]).to eq(xml)
137
136
  end
138
137
  end
139
138
  end
@@ -1,2 +1,4 @@
1
1
  require 'bundler/setup'
2
- require 'hexillion'
2
+ require 'hexillion'
3
+
4
+ RSpec::Mocks.configuration.allow_message_expectations_on_nil = true
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hexillion
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
- - Louis Simoneau
7
+ - Flippa Developers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-09 00:00:00.000000000 Z
11
+ date: 2017-07-09 00:00:00.000000000 Z
12
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.7'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.7'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: nokogiri
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +30,14 @@ dependencies:
44
30
  requirements:
45
31
  - - "~>"
46
32
  - !ruby/object:Gem::Version
47
- version: '2.6'
33
+ version: '3.6'
48
34
  type: :development
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
38
  - - "~>"
53
39
  - !ruby/object:Gem::Version
54
- version: '2.6'
40
+ version: '3.6'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: rake
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -68,7 +54,7 @@ dependencies:
68
54
  version: '0'
69
55
  description: Hexillion WhoIs API Client for Ruby
70
56
  email:
71
- - simoneau.louis@gmail.com
57
+ - developers@flippa.com
72
58
  executables: []
73
59
  extensions: []
74
60
  extra_rdoc_files: []
@@ -85,7 +71,7 @@ files:
85
71
  - lib/hexillion/version.rb
86
72
  - spec/client_spec.rb
87
73
  - spec/spec_helper.rb
88
- homepage: ''
74
+ homepage: https://github.com/flippa/hexillion
89
75
  licenses: []
90
76
  metadata: {}
91
77
  post_install_message:
@@ -104,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
90
  version: '0'
105
91
  requirements: []
106
92
  rubyforge_project:
107
- rubygems_version: 2.4.5
93
+ rubygems_version: 2.6.8
108
94
  signing_key:
109
95
  specification_version: 4
110
96
  summary: Provides a simple client for the Hexillion API