namecheap-ruby 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a1cea1aa16b1dd79407a492d950343466c6abd37
4
- data.tar.gz: 7675a67b49e2ef98829be2bbba1e48c495f9779d
3
+ metadata.gz: 97ec5beed766721b2fcadd63f7bbb0574e1749fd
4
+ data.tar.gz: ca91f903a866d4bdb6a6be0cefc0c27e03446974
5
5
  SHA512:
6
- metadata.gz: 6a4c8fe179d23f19bb743fb9b53d2831a61a973c24618b67d16e98ab30aaf391e5e957c42d4a042b8361da89d80ab86852ba9bb2a43709ef6404b7736a1db6c7
7
- data.tar.gz: 7bbda3531a79fbade0e3e778d8388ae2aa94e7f192a2345237773762793ebb454c266d76e9c263e565f88114049a0f6a4af3e45695a790967ac5d16437a32fe5
6
+ metadata.gz: aac441d240c5c2811efa427935c366d5020dd8ad96a444bc1a60878498bc69d5b51feac933121be571e777bed5cf1c0574839c3c687500dae1b6aae6d2c5b36c
7
+ data.tar.gz: 28fe6131b0a2f1e04d93a74a2f24cb1bf1079ddc9df3eedf35df8c1ddc33dd5e84d4846b978a3de44c134838f49e43759c5955914c2c0bfa9e5030c54c2cd2db
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ pkg
data/Gemfile.lock ADDED
@@ -0,0 +1,23 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ namecheap-ruby (0.0.1)
5
+ httparty
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ httparty (0.12.0)
11
+ json (~> 1.8)
12
+ multi_xml (>= 0.5.2)
13
+ json (1.8.1)
14
+ multi_xml (0.5.5)
15
+ rake (10.1.0)
16
+
17
+ PLATFORMS
18
+ ruby
19
+
20
+ DEPENDENCIES
21
+ bundler (~> 1.3)
22
+ namecheap-ruby!
23
+ rake
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 James Newton
1
+ Copyright (c) 2013 James Newton <hello@jamesnewton.com>
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,12 +1,16 @@
1
1
  # Namecheap
2
2
 
3
- TODO: Write a gem description
3
+ A gem to use the Namecheap API easily.
4
+
5
+ There are many like it, but this one is mine.
6
+
7
+ This is a work in progress, but totally useable. Feel free to contribute.
4
8
 
5
9
  ## Installation
6
10
 
7
11
  Add this line to your application's Gemfile:
8
12
 
9
- gem 'namecheap'
13
+ gem 'namecheap-ruby'
10
14
 
11
15
  And then execute:
12
16
 
@@ -14,11 +18,15 @@ And then execute:
14
18
 
15
19
  Or install it yourself as:
16
20
 
17
- $ gem install namecheap
21
+ $ gem install namecheap-ruby
18
22
 
19
23
  ## Usage
20
24
 
21
- TODO: Write usage instructions here
25
+ ```ruby
26
+ Namecheap.configure user: 'something', api_key: 'something', ip: 'something'
27
+
28
+ Namecheap::Domain.get_list
29
+ ```
22
30
 
23
31
  ## Contributing
24
32
 
