nic_ar 0.3.0 → 0.4.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.
data/.gitignore CHANGED
@@ -5,6 +5,7 @@
5
5
  .config
6
6
  .DS_Store
7
7
  .ruby-version
8
+ .vimrc
8
9
  .yardoc
9
10
  Gemfile.lock
10
11
  InstalledFiles
data/README.rdoc CHANGED
@@ -5,20 +5,28 @@
5
5
 
6
6
  The NicAr::Client class allows to you programatically extract information about any ".ar" (Argentina) domain name.
7
7
 
8
- It uses the public information as is made available at the {Dirección Nacional del Registro de Dominios de Internet}[http://www.nic.ar] (Nic.ar) website using the third-party {nic!alert API}[http://api.nicalert.com.ar] webservice.
8
+ It uses the public information as is made available at the {Dirección Nacional del Registro de Dominios de Internet}[http://www.nic.ar] (NIC.ar) website using the third-party {nic!alert API}[http://api.nicalert.com.ar] webservice.
9
9
 
10
10
  == Usage
11
11
 
12
- The NicAr::Client class supports lookups for domain names, domain transactions, entities, people, DNS servers.
12
+ The client initialization is pretty straigt-forward, and the only argument is optional.
13
13
 
14
- First, find out what kind of domain names you are allowed to looup.
14
+ nic_ar = NicAr::Client.new
15
+
16
+ The optional argument is an API token that can be obtained to by-pass the CAPTCHA challenge that the NIC.ar website sometimes requests to you solve before answering your domain lookup. Please refer to the nic!alert API {official documentation}[http://api.nicalert.me/docs] for more details.
17
+
18
+ nic_ar = NicAr::Client.new("234d3cdf979e04db3d709ed8")
19
+
20
+ The NicAr::Client class supports lookups for domain names. First, find out what kind of domain names you are allowed to looup.
21
+
22
+ nic_ar.whois
15
23
 
16
- NicAr::Client.domains
17
24
  => [".com.ar", ".gob.ar", ".int.ar", ".mil.ar", ".net.ar", ".org.ar", ".tur.ar"]
18
25
 
19
26
  All the following lookups will raise a NicAr::NotFound exception if the requested resource could not be found.
20
27
 
21
- NicAr::Client.domains("vivaserver.com.ar")
28
+ nic_ar.whois("vivaserver.com.ar")
29
+
22
30
  => {
23
31
  "status"=> {
24
32
  "available"=>false,
@@ -63,25 +71,31 @@ Please note that this output conforms to the latest update of the Nic.ar website
63
71
 
64
72
  You can also check if a given domain name resolves OK to it's DNS servers, thus effectively know if it's available online or not.
65
73
 
66
- NicAr::Client.status("www.nic.ar")
67
- => {
68
- "domain"=>"www.nic.ar",
69
- "online"=>true,
70
- "offline"=>false,
71
- "ip"=>"200.16.109.19",
72
- "host"=>"firpo.nic.ar"
73
- }
74
+ nic_ar.status("www.nic.ar")
75
+
76
+ => {
77
+ "status" => {
78
+ "domain"=>"www.nic.ar",
79
+ "online"=>true,
80
+ "offline"=>false,
81
+ "ip"=>"200.16.109.19",
82
+ "host"=>"firpo.nic.ar"
83
+ }
84
+ }
74
85
 
75
86
  But also note that a domain name without the "www." may or may not resolve in the same way.
76
87
 
77
- NicAr::Client.status("nic.ar")
88
+ nic_ar.status("nic.ar")
89
+
78
90
  => {
79
- "domain"=>"nic.ar",
80
- "online"=>true,
81
- "offline"=>false,
82
- "ip"=>"200.16.109.25",
83
- "host"=>"roldan.nic.ar"
84
- }
91
+ "status" => {
92
+ "domain"=>"nic.ar",
93
+ "online"=>true,
94
+ "offline"=>false,
95
+ "ip"=>"200.16.109.25",
96
+ "host"=>"roldan.nic.ar"
97
+ }
98
+ }
85
99
 
86
100
  Lastly, status checking only works for ".ar" (Argentina) domain names.
87
101
 
data/lib/nic_ar.rb CHANGED
@@ -8,37 +8,34 @@ require 'rest_client'
8
8
 
9
9
  module NicAr
10
10
  # The base URI for the nic!alert API
11
- API_URI = 'http://api.nicalert.com.ar'
11
+ API_URI = 'http://api.nicalert.me/v1'
12
12
 
13
- # Exception for status HTTP 424: Failed Dependency
14
- class CaptchaError < StandardError; end
13
+ # status HTTP 204: No Content
14
+ class NoContent < StandardError; end
15
15
 
16
- # Exception for status HTTP 406: Not Acceptable
16
+ # status HTTP 400: Bad Request
17
17
  class RequestError < StandardError; end
18
18
 
19
- # Exception for status HTTP 417: Expectation Failed (available?, pending?)
20
- class ExpectationError < StandardError; end
21
-
22
- # Exception for status HTTP 204: No Content
23
- class NoContent < StandardError; end
24
-
25
- # Exception for status HTTP 404: Not Found
19
+ # status HTTP 404: Not Found
26
20
  class NotFound < StandardError; end
27
21
 
28
- # Exception for status HTTP 400: Bad Request
29
- class ParameterError < StandardError; end
22
+ # status HTTP 408: Request Timeout
23
+ class TimeoutError < StandardError; end
30
24
 
31
- # Exception for status HTTP 412: Precondition Failed
25
+ # status HTTP 412: Precondition Failed
32
26
  class PreconditionError < StandardError; end
33
27
 
34
- # Exception for status HTTP 500: System Error
28
+ # status HTTP 417: Expectation Failed (available?, pending?)
29
+ class ExpectationError < StandardError; end
30
+
31
+ # status HTTP 424: Failed Dependency
32
+ class CaptchaError < StandardError; end
33
+
34
+ # status HTTP 500: System Error
35
35
  class ServiceError < StandardError; end
36
36
 
37
- # Exception for status HTTP 503: Service Unavailable
37
+ # status HTTP 503: Service Unavailable
38
38
  class UnavailableError < StandardError; end
39
-
40
- # Exception for status HTTP 408: Request Timeout, 503: Service Unavailable
41
- class TimeoutError < StandardError; end
42
39
  end
43
40
 
44
41
  require "nic_ar/client"
data/lib/nic_ar/client.rb CHANGED
@@ -1,74 +1,62 @@
1
1
  module NicAr
2
-
3
2
  # NicAr::Client
4
- # Simple HTTP client for accessing the {public nic!alert API}[http://api.nicalert.com.ar].
5
- # Full API spec. available at {api.nicalert.com.ar/docs}[http://api.nicalert.com.ar/docs]
3
+ # Simple HTTP client for accessing the {public nic!alert API}[http://api.nicalert.me].
4
+ # Full API spec. available at {api.nicalert.com.ar/docs}[http://api.nicalert.me/docs]
6
5
  #
7
6
  # (c)2014 Cristian R. Arroyo <cristian.arroyo@vivaserver.com>
8
7
 
9
8
  class Client
10
- class << self
11
- # Maps class methods to API calls
12
- def method_missing(name, *args)
13
- params = '/' + args.map { |p| CGI.escape(p) }.join('/') unless args.empty?
14
- resource = name.to_s
15
- # send the bang! trailing the request (upcoming API feat.)
16
- if unbanged = resource[/(\w+)!$/,1]
17
- resource = unbanged
18
- params = "#{params}!"
19
- end
20
- get "/#{resource}#{params}"
21
- end
22
-
23
- # Acknowledge supported methods/API calls
24
- def respond_to?(resource)
25
- return true if %w[domains].include? resource.to_s # old resources deprecated by new Nic.ar website
26
- super
27
- end
28
-
29
- private
9
+ attr_reader :token
30
10
 
31
- def get(path) #:nodoc:
32
- response = RestClient.get("#{api_host}/#{path}")
33
- raise NoContent if response.code == 204
34
- JSON.parse(response)
35
- rescue RestClient::Exception => e
36
- message = message_from(e.http_body)
11
+ def initialize(token=nil)
12
+ @token = token
13
+ end
37
14
 
38
- case e.http_code
39
- when 400 # Bad Request
40
- raise ParameterError, message
41
- when 404 # Not Found
42
- raise NotFound
43
- when 406 # Not Acceptable
44
- raise RequestError, message
45
- when 408 # Request Timeout
46
- raise TimeoutError, message
47
- when 412 # Precondition Failed
48
- raise PreconditionError, message
49
- when 417 # Expectation Failed
50
- raise ExpectationError, message
51
- when 424 # Failed Dependency
52
- raise CaptchaError, message
53
- when 500 # System Error
54
- raise ServiceError, message
55
- when 503 # Service Unavailable
56
- raise UnavailableError, message
57
- else
58
- raise e
59
- end
15
+ def whois(name=nil) #:nodoc:
16
+ if name
17
+ request "whois/#{name}" + (@token.nil? || @token.empty?? '' : "?token=#{@token}")
18
+ else
19
+ request "whois"
60
20
  end
21
+ end
61
22
 
62
- def message_from(response) #:nodoc:
63
- JSON.parse(response)['message']
64
- rescue
65
- nil
23
+ private
24
+
25
+ def request(path) #:nodoc:
26
+ response = RestClient.get("#{api_host}/#{path}")
27
+ JSON.parse(response)
28
+ rescue RestClient::Exception => e
29
+ message = message_from(e.http_body)
30
+ case e.http_code
31
+ when 400 # Bad Request
32
+ fail RequestError, message
33
+ when 404 # Not Found
34
+ fail NotFound
35
+ when 408 # Request Timeout
36
+ fail TimeoutError, message
37
+ when 412 # Precondition Failed
38
+ fail PreconditionError, message # PageError
39
+ when 424 # Failed Dependency
40
+ fail CaptchaError, message # CaptchaError
41
+ when 500 # System Error
42
+ fail ServiceError, message
43
+ when 503 # Service Unavailable
44
+ fail UnavailableError, message
45
+ else
46
+ raise e
66
47
  end
48
+ end
67
49
 
68
- # override to support multiple API hosts
69
- def api_host #:nodoc:
70
- API_URI
71
- end
50
+ def message_from(response) #:nodoc:
51
+ result = JSON.parse(response)
52
+ result['error']['message'] if result.has_key? 'error'
53
+ rescue
54
+ nil
55
+ end
56
+
57
+ # override to support multiple API hosts
58
+ def api_host #:nodoc:
59
+ API_URI
72
60
  end
73
61
  end
74
62
  end
@@ -1,4 +1,4 @@
1
1
  module NicAr
2
2
  # This Gem version does not map the API version in any way.
3
- VERSION = '0.3.0'
3
+ VERSION = '0.4.0'
4
4
  end
data/spec/client_spec.rb CHANGED
@@ -1,42 +1,38 @@
1
1
  require_relative 'spec_helper'
2
2
 
3
3
  describe 'NicAr::Client' do
4
- it 'fixes respond_to?' do
5
- refute NicAr::Client.respond_to? :dns_servers # old resources deprecated by new Nic.ar website
6
- assert NicAr::Client.respond_to? :domains
7
- refute NicAr::Client.respond_to? :entities
8
- refute NicAr::Client.respond_to? :people
9
- refute NicAr::Client.respond_to? :transactions
4
+ subject do
5
+ NicAr::Client.new
10
6
  end
11
7
 
12
- describe 'when receiving invalid requests' do
13
- it 'rejects single invalid requests' do
14
- stub_request(:get,/invalid_request$/).to_return(:status => 406)
15
- proc { NicAr::Client.invalid_request }.must_raise NicAr::RequestError
16
- end
17
-
18
- it 'also rejects invalid requests with parameters' do
19
- stub_request(:get,/invalid_request\/with\/parameters$/).to_return(:status => 406)
20
- proc { NicAr::Client.invalid_request 'with', 'parameters' }.must_raise NicAr::RequestError
21
- end
8
+ it 'deprecates some old methods' do
9
+ assert subject.respond_to? :whois
10
+ refute subject.respond_to? :domains
11
+ refute subject.respond_to? :entities
12
+ refute subject.respond_to? :people
13
+ refute subject.respond_to? :transactions
22
14
  end
23
15
 
24
16
  describe 'Domains lookups' do
17
+ it 'sends no token by default' do
18
+ subject.token.must_be_nil
19
+ end
20
+
25
21
  it 'knows what kind of domains to lookup' do
26
- stub_request(:get,/domains$/).to_return(:body => '[".com.ar", ".gob.ar", ".int.ar", ".mil.ar", ".net.ar", ".org.ar", ".tur.ar"]')
27
- result = NicAr::Client.domains
22
+ stub_request(:get,/whois$/).to_return(:body => '[".com.ar", ".gob.ar", ".int.ar", ".mil.ar", ".net.ar", ".org.ar", ".tur.ar"]')
23
+ result = subject.whois
28
24
  result.must_be_instance_of Array
29
25
  result.wont_be_empty
30
26
  end
31
27
 
32
28
  it 'raises on unexisting domains' do
33
- stub_request(:get,/domains\/hispafuentes\.com\.ar$/).to_return(:status => 404)
34
- proc { NicAr::Client.domains 'hispafuentes.com.ar' }.must_raise NicAr::NotFound
29
+ stub_request(:get,/whois\/hispafuentes\.com\.ar$/).to_return(:status => 404)
30
+ proc { subject.whois 'hispafuentes.com.ar' }.must_raise NicAr::NotFound
35
31
  end
36
32
 
37
33
  it 'returns a Hash for Domain lookups' do
38
- stub_request(:get,/domains\/dww\.com\.ar$/).to_return(:body => stub_for('domains/dww.com.ar'))
39
- result = NicAr::Client.domains 'dww.com.ar'
34
+ stub_request(:get,/whois\/dww\.com\.ar$/).to_return(:body => stub_for('domains/dww.com.ar'))
35
+ result = subject.whois 'dww.com.ar'
40
36
  result.must_be_instance_of Hash
41
37
  result['name'].must_equal 'dww.com.ar'
42
38
  end
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: nic_ar
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.3.0
5
+ version: 0.4.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Cristian R. Arroyo
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-01-14 00:00:00.000000000 Z
12
+ date: 2014-03-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  prerelease: false
@@ -109,7 +109,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
109
  - !ruby/object:Gem::Version
110
110
  segments:
111
111
  - 0
112
- hash: 2419756568503364636
112
+ hash: -3292143947690208492
113
113
  version: '0'
114
114
  none: false
115
115
  required_rubygems_version: !ruby/object:Gem::Requirement
@@ -118,12 +118,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
118
  - !ruby/object:Gem::Version
119
119
  segments:
120
120
  - 0
121
- hash: 2419756568503364636
121
+ hash: -3292143947690208492
122
122
  version: '0'
123
123
  none: false
124
124
  requirements: []
125
125
  rubyforge_project:
126
- rubygems_version: 1.8.25
126
+ rubygems_version: 1.8.28
127
127
  signing_key:
128
128
  specification_version: 3
129
129
  summary: A simple client for ".ar" (Argentina) domain names lookups using the nic!alert