namecheap 0.0.1 → 0.0.2
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 +4 -0
- data/Rakefile +5 -0
- data/config/namecheap.yml.orig +14 -0
- data/lib/monkey_patch.rb +21 -0
- data/lib/namecheap.rb +24 -68
- data/lib/namecheap/domains.rb +8 -0
- data/lib/namecheap/version.rb +1 -1
- data/namecheap.gemspec +1 -1
- data/spec/domains_spec.rb +7 -0
- data/spec/namecheap_spec.rb +17 -66
- data/spec/spec_helper.rb +4 -5
- metadata +10 -10
- data/lib/namecheap.yml +0 -4
- data/spec/namecheap_domain_check_response_spec.rb +0 -78
- data/spec/namecheap_response_spec.rb +0 -25
data/.gitignore
CHANGED
data/Rakefile
CHANGED
data/lib/monkey_patch.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
class Hash
|
2
|
+
def symbolize_keys!
|
3
|
+
keys.each do |key|
|
4
|
+
self[(key.to_sym rescue key) || key] = delete(key)
|
5
|
+
end
|
6
|
+
self
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_param(namespace = nil)
|
10
|
+
collect do |key, value|
|
11
|
+
value.to_query(namespace ? "#{namespace}[#{key}]" : key)
|
12
|
+
end.sort * '&'
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
|
17
|
+
def to_query(key)
|
18
|
+
require 'cgi' unless defined?(CGI) && defined?(CGI::escape)
|
19
|
+
"#{CGI.escape(key.to_param)}=#{CGI.escape(to_param.to_s)}"
|
20
|
+
end
|
21
|
+
end
|
data/lib/namecheap.rb
CHANGED
@@ -1,77 +1,33 @@
|
|
1
|
-
require "namecheap/version"
|
2
1
|
require 'httparty'
|
3
2
|
|
4
3
|
module Namecheap
|
5
|
-
|
6
|
-
|
7
|
-
class
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
def message
|
20
|
-
if @response["ApiResponse"]["Errors"].any?
|
21
|
-
@response["ApiResponse"]["Errors"]["Error"]
|
4
|
+
SANDBOX = 'https://api.sandbox.namecheap.com/xml.response'
|
5
|
+
PRODUCTION = 'https://api.namecheap.com/xml.response'
|
6
|
+
class Api
|
7
|
+
attr_reader :username, :key, :client_ip
|
8
|
+
def initialize(options = {})
|
9
|
+
config_file = options[:config_file] || "#{File.dirname(__FILE__)}/../config/namecheap.yml"
|
10
|
+
environment = options[:environment] || ENV['RACK_ENV'] || 'development'
|
11
|
+
config = options[:config_file] || YAML.load_file(config_file)[environment].symbolize_keys!
|
12
|
+
@key = options[:key] || config[:key]
|
13
|
+
@username = options[:username] || config[:username]
|
14
|
+
@client_ip = options[:client_ip] || config[:client_ip]
|
15
|
+
@endpoint = (environment == 'production' ? PRODUCTION : SANDBOX)
|
22
16
|
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def items
|
26
|
-
response = @response["ApiResponse"]["CommandResponse"]
|
27
|
-
raise NilNamecheapResponse if response.nil?
|
28
|
-
response.delete_if { |key, value| key == "Type" }
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
17
|
|
33
|
-
|
34
|
-
attr_accessor :domain, :available, :error, :description
|
18
|
+
protected
|
35
19
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
def items
|
46
|
-
super.collect {|item| DomainCheck.new(item[1])}
|
20
|
+
def api_call(command, command_args)
|
21
|
+
args = {}
|
22
|
+
args['ApiUser'] = args['UserName'] = @username
|
23
|
+
args['ApiKey'] = @key
|
24
|
+
args['ClientIp'] = @client_ip
|
25
|
+
args['Command'] = command
|
26
|
+
query = @endpoint + '?' + args.to_param
|
27
|
+
HTTParty.get(query)
|
28
|
+
end
|
47
29
|
end
|
48
30
|
end
|
49
31
|
|
50
|
-
|
51
|
-
|
52
|
-
def initialize(options = {})
|
53
|
-
config = YAML.load_file("#{File.dirname(__FILE__)}/namecheap.yml").symbolize_keys!
|
54
|
-
@key = options[:key] || config[:key]
|
55
|
-
@username = options[:username] || config[:username]
|
56
|
-
@client_ip = options[:client_ip] || config[:client_ip]
|
57
|
-
end
|
58
|
-
|
59
|
-
def is_domain_available?(domain)
|
60
|
-
results = domain_check(domain).items
|
61
|
-
results.nil? ? false : results.first.available?
|
62
|
-
end
|
63
|
-
|
64
|
-
def domain_check(domain)
|
65
|
-
domain = domain.join(",") if domain.is_a? Array
|
66
|
-
NamecheapDomainCheckResponse.new(do_query("namecheap.domains.check", "&DomainList=#{domain}"))
|
67
|
-
end
|
68
|
-
|
69
|
-
protected
|
70
|
-
|
71
|
-
def do_query(api_method, options)
|
72
|
-
query = "https://api.sandbox.namecheap.com/xml.response?ApiUser=#{@username}&ApiKey=#{@key}&UserName=#{@username}&ClientIp=#{@client_ip}&Command=#{api_method}"
|
73
|
-
query += options
|
74
|
-
HTTParty.get(query)
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
32
|
+
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/namecheap")
|
33
|
+
Dir.glob("#{File.dirname(__FILE__)}/namecheap/*.rb") { |lib| require File.basename(lib, '.*') }
|
data/lib/namecheap/version.rb
CHANGED
data/namecheap.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.name = "namecheap"
|
7
7
|
s.version = Namecheap::VERSION
|
8
8
|
s.authors = ["parasquid"]
|
9
|
-
s.email = ["tristan.
|
9
|
+
s.email = ["tristan.gomez@gmail.com"]
|
10
10
|
s.homepage = "https://github.com/parasquid/namecheap"
|
11
11
|
s.summary = %q{Ruby wrapper for the Namecheap API}
|
12
12
|
s.description = %q{Ruby wrapper for the Namecheap API}
|
data/spec/namecheap_spec.rb
CHANGED
@@ -1,85 +1,36 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
require File.dirname(__FILE__) + '/../lib/namecheap'
|
3
|
-
require 'mocha'
|
4
2
|
|
5
3
|
describe "NamecheapAPI Wrapper" do
|
6
4
|
describe "initializating settings" do
|
7
|
-
describe "with defaults" do
|
5
|
+
describe "with defaults" do
|
8
6
|
it "should contain a username" do
|
9
|
-
|
10
|
-
|
11
|
-
end
|
7
|
+
namecheap = Namecheap::Api.new(:environment => 'test')
|
8
|
+
namecheap.send(:username).should == 'apiuser'
|
9
|
+
end
|
12
10
|
it "should contain a key" do
|
13
|
-
|
14
|
-
|
11
|
+
namecheap = Namecheap::Api.new(:environment => 'test')
|
12
|
+
namecheap.send(:key).should == 'apikey'
|
15
13
|
end
|
16
14
|
it "should contain a client_ip" do
|
17
|
-
|
18
|
-
|
15
|
+
namecheap = Namecheap::Api.new(:environment => 'test')
|
16
|
+
namecheap.send(:client_ip).should == '127.0.0.1'
|
19
17
|
end
|
20
18
|
end
|
21
19
|
|
22
|
-
describe "with defaults overidden" do
|
20
|
+
describe "with defaults overidden" do
|
23
21
|
it "shoud contain a overidden username" do
|
24
|
-
|
25
|
-
|
26
|
-
end
|
22
|
+
namecheap = Namecheap::Api.new(:environment => 'test', :username => 'testuser')
|
23
|
+
namecheap.send(:username).should == 'testuser'
|
24
|
+
end
|
27
25
|
|
28
26
|
it "shoud contain a key" do
|
29
|
-
|
30
|
-
|
27
|
+
namecheap = Namecheap::Api.new(:environment => 'test', :key => 'testkey')
|
28
|
+
namecheap.send(:key).should == 'testkey'
|
31
29
|
end
|
32
30
|
it "shoud contain a client_ip" do
|
33
|
-
|
34
|
-
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe "Attempt to connect with bad credentials" do
|
40
|
-
it "should report an error on erroneous account information" do
|
41
|
-
namecheap = Namecheap.new
|
42
|
-
namecheap.domain_check("fakedomain").status.should == "ERROR"
|
31
|
+
namecheap = Namecheap::Api.new(:environmeny => 'test', :client_ip => '66.11.22.44')
|
32
|
+
namecheap.send(:client_ip).should == '66.11.22.44'
|
43
33
|
end
|
44
|
-
|
45
|
-
it "should give error message for invalid api key when using an invalid key" do
|
46
|
-
namecheap = Namecheap.new
|
47
|
-
namecheap.domain_check("fakedomain").message.should include("API Key is invalid")
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe "Attempt to connect with valid credentials" do
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
describe "#domain_check" do
|
56
|
-
it "should build query with multiple domains" do
|
57
|
-
namecheap = Namecheap.new()
|
58
|
-
namecheap.expects(:do_query).with("namecheap.domains.check", "&DomainList=domain1.com,domain2.com")
|
59
|
-
namecheap.domain_check(['domain1.com','domain2.com'])
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe "#is_domain_available?" do
|
64
|
-
it "should return false if connection fails" do
|
65
|
-
namecheap = Namecheap.new(:apikey => 'BADKEY')
|
66
|
-
lambda {
|
67
|
-
namecheap.is_domain_available?('fakedomain.tld').should be_false
|
68
|
-
}.should raise_error(NilNamecheapResponse)
|
69
|
-
end
|
70
|
-
|
71
|
-
it "should return true if connections succeeds and domain is available" do
|
72
|
-
pending "Need API Access To Namecheap.com"
|
73
|
-
namecheap = Namecheap.new
|
74
|
-
namecheap.is_domain_available?('saucytuborswithashoefetish.com').should be_true
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should return false if connections succeeds and domain is not available" do
|
78
|
-
namecheap = Namecheap.new
|
79
|
-
lambda {
|
80
|
-
namecheap.is_domain_available?('hashrocket.com').should be_false
|
81
|
-
}.should raise_error(NilNamecheapResponse)
|
82
34
|
end
|
83
35
|
end
|
84
|
-
end
|
85
|
-
|
36
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
begin
|
2
|
-
require '
|
2
|
+
require 'rspec'
|
3
3
|
rescue LoadError
|
4
4
|
require 'rubygems'
|
5
5
|
gem 'rspec'
|
6
6
|
require 'spec'
|
7
7
|
end
|
8
8
|
|
9
|
-
require '
|
10
|
-
|
11
|
-
|
12
|
-
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
9
|
+
require File.dirname(__FILE__) + '/../lib/namecheap'
|
10
|
+
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib/namecheap")
|
11
|
+
require 'namecheap/domains'
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: namecheap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- parasquid
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-10-
|
18
|
+
date: 2011-10-14 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rspec
|
@@ -47,7 +47,7 @@ dependencies:
|
|
47
47
|
version_requirements: *id002
|
48
48
|
description: Ruby wrapper for the Namecheap API
|
49
49
|
email:
|
50
|
-
- tristan.
|
50
|
+
- tristan.gomez@gmail.com
|
51
51
|
executables: []
|
52
52
|
|
53
53
|
extensions: []
|
@@ -60,12 +60,13 @@ files:
|
|
60
60
|
- Gemfile
|
61
61
|
- README.textile
|
62
62
|
- Rakefile
|
63
|
+
- config/namecheap.yml.orig
|
64
|
+
- lib/monkey_patch.rb
|
63
65
|
- lib/namecheap.rb
|
64
|
-
- lib/namecheap.
|
66
|
+
- lib/namecheap/domains.rb
|
65
67
|
- lib/namecheap/version.rb
|
66
68
|
- namecheap.gemspec
|
67
|
-
- spec/
|
68
|
-
- spec/namecheap_response_spec.rb
|
69
|
+
- spec/domains_spec.rb
|
69
70
|
- spec/namecheap_spec.rb
|
70
71
|
- spec/spec_helper.rb
|
71
72
|
homepage: https://github.com/parasquid/namecheap
|
@@ -102,7 +103,6 @@ signing_key:
|
|
102
103
|
specification_version: 3
|
103
104
|
summary: Ruby wrapper for the Namecheap API
|
104
105
|
test_files:
|
105
|
-
- spec/
|
106
|
-
- spec/namecheap_response_spec.rb
|
106
|
+
- spec/domains_spec.rb
|
107
107
|
- spec/namecheap_spec.rb
|
108
108
|
- spec/spec_helper.rb
|
data/lib/namecheap.yml
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
require File.dirname(__FILE__) + '/../lib/namecheap'
|
3
|
-
|
4
|
-
describe NamecheapDomainCheckResponse do
|
5
|
-
|
6
|
-
describe "successful response from namecheap" do
|
7
|
-
before(:each) do
|
8
|
-
@domain_check_response_hash = {"ApiResponse"=>{"Status"=>"OK",
|
9
|
-
"Errors"=>{},
|
10
|
-
"CommandResponse" => {"Type" => "namecheap.domains.check",
|
11
|
-
"DomainCheckResult1" => {"Domain" => "domain1.com", "Available" => "true"},
|
12
|
-
"DomainCheckResult2" => {"Domain" => "domain2.com", "Available" => "false"},
|
13
|
-
"DomainCheckResult3" => {"Domain" => "domain.wtf", "Available" => "error",
|
14
|
-
"ErrorNo" => "750", "Description" => "No response from the registry"}},
|
15
|
-
"GMTTimeDifference"=>"--6:00",
|
16
|
-
"RequestedCommand"=>"namecheap.domains.check",
|
17
|
-
"Server"=>"SERVER159",
|
18
|
-
"ExecutionTime"=>"0.01",
|
19
|
-
"xmlns"=>"http://api.namecheap.com/xml.response"}}
|
20
|
-
|
21
|
-
@response = NamecheapDomainCheckResponse.new(@domain_check_response_hash)
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should have a domain check result" do
|
26
|
-
@response.items.length.should == 3
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should report that domain1.com is available" do
|
30
|
-
@response.items[1].available.should be_true
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should report that domain2.com is not available" do
|
34
|
-
@response.items[2].available.should be_false
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should report errors if there are any" do
|
38
|
-
@response.items[0].error.should == "750"
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should include a description if there are errors" do
|
42
|
-
@response.items[0].description == "No response from the registry"
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe "failure response from namecheap" do
|
47
|
-
before(:each) do
|
48
|
-
@bad_response_hash = {"ApiResponse"=>{"Status"=>"ERROR",
|
49
|
-
"Errors"=>{"Error"=>"API Key is invalid or API access has not been enabled"},
|
50
|
-
"GMTTimeDifference"=>"--6:00",
|
51
|
-
"RequestedCommand"=>"namecheap.domains.check",
|
52
|
-
"Server"=>"SERVER159",
|
53
|
-
"ExecutionTime"=>"0.01",
|
54
|
-
"xmlns"=>"http://api.namecheap.com/xml.response"}}
|
55
|
-
|
56
|
-
|
57
|
-
it "should return false if bad hash is returned" do
|
58
|
-
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
#<?xml version="1.0" encoding="utf-8"?>
|
65
|
-
# <ApiResponse Status="OK" xmlns="http://api.namecheap.com/xml.response">
|
66
|
-
# <Errors />
|
67
|
-
# <RequestedCommand>namecheap.domains.check</RequestedCommand>
|
68
|
-
# <CommandResponse Type="namecheap.domains.check">
|
69
|
-
# <DomainCheckResult Domain="domain1.com" Available="true" />
|
70
|
-
# <DomainCheckResult Domain="availabledomain.com" Available="false" />
|
71
|
-
# <DomainCheckResult Domain="err.tld" Available="error" ErrorNo="750" Description="No response from the registry" />
|
72
|
-
# </CommandResponse>
|
73
|
-
# <Server>SERVER-NAME</Server>
|
74
|
-
# <GMTTimeDifference>+5</GMTTimeDifference>
|
75
|
-
# <ExecutionTime>32.76</ExecutionTime>
|
76
|
-
#</ApiResponse>
|
77
|
-
|
78
|
-
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
require File.dirname(__FILE__) + '/../lib/namecheap'
|
3
|
-
|
4
|
-
describe NamecheapResponse do
|
5
|
-
before(:each) do
|
6
|
-
@bad_response_hash = {"ApiResponse"=>{"Status"=>"ERROR",
|
7
|
-
"Errors"=>{"Error"=>"API Key is invalid or API access has not been enabled"},
|
8
|
-
"GMTTimeDifference"=>"--6:00",
|
9
|
-
"RequestedCommand"=>"namecheap.domains.check",
|
10
|
-
"Server"=>"SERVER159",
|
11
|
-
"ExecutionTime"=>"0.01",
|
12
|
-
"xmlns"=>"http://api.namecheap.com/xml.response"}}
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should return a status" do
|
16
|
-
response = NamecheapResponse.new(@bad_response_hash)
|
17
|
-
response.status.should == "ERROR"
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should give error message for invalid api key when using an invalid key" do
|
21
|
-
response = NamecheapResponse.new(@bad_response_hash)
|
22
|
-
response.message.should include("API Key is invalid")
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|