enom 0.9.7 → 0.9.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,7 @@
1
1
  require 'httparty'
2
2
 
3
3
  require File.expand_path('../enom/client', __FILE__)
4
+ require File.expand_path('../enom/contact_info', __FILE__)
4
5
  require File.expand_path('../enom/domain', __FILE__)
5
6
  require File.expand_path('../enom/account', __FILE__)
6
7
  require File.expand_path('../enom/error', __FILE__)
@@ -40,7 +40,8 @@ module Enom
40
40
  'list' => Enom::Commands::ListDomains,
41
41
  'check' => Enom::Commands::CheckDomain,
42
42
  'register' => Enom::Commands::RegisterDomain,
43
- 'renew' => Enom::Commands::RenewDomain
43
+ 'renew' => Enom::Commands::RenewDomain,
44
+ 'describe' => Enom::Commands::DescribeDomain
44
45
  }
45
46
  end
46
47
 
@@ -50,3 +51,4 @@ require 'enom/commands/list_domains'
50
51
  require 'enom/commands/check_domain'
51
52
  require 'enom/commands/register_domain'
52
53
  require 'enom/commands/renew_domain'
54
+ require 'enom/commands/describe_domain'
@@ -0,0 +1,26 @@
1
+ module Enom
2
+ module Commands
3
+ class DescribeDomain
4
+ def execute(args, options={})
5
+ name = args.shift
6
+ domain = Domain.find(name)
7
+
8
+ puts domain.name.upcase
9
+ puts "Expires: #{domain.expiration_date.strftime("%B %d, %Y")}"
10
+
11
+ puts "Name Servers:"
12
+ domain.nameservers.each do |ns|
13
+ puts "\t#{ns}"
14
+ end
15
+
16
+ puts "Contact Info:"
17
+ domain.all_contact_info.each do |k,v|
18
+ puts "\t#{k}:"
19
+ v.each do |k,v|
20
+ puts "\t\t#{k}: #{v}"
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,79 @@
1
+ module Enom
2
+ module ContactInfo
3
+
4
+ CONTACT_TYPES = %w(Registrant AuxBilling Tech Admin)
5
+ FIELDS = [
6
+ {:name => "FirstName", :required => true},
7
+ {:name => "LastName", :required => true},
8
+ {:name => "OrganizationName", :required => true},
9
+ {:name => "JobTitle", :required => false},
10
+ {:name => "Address1", :required => true},
11
+ {:name => "Address2", :required => false},
12
+ {:name => "City", :required => true},
13
+ {:name => "StateProvinceChoice", :required => false}, # "S" or "P" are valid
14
+ {:name => "StateProvince", :required => false},
15
+ {:name => "PostalCode", :required => true},
16
+ {:name => "Country", :required => true},
17
+ {:name => "EmailAddress", :required => true},
18
+ {:name => "Phone", :required => true}
19
+ ]
20
+
21
+ CONTACT_TYPES.each do |contact_type|
22
+
23
+ # Define getter methods for each contact type
24
+ # def registrant_contact_info
25
+ # ...
26
+ # end
27
+ define_method "#{contact_type.downcase}_contact_info" do
28
+ Client.request('Command' => 'GetContacts', 'SLD' => sld, 'TLD' => tld)["interface_response"]["GetContacts"][contact_type]
29
+ end
30
+
31
+ # Define setter methods for each contact type
32
+ # def update_registrant_contact_info(contact_data = {})
33
+ # ...
34
+ # end
35
+ define_method "update_#{contact_type.downcase}_contact_info" do |contact_data = {}|
36
+
37
+ # Remove attributes that are not in Enom's list of available fields
38
+ contact_data.select!{|k| FIELDS.map{|f| f[:name] }.include?(k)}
39
+
40
+ # Write the initial options hash containing the current ContactType
41
+ opts = {"ContactType" => contact_type}
42
+
43
+ # Check to make sure all required fields are present
44
+ FIELDS.each do |field|
45
+ if field[:required]
46
+ if contact_data[field[:name]].nil? || contact_data[field[:name]].empty?
47
+ raise Error, "#{field[:name]} is required to update contact info"
48
+ end
49
+ end
50
+ end
51
+
52
+ # Prepend ContactType to beginning of all data and add to options hash
53
+ contact_data.each do |k,v|
54
+ opts.merge!("#{contact_type}#{k}" => v)
55
+ end
56
+
57
+ # Send the new contact details to Enom
58
+ Client.request({'Command' => 'Contacts', 'SLD' => sld, 'TLD' => tld}.merge(opts))
59
+
60
+ # Fetch the new contact info and return it
61
+ send("#{contact_type.downcase}_contact_info")
62
+ end
63
+
64
+ def all_contact_info
65
+ Client.request('Command' => 'GetContacts', 'SLD' => sld, 'TLD' => tld)["interface_response"]["GetContacts"].select{|k| CONTACT_TYPES.include?(k)}
66
+ end
67
+
68
+ # Update all contact types with the same data
69
+ # Performs a separate API call for each type
70
+ def update_all_contact_info(data = {})
71
+ CONTACT_TYPES.each do |contact_type|
72
+ send("update_#{contact_type.downcase}_contact_info", data)
73
+ end
74
+ end
75
+
76
+ end
77
+
78
+ end
79
+ end
@@ -2,6 +2,7 @@ module Enom
2
2
 
