namecheap 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/COPYING +159 -668
- data/Gemfile +10 -2
- data/README.md +35 -27
- data/lib/namecheap.rb +17 -12
- data/lib/namecheap/api.rb +51 -11
- data/lib/namecheap/config.rb +3 -46
- data/lib/namecheap/dns.rb +32 -27
- data/lib/namecheap/domains.rb +46 -31
- data/lib/namecheap/ns.rb +16 -16
- data/lib/namecheap/ssl.rb +37 -27
- data/lib/namecheap/transfers.rb +16 -12
- data/lib/namecheap/users.rb +31 -17
- data/lib/namecheap/version.rb +1 -1
- data/lib/namecheap/whois_guard.rb +24 -19
- data/namecheap.gemspec +5 -3
- data/spec/helper.rb +25 -0
- data/spec/namecheap/dns_spec.rb +13 -0
- data/spec/{domains_spec.rb → namecheap/domains_spec.rb} +4 -2
- data/spec/namecheap/ns_spec.rb +13 -0
- data/spec/namecheap/ssl_spec.rb +17 -0
- data/spec/namecheap/transfers.rb +13 -0
- data/spec/namecheap/users_spec.rb +13 -0
- data/spec/namecheap/whois_guard_spec.rb +13 -0
- data/spec/namecheap_spec.rb +25 -34
- metadata +85 -73
- data/.rvmrc +0 -3
- data/lib/monkey_patch.rb +0 -84
- data/spec/spec_helper.rb +0 -10
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,32 @@
|
|
1
1
|
Overview
|
2
2
|
========
|
3
3
|
|
4
|
+
Documentation
|
5
|
+
-----
|
6
|
+
|
7
|
+
[http://rubygems.org/gems/namecheap](http://rubygems.org/gems/namecheap)
|
8
|
+
|
9
|
+
Usage
|
10
|
+
-----
|
11
|
+
|
12
|
+
In your initializers, configure Namecheap like so:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
Namecheap.configure do |config|
|
16
|
+
config.key = 'apikey'
|
17
|
+
config.username = 'apiuser'
|
18
|
+
config.client_ip = '127.0.0.1'
|
19
|
+
end
|
20
|
+
```
|
21
|
+
|
22
|
+
Then you can do something like:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
Namecheap.domains.get_list
|
26
|
+
```
|
27
|
+
|
28
|
+
Please see the Namecheap API documentation for more information
|
29
|
+
|
4
30
|
About this project
|
5
31
|
-------------
|
6
32
|
|
@@ -34,22 +60,20 @@ the purchase API wrappers, but it was a good starting point (and allowed me to
|
|
34
60
|
study how seasoned pros would approach API wrappers). So I forked, published a
|
35
61
|
gem based on the fork, and hacked on it. And that's how it all began :)
|
36
62
|
|
37
|
-
|
38
|
-
|
63
|
+
Credits
|
64
|
+
-------
|
39
65
|
|
40
|
-
|
66
|
+
Tristan V. Gomez: tristan dot gomez at gmail dot com
|
67
|
+
|
68
|
+
[Hashrocket](http://www.hashrocket.com/) from where the original code was forked from
|
41
69
|
|
42
|
-
|
43
|
-
config.key = 'apikey'
|
44
|
-
config.username = 'apiuser'
|
45
|
-
config.client_ip = '127.0.0.1'
|
46
|
-
end
|
70
|
+
[Mongoid](http://www.mongoid.org) from where the configuration code was modified from
|
47
71
|
|
48
|
-
Then you can do something like:
|
49
72
|
|
50
|
-
|
73
|
+
Plug!!
|
74
|
+
------
|
51
75
|
|
52
|
-
|
76
|
+
Mindvalley is [hiring](http://www.mindvalley.com/careers) :)
|
53
77
|
|
54
78
|
License
|
55
79
|
-------
|
@@ -68,19 +92,3 @@ GNU General Public License for more details.
|
|
68
92
|
|
69
93
|
You should have received a copy of the GNU General Public License
|
70
94
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
71
|
-
|
72
|
-
|
73
|
-
Credits
|
74
|
-
-------
|
75
|
-
|
76
|
-
Tristan V. Gomez: tristan dot gomez at gmail dot com
|
77
|
-
|
78
|
-
[Hashrocket](http://www.hashrocket.com/) from where the original code was forked from
|
79
|
-
|
80
|
-
[Mongoid](http://www.mongoid.org) from where the configuration code was modified from
|
81
|
-
|
82
|
-
|
83
|
-
Plug!!
|
84
|
-
------
|
85
|
-
|
86
|
-
Mindvalley is [hiring](http://www.mindvalley.com/careers) :)
|
data/lib/namecheap.rb
CHANGED
@@ -1,9 +1,15 @@
|
|
1
1
|
require 'httparty'
|
2
|
-
require 'monkey_patch'
|
3
2
|
require 'pp'
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
require 'namecheap/version'
|
4
|
+
require 'namecheap/api'
|
5
|
+
require 'namecheap/config'
|
6
|
+
require 'namecheap/domains'
|
7
|
+
require 'namecheap/dns'
|
8
|
+
require 'namecheap/ns'
|
9
|
+
require 'namecheap/ssl'
|
10
|
+
require 'namecheap/transfers'
|
11
|
+
require 'namecheap/users'
|
12
|
+
require 'namecheap/whois_guard'
|
7
13
|
|
8
14
|
module Namecheap
|
9
15
|
|
@@ -22,15 +28,14 @@ module Namecheap
|
|
22
28
|
block_given? ? yield(Config) : Config
|
23
29
|
end
|
24
30
|
alias :config :configure
|
25
|
-
|
26
|
-
# Take all the public instance methods from the Config singleton and allow
|
27
|
-
# them to be accessed through the Namecheap module directly.
|
28
|
-
#
|
29
|
-
# @example Delegate the configuration methods.
|
30
|
-
# Namecheap.key = 'newkey'
|
31
|
-
delegate *(Config.public_instance_methods(false) << { :to => Config })
|
32
31
|
|
33
|
-
attr_accessor :domains
|
32
|
+
attr_accessor :domains, :dns, :ns, :transfers, :ssl, :users, :whois_guard
|
34
33
|
self.domains = Namecheap::Domains.new
|
34
|
+
self.dns = Namecheap::Dns.new
|
35
|
+
self.ns = Namecheap::Ns.new
|
36
|
+
self.transfers = Namecheap::Transfers.new
|
37
|
+
self.ssl = Namecheap::Ssl.new
|
38
|
+
self.users = Namecheap::Users.new
|
39
|
+
self.whois_guard = Namecheap::Whois_Guard.new
|
35
40
|
|
36
41
|
end
|
data/lib/namecheap/api.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'active_support/core_ext/string/inflections'
|
2
|
+
|
1
3
|
module Namecheap
|
2
4
|
class Api
|
3
5
|
SANDBOX = 'https://api.sandbox.namecheap.com/xml.response'
|
@@ -5,18 +7,56 @@ module Namecheap
|
|
5
7
|
ENVIRONMENT = defined?(Rails) && Rails.respond_to?(:env) ? Rails.env : (ENV["RACK_ENV"] || 'development')
|
6
8
|
ENDPOINT = (ENVIRONMENT == 'production' ? PRODUCTION : SANDBOX)
|
7
9
|
|
8
|
-
def
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
def get(command, options = {})
|
11
|
+
request 'get', command, options
|
12
|
+
end
|
13
|
+
|
14
|
+
def post(command, options = {})
|
15
|
+
request 'post', command, options
|
16
|
+
end
|
17
|
+
|
18
|
+
def put(command, options = {})
|
19
|
+
request 'post', command, options
|
20
|
+
end
|
21
|
+
|
22
|
+
def delete(command, options = {})
|
23
|
+
request 'post', command, options
|
24
|
+
end
|
25
|
+
|
26
|
+
def request(method, command, options = {})
|
27
|
+
command = 'namecheap.' + command
|
28
|
+
options = init_args.merge(options).merge({:command => command})
|
29
|
+
options.keys.each do |key|
|
30
|
+
options[key.to_s.camelize] = options.delete(key)
|
31
|
+
end
|
32
|
+
|
33
|
+
case method
|
34
|
+
when 'get'
|
35
|
+
#raise options.inspect
|
36
|
+
HTTParty.get(ENDPOINT, { :query => options})
|
37
|
+
when 'post'
|
38
|
+
HTTParty.post(ENDPOINT, { :query => options})
|
39
|
+
when 'put'
|
40
|
+
HTTParty.put(ENDPOINT, { :query => options})
|
41
|
+
when 'delete'
|
42
|
+
HTTParty.delete(ENDPOINT, { :query => options})
|
43
|
+
end
|
12
44
|
end
|
13
45
|
|
14
|
-
def init_args
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
46
|
+
def init_args
|
47
|
+
%w(username key client_ip).each do |key|
|
48
|
+
if Namecheap.config.key.nil?
|
49
|
+
raise Namecheap::Config::RequiredOptionMissing,
|
50
|
+
"Configuration parameter missing: #{key}, " +
|
51
|
+
"please add it to the Namecheap.configure block"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
options = {
|
55
|
+
api_user: Namecheap.config.username,
|
56
|
+
user_name: Namecheap.config.username,
|
57
|
+
api_key: Namecheap.config.key,
|
58
|
+
client_ip: Namecheap.config.client_ip
|
59
|
+
}
|
20
60
|
end
|
21
61
|
end
|
22
|
-
end
|
62
|
+
end
|
data/lib/namecheap/config.rb
CHANGED
@@ -1,43 +1,9 @@
|
|
1
1
|
module Namecheap
|
2
2
|
module Config
|
3
|
-
|
4
|
-
|
3
|
+
class RequiredOptionMissing < RuntimeError ; end
|
5
4
|
extend self
|
6
5
|
|
7
|
-
attr_accessor :
|
8
|
-
@settings = {}
|
9
|
-
@defaults = {}
|
10
|
-
|
11
|
-
# Define a configuration option with a default.
|
12
|
-
#
|
13
|
-
# @example Define the option.
|
14
|
-
# Config.option(:client_ip, :default => '127.0.0.1')
|
15
|
-
#
|
16
|
-
# @param [ Symbol ] name The name of the configuration option.
|
17
|
-
# @param [ Hash ] options Extras for the option.
|
18
|
-
#
|
19
|
-
# @option options [ Object ] :default The default value.
|
20
|
-
def option(name, options = {})
|
21
|
-
defaults[name] = settings[name] = options[:default]
|
22
|
-
|
23
|
-
class_eval <<-RUBY
|
24
|
-
def #{name}
|
25
|
-
settings[#{name.inspect}]
|
26
|
-
end
|
27
|
-
|
28
|
-
def #{name}=(value)
|
29
|
-
settings[#{name.inspect}] = value
|
30
|
-
end
|
31
|
-
|
32
|
-
def #{name}?
|
33
|
-
#{name}
|
34
|
-
end
|
35
|
-
RUBY
|
36
|
-
end
|
37
|
-
|
38
|
-
option :key, :default => 'apikey'
|
39
|
-
option :username, :default => 'apiuser'
|
40
|
-
option :client_ip, :default => '127.0.0.1'
|
6
|
+
attr_accessor :key, :username, :client_ip
|
41
7
|
|
42
8
|
# Configure namecheap from a hash. This is usually called after parsing a
|
43
9
|
# yaml config file such as mongoid.yml.
|
@@ -65,14 +31,5 @@ module Namecheap
|
|
65
31
|
from_hash(settings)
|
66
32
|
end
|
67
33
|
end
|
68
|
-
|
69
|
-
# Reset the configuration options to the defaults.
|
70
|
-
#
|
71
|
-
# @example Reset the configuration options.
|
72
|
-
# config.reset
|
73
|
-
def reset
|
74
|
-
settings.replace(defaults)
|
75
|
-
end
|
76
|
-
|
77
34
|
end
|
78
|
-
end
|
35
|
+
end
|
data/lib/namecheap/dns.rb
CHANGED
@@ -1,51 +1,56 @@
|
|
1
1
|
module Namecheap
|
2
2
|
class Dns < Api
|
3
|
+
# Sets domain to use Namecheap's default DNS servers.
|
4
|
+
# @see http://developer.namecheap.com/docs/doku.php?id=api-reference:domains.dns:setdefault
|
3
5
|
def set_default(sld, tld, options = {})
|
4
|
-
|
5
|
-
|
6
|
-
args['TLD'] = tld
|
7
|
-
api_call('namecheap.domains.dns.setDefault', args)
|
6
|
+
options = {:SLD => sld, :TLD => tld}.merge(options)
|
7
|
+
get 'domains.dns.setDefault', options
|
8
8
|
end
|
9
9
|
|
10
|
+
# Sets domain to use custom DNS servers.
|
11
|
+
# @see http://developer.namecheap.com/docs/doku.php?id=api-reference:domains.dns:setcustom
|
10
12
|
def set_custom(sld, tld, nameservers = [], options = {})
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
if nameservers.respond_to?(:join)
|
14
|
+
nameservers = nameservers.join(',')
|
15
|
+
end
|
16
|
+
|
17
|
+
options = {:SLD => sld, :TLD => tld, :Nameservers => nameservers}.merge(options)
|
18
|
+
get 'domains.dns.setCustom', options
|
16
19
|
end
|
17
20
|
|
21
|
+
# Gets a list of DNS servers associated with the requested domain.
|
22
|
+
# @see http://developer.namecheap.com/docs/doku.php?id=api-reference:domains.dns:getlist
|
18
23
|
def get_list(sld, tld, options = {})
|
19
|
-
|
20
|
-
|
21
|
-
args['TLD'] = tld
|
22
|
-
api_call('namecheap.domains.dns.getList', args)
|
24
|
+
options = {:SLD => sld, :TLD => tld}.merge(options)
|
25
|
+
get 'domains.dns.getList', options
|
23
26
|
end
|
24
27
|
|
28
|
+
# Retrieves DNS host record settings for the requested domain.
|
29
|
+
# @see http://developer.namecheap.com/docs/doku.php?id=api-reference:domains.dns:gethosts
|
25
30
|
def get_hosts(sld, tld, options = {})
|
26
|
-
|
27
|
-
|
28
|
-
args['TLD'] = tld
|
29
|
-
api_call('namecheap.domains.dns.getHosts', args)
|
31
|
+
options = {:SLD => sld, :TLD => tld}.merge(options)
|
32
|
+
get 'domains.dns.getHosts', options
|
30
33
|
end
|
31
34
|
|
35
|
+
# Gets email forwarding settings for the requested domain.
|
36
|
+
# @see http://developer.namecheap.com/docs/doku.php?id=api-reference:domains.dns:getemailforwarding
|
32
37
|
def get_email_forwarding(domain, options = {})
|
33
|
-
|
34
|
-
|
35
|
-
api_call('namecheap.domains.dns.getEmailForwarding', args)
|
38
|
+
options = {:DomainName => domain}.merge(options)
|
39
|
+
get 'domains.dns.getEmailForwarding', options
|
36
40
|
end
|
37
41
|
|
42
|
+
# Sets email forwarding for a domain name.
|
43
|
+
# @see http://developer.namecheap.com/docs/doku.php?id=api-reference:domains.dns:setemailforwarding
|
38
44
|
def set_email_forwarding(domain, options = {})
|
39
|
-
|
40
|
-
|
41
|
-
api_call('namecheap.domains.dns.setEmailForwarding', args)
|
45
|
+
options = {:DomainName => domain}.merge(options)
|
46
|
+
get 'domains.dns.setEmailForwarding', options
|
42
47
|
end
|
43
48
|
|
49
|
+
# Sets DNS host records settings for the requested domain.
|
50
|
+
# @see http://developer.namecheap.com/docs/doku.php?id=api-reference:domains.dns:sethosts
|
44
51
|
def set_hosts(sld, tld, options = {})
|
45
|
-
|
46
|
-
|
47
|
-
args['TLD'] = tld
|
48
|
-
api_call('namecheap.domains.dns.setHosts', args)
|
52
|
+
options = {:SLD => sld, :TLD => tld}.merge(options)
|
53
|
+
get 'domains.dns.setHosts', options
|
49
54
|
end
|
50
55
|
end
|
51
56
|
end
|
data/lib/namecheap/domains.rb
CHANGED
@@ -1,67 +1,82 @@
|
|
1
1
|
module Namecheap
|
2
2
|
class Domains < Api
|
3
|
+
# Returns a list of domains for the particular user.
|
4
|
+
# @see http://developer.namecheap.com/docs/doku.php?id=api-reference:domains:getlist
|
3
5
|
def get_list(options = {})
|
4
|
-
|
5
|
-
api_call('namecheap.domains.getList', args)
|
6
|
+
get 'domains.getList', options
|
6
7
|
end
|
7
8
|
|
9
|
+
# Gets contact information for the requested domain.
|
10
|
+
# @see http://developer.namecheap.com/docs/doku.php?id=api-reference:domains:getcontacts
|
8
11
|
def get_contacts(domain, options = {})
|
9
|
-
|
10
|
-
|
11
|
-
api_call('namecheap.domains.getContacts', args)
|
12
|
+
options = {:DomainName => domain}.merge(options)
|
13
|
+
get 'domains.getContacts', options
|
12
14
|
end
|
13
15
|
|
16
|
+
# Registers a domain.
|
17
|
+
# @see http://developer.namecheap.com/docs/doku.php?id=api-reference:domains:create
|
14
18
|
def create(domain, options = {})
|
15
|
-
|
16
|
-
|
17
|
-
api_call('namecheap.domains.create', args)
|
19
|
+
options = {:DomainName => domain}.merge(options)
|
20
|
+
get 'domains.create', options
|
18
21
|
end
|
19
22
|
|
23
|
+
# Returns a list of tlds.
|
24
|
+
# @see http://developer.namecheap.com/docs/doku.php?id=api-reference:domains:gettldlist
|
20
25
|
def get_tld_list(options = {})
|
21
|
-
|
22
|
-
api_call('namecheap.domains.getTldList', args)
|
26
|
+
get 'domains.getTldList', options
|
23
27
|
end
|
24
28
|
|
29
|
+
# Sets contact information for the requested domain.
|
30
|
+
# @see http://developer.namecheap.com/docs/doku.php?id=api-reference:domains:setcontacts
|
25
31
|
def set_contacts(domain, options = {})
|
26
|
-
|
27
|
-
|
28
|
-
api_call('namecheap.domains.setContacts', args)
|
32
|
+
options = {:DomainName => domain}.merge(options)
|
33
|
+
get 'domains.setContacts', options
|
29
34
|
end
|
30
35
|
|
36
|
+
# Checks the availability of domains.
|
37
|
+
# @see http://developer.namecheap.com/docs/doku.php?id=api-reference:domains:check
|
31
38
|
def check(domains = [], options = {})
|
32
|
-
|
33
|
-
|
34
|
-
|
39
|
+
if domains.respond_to?(:join)
|
40
|
+
domains = domains.join(',')
|
41
|
+
end
|
42
|
+
|
43
|
+
options = {:DomainList => domains}.merge(options)
|
44
|
+
get 'domains.check', options
|
35
45
|
end
|
36
46
|
|
47
|
+
# Reactivates an expired domain.
|
48
|
+
# @see http://developer.namecheap.com/docs/doku.php?id=api-reference:domains:reactivate
|
37
49
|
def reactivate(domain, options = {})
|
38
|
-
|
39
|
-
|
40
|
-
api_call('namecheap.domains.reactivate', args)
|
50
|
+
options = {:DomainName => domain}.merge(options)
|
51
|
+
get 'domains.reactivate', options
|
41
52
|
end
|
42
53
|
|
54
|
+
# Renews an expiring domain.
|
55
|
+
# http://developer.namecheap.com/docs/doku.php?id=api-reference:domains:renew
|
43
56
|
def renew(domain, options = {})
|
44
|
-
|
45
|
-
|
46
|
-
api_call('namecheap.domains.renew', args)
|
57
|
+
options = {:DomainName => domain}.merge(options)
|
58
|
+
get 'domains.renew', options
|
47
59
|
end
|
48
60
|
|
61
|
+
# Gets the status of RegistrarLock for the requested domain.
|
62
|
+
# @see http://developer.namecheap.com/docs/doku.php?id=api-reference:domains:getregistrarlock
|
49
63
|
def get_registrar_lock(domain, options = {})
|
50
|
-
|
51
|
-
|
52
|
-
api_call('namecheap.domains.getRegistrarLock', args)
|
64
|
+
options = {:DomainName => domain}.merge(options)
|
65
|
+
get 'domains.getRegistrarLock', options
|
53
66
|
end
|
54
67
|
|
68
|
+
# Sets the RegistrarLock status for a domain.
|
69
|
+
# @see http://developer.namecheap.com/docs/doku.php?id=api-reference:domains:setregistrarlock
|
55
70
|
def set_registrar_lock(domain, options = {})
|
56
|
-
|
57
|
-
|
58
|
-
api_call('namecheap.domains.setRegistrarLock', args)
|
71
|
+
options = {:DomainName => domain}.merge(options)
|
72
|
+
get 'domains.setRegistrarLock', options
|
59
73
|
end
|
60
74
|
|
75
|
+
# Returns information about the requested domain.
|
76
|
+
# @see http://developer.namecheap.com/docs/doku.php?id=api-reference:domains:getinfo
|
61
77
|
def get_info(domain, options = {})
|
62
|
-
|
63
|
-
|
64
|
-
api_call('namecheap.domains.getInfo', args)
|
78
|
+
options = {:DomainName => domain}.merge(options)
|
79
|
+
get 'domains.getInfo', options
|
65
80
|
end
|
66
81
|
end
|
67
82
|
end
|