@@ -0,0 +1,20 @@
1
+ require 'httparty'
2
+
3
+ require 'namecheap/version'
4
+ require 'namecheap/configuration'
5
+ require 'namecheap/api'
6
+ require 'namecheap/resources/domain'
7
+ require 'namecheap/resources/dns'
8
+ require 'namecheap/resources/ns'
9
+
10
+ module Namecheap
11
+ class << self
12
+ def config
13
+ @config
14
+ end
15
+
16
+ def configure(opts = {})
17
+ @config = Namecheap::Configuration.new(opts).options
18
+ end
19
+ end
20
+ end
data/lib/namecheap.rb CHANGED
@@ -1,5 +1 @@
1
- require "namecheap/version"
2
-
3
- module Namecheap
4
- # Your code goes here...
5
- end
1
+ require_relative 'namecheap-ruby'
@@ -0,0 +1,39 @@
1
+ module Namecheap::API
2
+ SANDBOX = 'https://api.sandbox.namecheap.com/xml.response'
3
+ PRODUCTION = 'https://api.namecheap.com/xml.response'
4
+
5
+ def get(command, options = {})
6
+ request :get, command, options
7
+ end
8
+
9
+ def post(command, options = {})
10
+ request :post, command, options
11
+ end
12
+
13
+ private
14
+
15
+ def base_uri
16
+ Namecheap.config[:sandbox] ? SANDBOX : PRODUCTION
17
+ end
18
+
19
+ def request(type, command, options = {})
20
+ endpoint = "#{params(options)}&Command=namecheap.#{command}"
21
+
22
+ HTTParty.send(type, "#{base_uri}#{endpoint}")
23
+ end
24
+
25
+ def params(options = {})
26
+ params = ''
27
+
28
+ {
29
+ ApiUser: Namecheap.config[:user],
30
+ ApiKey: Namecheap.config[:api_key],
31
+ ClientIp: Namecheap.config[:ip],
32
+ UserName: Namecheap.config[:user]
33
+ }.merge(options).each do |key, value|
34
+ params += "&#{key}=#{value}"
35
+ end
36
+
37
+ params.gsub(/^&/, '?')
38
+ end
39
+ end
@@ -0,0 +1,19 @@
1
+ class Namecheap::Configuration
2
+ attr_reader :options
3
+
4
+ REQUIRED_PARAMS = [:user, :api_key, :ip]
5
+
6
+ def initialize(opts = {})
7
+ raise "Missing configuration options: #{REQUIRED_PARAMS.delete_if { |param| opts.has_key?(param) }.join(', ')}" unless validate_config(opts)
8
+
9
+ @options = opts
10
+ @options[:sandbox] ||= false
11
+ @options
12
+ end
13
+
14
+ private
15
+
16
+ def validate_config(opts)
17
+ REQUIRED_PARAMS.delete_if { |param| opts.has_key?(param) }.count.zero?
18
+ end
19
+ end
@@ -0,0 +1,68 @@
1
+ module Namecheap::DNS
2
+ include Namecheap::API
3
+ extend self
4
+
5
+ def get_email_forwarding(domain)
6
+ get 'domains.dns.getEmailForwarding', DomainName: domain
7
+ end
8
+
9
+ def get_hosts(domain)
10
+ get 'domains.dns.getHosts', split_domain(domain)
11
+ end
12
+
13
+ def get_list(domain)
14
+ get 'domains.dns.getList', split_domain(domain)
15
+ end
16
+
17
+ def set_custom(domain, nameservers)
18
+ nameservers = nameservers.is_a?(Array) ? nameservers.join(',') : nameservers
19
+
20
+ get 'domains.dns.setCustom', split_domain(domain).merge(Nameservers: nameservers)
21
+ end
22
+
23
+ def set_default(domain)
24
+ get 'domains.dns.setDefault', split_domain(domain)
25
+ end
26
+
27
+ def set_email_forwarding(domain, mailboxes)
28
+ get 'domains.dns.setEmailForwarding', { DomainName: domain }.merge(format_mailboxes(mailboxes))
29
+ end
30
+
31
+ def set_hosts(domain, hosts)
32
+ get 'domains.dns.setHosts', split_domain(domain).merge(format_hosts(hosts))
33
+ end
34
+
35
+ private
36
+
37
+ def format_hosts(hosts)
38
+ hosts = hosts.is_a?(Array) ? hosts : [hosts]
39
+ host_params = {}
40
+
41
+ hosts.each_with_index do |hash, index|
42
+ i = index + 1
43
+ host_params["HostName#{i}"] = hash[:hostname]
44
+ host_params["RecordType#{i}"] = hash[:type]
45
+ host_params["Address#{i}"] = hash[:address]
46
+ host_params["MXPref#{i}"] = hash[:mx_pref] if hash[:type] == 'MX'
47
+ host_params["EmailType#{i}"] = hash[:email_type] if hash[:email_type]
48
+ host_params["TTL#{i}"] = hash[:ttl] if hash[:ttl]
49
+ end
50
+ end
51
+
52
+ def format_mailboxes(mailboxes)
53
+ mailboxes = mailboxes.is_a?(Array) ? mailboxes : [mailboxes]
54
+ box_params = {}
55
+
56
+ mailboxes.each_with_index do |hash, index|
57
+ i = index + 1
58
+ box_params["MailBox#{i}".to_sym] = hash[:mailbox]
59
+ box_params["ForwardTo#{i}".to_sym] = hash[:forward_to]
60
+ end
61
+ end
62
+
63
+ def split_domain(domain)
64
+ tld, sld = domain.split('.')
65
+
66
+ { TLD: tld, SLD: sld }
67
+ end
68
+ end
@@ -0,0 +1,57 @@
1
+ module Namecheap::Domain
2
+ include Namecheap::API
3
+ extend self
4
+
5
+ def check(domains)
6
+ domains = domains.is_a?(Array) ? domains.join(',') : domains
7
+
8
+ get 'domains.check', DomainList: domains
9
+ end
10
+
11
+ def create(*)
12
+ raise 'implementation needed'
13
+ end
14
+
15
+ def get_contacts(domain)
16
+ get 'domains.getContacts', DomainName: domain
17
+ end
18
+
19
+ def get_info(domain)
20
+ get 'domains.getInfo', DomainName: domain
21
+ end
22
+
23
+ def get_list
24
+ get 'domains.getList'
25
+ end
26
+
27
+ def get_registrar_lock(domain)
28
+ get 'domains.getRegistrarLock', DomainName: domain
29
+ end
30
+
31
+ def get_tld_list
32
+ get 'domains.getTldList'
33
+ end
34
+
35
+ def reactivate(domain)
36
+ get 'domains.reactivate', DomainName: domain
37
+ end
38
+
39
+ def renew(domain, years = 1, promo_code = nil)
40
+ params = { DomainName: domain, Years: years }
41
+ params.merge!(PromotionCode: promo_code) unless promo_code.nil?
42
+
43
+ get 'domains.renew', params
44
+ end
45
+
46
+ def set_contacts(*)
47
+ raise 'implementation needed'
48
+ end
49
+
50
+ def set_registrar_lock(domain, lock)
51
+ raise "Lock value must be 'LOCK' or 'UNLOCK'" unless lock == 'LOCK' || lock == 'UNLOCK'
52
+
53
+ params = { DomainName: domain, LockAction: lock }
54
+
55
+ get 'domains.setRegistrarLock', params
56
+ end
57
+ end
@@ -0,0 +1,30 @@
1
+ module Namecheap::NS
2
+ include Namecheap::API
3
+ extend self
4
+
5
+ def create(domain, nameserver, ip)
6
+ get 'domains.ns.create', split_domain(domain).merge(Nameserver: nameserver, IP: ip)
7
+ end
8
+
9
+ def delete(domain, nameserver)
10
+ get 'domains.ns.delete', split_domain(domain).merge(Nameserver: nameserver)
11
+ end
12
+
13
+ def get_info(domain, nameserver)
14
+ get 'domains.ns.getInfo', split_domain(domain).merge(Nameserver: nameserver)
15
+ end
16
+
17
+ def update(domain, nameserver, ip)
18
+ old_ip = get_info(domain, nameserver).parsed_response['ApiResponse']['CommandResponse']['DomainNSInfoResult']['IP']
19
+
20
+ get 'domains.ns.update', split_domain(domain).merge(Nameserver: nameserver, OldIP: old_ip, IP: ip)
21
+ end
22
+
23
+ private
24
+
25
+ def split_domain(domain)
26
+ sld, tld = domain.split('.')
27
+
28
+ { SLD: sld, TLD: tld }
29
+ end
30
+ end
@@ -1,3 +1,3 @@
1
1
  module Namecheap
