enom 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/enom/cli.rb CHANGED
@@ -2,12 +2,22 @@ require 'yaml'
2
2
  module Enom
3
3
 
4
4
  class CommandNotFound < RuntimeError; end
5
+ class InvalidCredentials < RuntimeError; end
5
6
 
6
7
  class CLI
7
8
 
8
9
  def initialize
9
- Client.username = "test"
10
- Client.password = "password"
10
+ # If the username and password are set elsewhere, they take precedence
11
+ unless Enom::Client.username && Enom::Client.password
12
+ file = File.expand_path("~/.enomconfig")
13
+ if File.exists?(file)
14
+ credentials = YAML.load(File.new(file))
15
+ Enom::Client.username = credentials['username']
16
+ Enom::Client.password = credentials['password']
17
+ else
18
+ raise InvalidCredentials, "Please provide a username/password as arguments create a config file with credentials in ~/.enomconfig"
19
+ end
20
+ end
11
21
  end
12
22
 
13
23
  def execute(command_name, args, options={})
@@ -27,24 +37,14 @@ module Enom
27
37
 
28
38
  def commands
29
39
  {
30
- 'info' => Enom::Commands::DescribeAccount,
31
- 'check' => Enom::Commands::CheckDomain,
32
- 'register' => Enom::Commands::RegisterDomain,
33
- # 'renew' => Enom::Commands::RenewDomain,
34
- # 'transfer' => Enom::Commands::TransferDomain,
35
- # 'describe' => Enom::Commands::DescribeDomain,
36
- 'list' => Enom::Commands::ListDomains,
37
- # 'lock' => Enom::Commands::LockDomain,
38
- # 'unlock' => Enom::Commands::UnlockDomain,
39
- # 'nameservers:list' => Enom::Commands::ListNameservers,
40
- # 'nameservers:set' => Enom::Commands::SetNameservers
40
+ 'list' => Enom::Commands::ListDomains,
41
+ 'check' => Enom::Commands::CheckDomain,
42
+ 'register' => Enom::Commands::RegisterDomain
41
43
  }
42
44
  end
43
45
 
44
- require 'enom/commands/describe_account'
45
- require 'enom/commands/check_domain'
46
- require 'enom/commands/register_domain'
47
- require 'enom/commands/list_domains'
48
-
49
46
  end
50
- end
47
+ end
48
+ require 'enom/commands/list_domains'
49
+ require 'enom/commands/check_domain'
50
+ require 'enom/commands/register_domain'
data/lib/enom/client.rb CHANGED
@@ -30,12 +30,11 @@ module Enom
30
30
  if response['interface_response']['ErrCount'] == '0'
31
31
  return response
32
32
  else
33
- raise InterfaceError
33
+ p response if test?
34
+ raise InterfaceError, response['interface_response']['errors'].values.join(", ")
34
35
  end
35
36
  end
36
37
  end
37
-
38
38
  end
39
-
40
39
  end
41
40
  end
@@ -0,0 +1,11 @@
1
+ module Enom
2
+ module Commands
3
+ class CheckDomain
4
+ def execute(args, options={})
5
+ name = args.shift
6
+ response = Domain.check(name)
7
+ puts "Check domain result for #{name}: #{response}"
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ module Enom
2
+ module Commands
3
+ class ListDomains
4
+ def execute(args, options = {})
5
+ domains = Domain.all
6
+ puts "Found #{domains.length} domains:"
7
+ domains.each do |domain|
8
+ puts "\t#{domain.name}"
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ module Enom
2
+ module Commands
3
+ class RegisterDomain
4
+ def execute(args, options={})
5
+ name = args.shift
6
+ domain = Domain.register!(name)
7
+ puts "Registered #{domain.name}"
8
+ end
9
+ end
10
+ end
11
+ end
data/lib/enom/domain.rb CHANGED
@@ -36,14 +36,18 @@ module Enom
36
36
  end
37
37
 
38
38
  # Determine if the domain is available for purchase
39
- # def self.check(name)
40
- # sld, tld = name.split('.')
41
- # response = self.get("#{Client.base_uri}/domains/#{name}/check.json", options)
42
- #
43
- # p response if Client.test?
44
- #
45
- # # return "registered" or "available"
46
- # end
39
+ def self.check(name)
40
+ sld, tld = name.split('.')
41
+ response = Client.request("Command" => "Check", "SLD" => sld, "TLD" => tld)["interface_response"]["RRPCode"]
42
+
43
+ p response if Client.test?
44
+
45
+ if response == "210"
46
+ "available"
47
+ else
48
+ "unavailable"
49
+ end
50
+ end
47
51
 
48
52
  # Find and return all domains in the account
49
53
  def self.all(options = {})
@@ -66,10 +70,12 @@ module Enom
66
70
  opts.merge!("NS#{count}" => nameserver)
67
71
  count += 1
68
72
  end
73
+ else
74
+ opts.merge!("UseDNS" => "default")
69
75
  end
70
76
  opts.merge!('NumYears' => options[:years]) if options[:years]
71
- purchase = get({'Command' => 'Purchase', 'SLD' => sld, 'TLD' => tld}.merge(opts))
72
- self.find(name)
77
+ response = Client.request({'Command' => 'Purchase', 'SLD' => sld, 'TLD' => tld}.merge(opts))
78
+ Domain.find(name)
73
79
  end
74
80
 
75
81
  # Lock the domain at the registrar so it can't be transferred
data/lib/enom/error.rb CHANGED
@@ -1,5 +1,11 @@
1
1
  module Enom
2
2
 
3
+ class Error < StandardError
4
+ def initialize(message)
5
+ super "An error occurred: #{message}"
6
+ end
7
+ end
8
+
3
9
  class InterfaceError < StandardError
4
10
  def initialize(message = nil)
5
11
  if message
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enom
3
3
  version: !ruby/object:Gem::Version
4
- hash: 59
4
+ hash: 57
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 0
10
- version: 0.9.0
9
+ - 1
10
+ version: 0.9.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - James Miller
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-13 00:00:00 -06:00
18
+ date: 2010-11-16 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -48,7 +48,7 @@ dependencies:
48
48
  version: "0"
49
49
  type: :development
50
50
  version_requirements: *id002
51
- description: Enom is a simple Ruby wrapper for portions of the Enom domain reseller API.
51
+ description: Enom is a Ruby wrapper and command line interface for portions of the Enom domain reseller API.
52
52
  email: bensie@gmail.com
53
53
  executables: []
54
54
 
@@ -66,6 +66,9 @@ files:
66
66
  - lib/enom/client.rb
67
67
  - lib/enom/domain.rb
68
68
  - lib/enom/error.rb
69
+ - lib/enom/commands/check_domain.rb
70
+ - lib/enom/commands/list_domains.rb
71
+ - lib/enom/commands/register_domain.rb
69
72
  - test/enom_test.rb
70
73
  - test/test_helper.rb
71
74
  has_rdoc: true