3
3
  class Domain
4
4
  include HTTParty
5
+ include ContactInfo
5
6
 
6
7
  # The domain name on Enom
7
8
  attr_reader :name
@@ -16,8 +17,9 @@ module Enom
16
17
  def initialize(attributes)
17
18
  @name = attributes["DomainName"] || attributes["domainname"]
18
19
  @sld, @tld = @name.split('.')
19
- expiration_string = attributes["expiration_date"] || attributes["status"]["expiration"]
20
- @expiration_date = Date.strptime(expiration_string.split(' ').first, "%m/%d/%Y")
20
+
21
+ expiration_date_string = attributes["expiration_date"] || attributes["status"]["expiration"]
22
+ @expiration_date = Date.strptime(expiration_date_string.split(' ').first, "%m/%d/%Y")
21
23
 
22
24
  # If we have more attributes for the domain from running GetDomainInfo
23
25
  # (as opposed to GetAllDomains), we should save it to the instance to
@@ -129,8 +131,11 @@ module Enom
129
131
  end
130
132
 
131
133
  def expiration_date
132
- date_string = @domain_payload['interface_response']['GetDomainInfo']['status']['expiration']
133
- Date.strptime(date_string.split(' ').first, "%m/%d/%Y")
134
+ unless @expiration_date
135
+ date_string = @domain_payload['interface_response']['GetDomainInfo']['status']['expiration']
136
+ @expiration_date = Date.strptime(date_string.split(' ').first, "%m/%d/%Y")
137
+ end
138
+ @expiration_date
134
139
  end
135
140
 
136
141
  def registration_status
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 9
8
- - 7
9
- version: 0.9.7
8
+ - 8
9
+ version: 0.9.8
10
10
  platform: ruby
11
11
  authors:
12
12
  - James Miller
@@ -61,9 +61,11 @@ files:
61
61
  - lib/enom/account.rb
62
62
  - lib/enom/cli.rb
63
63
  - lib/enom/client.rb
64
+ - lib/enom/contact_info.rb
64
65
  - lib/enom/domain.rb
65
66
  - lib/enom/error.rb
66
67
  - lib/enom/commands/check_domain.rb
68
+ - lib/enom/commands/describe_domain.rb
67
69
  - lib/enom/commands/list_domains.rb
68
70
  - lib/enom/commands/register_domain.rb
69
71
  - lib/enom/commands/renew_domain.rb