2
- VERSION = "0.0.1"
2
+ VERSION = '0.0.2'
3
3
  end
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.add_dependency 'httparty'
22
+
21
23
  spec.add_development_dependency "bundler", "~> 1.3"
22
24
  spec.add_development_dependency "rake"
23
25
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: namecheap-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Newton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-22 00:00:00.000000000 Z
11
+ date: 2014-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -45,11 +59,19 @@ executables: []
45
59
  extensions: []
46
60
  extra_rdoc_files: []
47
61
  files:
62
+ - .gitignore
48
63
  - Gemfile
64
+ - Gemfile.lock
49
65
  - LICENSE.txt
50
66
  - README.md
51
67
  - Rakefile
68
+ - lib/namecheap-ruby.rb
52
69
  - lib/namecheap.rb
70
+ - lib/namecheap/api.rb
71
+ - lib/namecheap/configuration.rb
72
+ - lib/namecheap/resources/dns.rb
73
+ - lib/namecheap/resources/domain.rb
74
+ - lib/namecheap/resources/ns.rb
53
75
  - lib/namecheap/version.rb
54
76
  - namecheap-ruby.gemspec
55
77
  homepage: https://github.com/jameswritescode/namecheap-ruby
@@ -72,8 +94,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
94
  version: '0'
73
95
  requirements: []
74
96
  rubyforge_project:
75
- rubygems_version: 2.0.6
97
+ rubygems_version: 2.1.10
76
98
  signing_key:
77
99
  specification_version: 4
78
100
  summary: Ruby wrapper for the Namecheap API
79
101
  test_files: []
102
+ has_rdoc: