netsol 0.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +1 -1
  3. data/api_docs/PartnerProtocol_Whats_New_6_8.pdf +0 -0
  4. data/api_docs/PartnerProtocol_XML_DTD_6.8/AuthLookupRequest.dtd +30 -0
  5. data/api_docs/PartnerProtocol_XML_DTD_6.8/AuthLookupResponse.dtd +34 -0
  6. data/api_docs/PartnerProtocol_XML_DTD_6.8/AvailableRequest.dtd +53 -0
  7. data/api_docs/PartnerProtocol_XML_DTD_6.8/AvailableResponse.dtd +81 -0
  8. data/api_docs/PartnerProtocol_XML_DTD_6.8/CommonDeclarations.dtd +173 -0
  9. data/api_docs/PartnerProtocol_XML_DTD_6.8/DomainData.dtd +68 -0
  10. data/api_docs/PartnerProtocol_XML_DTD_6.8/DomainProduct.dtd +189 -0
  11. data/api_docs/PartnerProtocol_XML_DTD_6.8/EmailForwardingLookupRequest.dtd +25 -0
  12. data/api_docs/PartnerProtocol_XML_DTD_6.8/EmailForwardingLookupResponse.dtd +31 -0
  13. data/api_docs/PartnerProtocol_XML_DTD_6.8/EmailForwardingRequest.dtd +26 -0
  14. data/api_docs/PartnerProtocol_XML_DTD_6.8/ErrorResponse.dtd +19 -0
  15. data/api_docs/PartnerProtocol_XML_DTD_6.8/HostProduct.dtd +72 -0
  16. data/api_docs/PartnerProtocol_XML_DTD_6.8/LookupRequest.dtd +34 -0
  17. data/api_docs/PartnerProtocol_XML_DTD_6.8/LookupResponse.dtd +38 -0
  18. data/api_docs/PartnerProtocol_XML_DTD_6.8/OrderRequest.dtd +31 -0
  19. data/api_docs/PartnerProtocol_XML_DTD_6.8/OrderResponse.dtd +43 -0
  20. data/api_docs/PartnerProtocol_XML_DTD_6.8/OrderStatusRequest.dtd +33 -0
  21. data/api_docs/PartnerProtocol_XML_DTD_6.8/PartnerManagerRequest.dtd +71 -0
  22. data/api_docs/PartnerProtocol_XML_DTD_6.8/PartnerManagerResponse.dtd +64 -0
  23. data/api_docs/PartnerProtocol_XML_DTD_6.8/PrivateRegistrationProduct.dtd +19 -0
  24. data/api_docs/PartnerProtocol_XML_DTD_6.8/RequestHeader.dtd +17 -0
  25. data/api_docs/PartnerProtocol_XML_DTD_6.8/ResponseHeader.dtd +10 -0
  26. data/api_docs/PartnerProtocol_XML_DTD_6.8/SSLProduct.dtd +90 -0
  27. data/api_docs/PartnerProtocol_XML_DTD_6.8/SecurityRequest.dtd +39 -0
  28. data/api_docs/PartnerProtocol_XML_DTD_6.8/SecurityResponse.dtd +21 -0
  29. data/api_docs/PartnerProtocol_XML_DTD_6.8/UserLookupRequest.dtd +39 -0
  30. data/api_docs/PartnerProtocol_XML_DTD_6.8/UserLookupResponse.dtd +47 -0
  31. data/api_docs/PartnerProtocol_XML_DTD_6.8/UserRequest.dtd +118 -0
  32. data/api_docs/PartnerProtocol_XML_DTD_6.8/UserResponse.dtd +21 -0
  33. data/api_docs/PartnerProtocol_XML_DTD_6.8/WebForwardingProduct.dtd +15 -0
  34. data/api_docs/XML_Reference_Version_6_8.pdf +0 -0
  35. data/lib/netsol.rb +107 -8
  36. data/netsol.gemspec +2 -1
  37. data/xml/_auth.haml +4 -0
  38. data/xml/_header.haml +5 -0
  39. data/xml/_lookup_domain.haml +11 -0
  40. data/xml/create_individual.haml +21 -0
  41. data/xml/create_registration.haml +10 -0
  42. data/xml/find_all_customers_for_partner.haml +5 -0
  43. data/xml/find_all_domains_for_partner.haml +5 -0
  44. data/xml/modify_registration.haml +11 -0
  45. metadata +53 -10
  46. data/xml/create_individual.xml.erb +0 -25
  47. data/xml/find_all_customers_for_partner.xml.erb +0 -7
  48. data/xml/find_all_domains_for_partner.xml.erb +0 -7
  49. data/xml/header.xml.erb +0 -7
  50. data/xml/modify_registration.xml.erb +0 -21
@@ -0,0 +1,47 @@
1
+ <!-- ===================================================================== -->
2
+ <!-- ==== User Lookup Response Message and Body Declaration. ============ -->
3
+ <!-- ===================================================================== -->
4
+
5
+ <!ELEMENT UserLookupResponse (ResponseHeader, Body)>
6
+ <!ELEMENT Body (Status, User*)>
7
+ <!ELEMENT User (Individual | Business)>
8
+
9
+ <!ELEMENT Individual (
10
+ UserID,
11
+ NicHandle?,
12
+ LoginName?,
13
+ FirstName,
14
+ MiddleName?,
15
+ LastName,
16
+ Address,
17
+ Phone,
18
+ Fax?,
19
+ Email,
20
+ AuthQuestion,
21
+ AuthAnswer,
22
+ SupplementalRegistryData?,
23
+ Password? ) >
24
+
25
+ <!ELEMENT Business (
26
+ UserID,
27
+ NicHandle?,
28
+ LoginName?,
29
+ CompanyName,
30
+ Address,
31
+ Phone,
32
+ Fax?,
33
+ Email?,
34
+ LegalContact,
35
+ AuthQuestion,
36
+ AuthAnswer,
37
+ SupplementalRegistryData? ) >
38
+
39
+
40
+ <!-- ===================================================================== -->
41
+ <!-- ==== Inclusion of externally defined elements. ====================== -->
42
+ <!-- ===================================================================== -->
43
+
44
+ <!ENTITY % ResponseHeader SYSTEM "ResponseHeader.dtd">
45
+ %ResponseHeader;
46
+
47
+ <!-- sccsID "%TC-INFO%" -->
@@ -0,0 +1,118 @@
1
+ <!-- ===================================================================== -->
2
+ <!-- ==== User Request Message and Body Declaration. ==================== -->
3
+ <!-- ===================================================================== -->
4
+
5
+ <!ELEMENT UserRequest (RequestHeader, Body)>
6
+ <!ELEMENT Body (
7
+ ( CreateIndividual |
8
+ CreateBusiness |
9
+ ModifyIndividual |
10
+ ModifyBusiness |
11
+ IndividualNewInfo |
12
+ BusinessNewInfo |
13
+ CreateRegistryContact |
14
+ ExtendCARegistrantApproval ) ) >
15
+
16
+ <!ELEMENT CreateIndividual (
17
+ LoginName?,
18
+ Password,
19
+ FirstName,
20
+ MiddleName?,
21
+ LastName,
22
+ Address,
23
+ Phone,
24
+ Fax?,
25
+ Email,
26
+ AuthQuestion,
27
+ AuthAnswer,
28
+ SupplementalRegistryData?) >
29
+
30
+ <!ELEMENT ModifyIndividual (
31
+ AuthorizedAgent,
32
+ CustomerID,
33
+ NewLoginName?,
34
+ NewPassword?,
35
+ FirstName?,
36
+ MiddleName?,
37
+ LastName?,
38
+ Address?,
39
+ Phone?,
40
+ Fax?,
41
+ Email?,
42
+ (AuthQuestion, AuthAnswer)?,
43
+ SupplementalRegistryData? ) >
44
+
45
+ <!ELEMENT CreateBusiness (
46
+ LoginName?,
47
+ Password,
48
+ CompanyName,
49
+ Address,
50
+ Phone,
51
+ Fax?,
52
+ Email,
53
+ LegalContact,
54
+ AuthQuestion,
55
+ AuthAnswer,
56
+ SupplementalRegistryData?) >
57
+
58
+ <!ELEMENT ModifyBusiness (
59
+ AuthorizedAgent,
60
+ CustomerID,
61
+ NewLoginName?,
62
+ NewPassword?,
63
+ CompanyName?,
64
+ Address?,
65
+ Phone?,
66
+ Fax?,
67
+ Email?,
68
+ LegalContact?,
69
+ (AuthQuestion, AuthAnswer)?,
70
+ SupplementalRegistryData? ) >
71
+
72
+ <!-- Remove all old information and replace with new. -->
73
+ <!ELEMENT IndividualNewInfo (
74
+ AuthorizedAgent,
75
+ CustomerID,
76
+ FirstName,
77
+ MiddleName?,
78
+ LastName,
79
+ Address,
80
+ Phone,
81
+ Fax?,
82
+ Email ) >
83
+
84
+ <!-- Remove all old information and replace with new. -->
85
+ <!ELEMENT BusinessNewInfo (
86
+ AuthorizedAgent,
87
+ CustomerID,
88
+ CompanyName,
89
+ Address,
90
+ Phone,
91
+ Fax?,
92
+ Email,
93
+ LegalContact ) >
94
+
95
+
96
+ <!-- ==== Create user login name, password at Registry for specific TLDs ===== -->
97
+ <!ELEMENT CreateRegistryContact (
98
+ AuthorizedAgent,
99
+ CustomerID,
100
+ RegistryContact) >
101
+
102
+
103
+ <!ELEMENT NewLoginName (#PCDATA)>
104
+ <!ELEMENT NewPassword (#PCDATA)>
105
+ <!ELEMENT RegistryContact (DotTELRegistryContact?)>
106
+ <!ELEMENT DotTELRegistryContact (LoginName, Password)>
107
+
108
+ <!-- === Extend .CA Registrant approval request ======= -->
109
+ <!ELEMENT ExtendCARegistrantApproval (AuthorizedAgent, CustomerID)>
110
+
111
+ <!-- ===================================================================== -->
112
+ <!-- ==== Inclusion of externally defined elements. ====================== -->
113
+ <!-- ===================================================================== -->
114
+
115
+ <!ENTITY % RequestHeader SYSTEM "RequestHeader.dtd">
116
+ %RequestHeader;
117
+
118
+ <!-- sccsID "%TC-INFO%" -->
@@ -0,0 +1,21 @@
1
+ <!-- ===================================================================== -->
2
+ <!-- ==== User Response Message and Body Declaration. =================== -->
3
+ <!-- ===================================================================== -->
4
+
5
+ <!ELEMENT UserResponse (ResponseHeader, Body)>
6
+
7
+ <!ELEMENT Body (
8
+ Status,
9
+ UserID?,
10
+ NicHandle?,
11
+ LoginName? ) >
12
+
13
+
14
+ <!-- ===================================================================== -->
15
+ <!-- ==== Inclusion of externally defined elements. ====================== -->
16
+ <!-- ===================================================================== -->
17
+
18
+ <!ENTITY % ResponseHeader SYSTEM "ResponseHeader.dtd">
19
+ %ResponseHeader;
20
+
21
+ <!-- sccsID "%TC-INFO%" -->
@@ -0,0 +1,15 @@
1
+ <!-- ===================================================================== -->
2
+ <!-- ==== Web Forwarding product actions =========================== -->
3
+ <!-- ===================================================================== -->
4
+ <!-- ==== Create Web Forwarding for existing domain ==== -->
5
+ <!ELEMENT CreateWebForwarding (WebForwardingProduct+, PurchasePeriod)>
6
+ <!-- ==== Modify Web Forwarding products only ===================== -->
7
+ <!ELEMENT ModifyWebForwarding (WebForwardingProduct+)>
8
+ <!-- ==== Delete Web Forwarding products only ===================== -->
9
+ <!ELEMENT DeleteWebForwarding (DomainName+)>
10
+ <!-- ==== Renew Web Forwarding products only ====================== -->
11
+ <!ELEMENT RenewWebForwarding (DomainName+, PurchasePeriod)>
12
+ <!-- ==== Webforwarding elements ====================== -->
13
+ <!ELEMENT WebForwardingProduct (DomainName, DestURL?, Masking?)>
14
+ <!ELEMENT DestURL (#PCDATA)>
15
+ <!ELEMENT Masking (#PCDATA)>
@@ -1,5 +1,5 @@
1
1
  require 'net/https'
2
- require 'erb'
2
+ require 'haml'
3
3
  require 'nokogiri'
4
4
 
5
5
  class Netsol
@@ -31,6 +31,46 @@ class Netsol
31
31
  @host = CONFIG[:host][@mode]
32
32
  end
33
33
 
34
+ # This is to split the lookup request into smaller requests
35
+ # (NetSol blocks requests which are too long)
36
+ def lookup_domain(domain_names)
37
+ result = {}
38
+ result[:domains] = {}
39
+
40
+ group_array(domain_names, per_group = 100).each do |domain_names_100|
41
+ result[:domains].merge!(_lookup_domain(domain_names_100)[:domains])
42
+ end
43
+
44
+ result
45
+ end
46
+
47
+ def _lookup_domain(domain_names)
48
+ @domain_names = domain_names
49
+ response = Nokogiri::XML(transmit(CONFIG[:api][:transaction], request_body).body, &:noblanks)
50
+
51
+ status = response.xpath('/LookupResponse/Body/Status')
52
+ status_code = status.xpath('StatusCode/text()')[0].to_s.to_i
53
+ status_desc = status.xpath('Description/text()')[0].to_s
54
+ success_codes = [11702]
55
+
56
+ raise "Unable to modify registration: [#{status_code}] #{status_desc}" unless success_codes.include?(status_code)
57
+
58
+ domains = {}
59
+
60
+ response.xpath('/LookupResponse/Body/Domain').each do |de|
61
+ domains[de.xpath('DomainNameProperties/text()')[0].to_s] =
62
+ de.xpath('HostData').map{ |host| host.xpath('HostName/text()')[0].to_s }
63
+ end
64
+
65
+ {
66
+ :status => {
67
+ :code => status_code,
68
+ :message => status_desc
69
+ },
70
+ :domains => domains
71
+ }
72
+ end
73
+
34
74
  def find_all_customers_for_partner
35
75
  response = transmit(CONFIG[:api][:transaction], request_body)
36
76
 
@@ -77,11 +117,25 @@ class Netsol
77
117
  end
78
118
  end
79
119
 
80
- def modify_registration
81
- raise 'Not yet implemented'
82
- # @domain_name = nil
83
- # @customer_id = nil
84
- # @auto_renew = nil
120
+ def modify_registration(customer_id, domain_name, auto_renew)
121
+ @customer_id,@domain_name,@auto_renew = customer_id,domain_name,auto_renew
122
+ response = Nokogiri::XML(transmit(CONFIG[:api][:transaction], request_body).body, &:noblanks)
123
+
124
+ status = response.xpath('/OrderResponse/Body/Order/Status')
125
+ status_code = status.xpath('StatusCode/text()')[0].to_s.to_i
126
+ status_desc = status.xpath('Description/text()')[0].to_s
127
+ success_codes = [7000]
128
+
129
+ raise "Unable to modify registration: [#{status_code}] #{status_desc}" unless success_codes.include?(status_code)
130
+
131
+ {
132
+ :status => {
133
+ :code => status_code,
134
+ :message => status_desc
135
+ },
136
+ :reference_number => response.xpath('/OrderResponse/Body/Order/ReferenceNumber/text()')[0].to_s,
137
+ :order_id => response.xpath('/OrderResponse/Body/Order/OrderID/text()')[0].to_s
138
+ }
85
139
  end
86
140
 
87
141
  def create_individual(individual)
@@ -126,6 +180,32 @@ class Netsol
126
180
  }
127
181
  end
128
182
 
183
+ def create_registration(customer_id, domain, purchase_period)
184
+ @customer_id = customer_id
185
+ @domain = {
186
+ :name => domain,
187
+ :purchase_period => purchase_period,
188
+ }
189
+
190
+ response = Nokogiri::XML(transmit(CONFIG[:api][:transaction], request_body).body, &:noblanks)
191
+
192
+ status = response.xpath('/OrderResponse/Body/Order/Status')
193
+ status_code = status.xpath('StatusCode/text()')[0].to_s.to_i
194
+ status_desc = status.xpath('Description/text()')[0].to_s
195
+ success_codes = [7000]
196
+
197
+ raise "Unable to create registration: [#{status_code}] #{status_desc}" unless success_codes.include?(status_code)
198
+
199
+ {
200
+ :status => {
201
+ :code => status_code,
202
+ :message => status_desc
203
+ },
204
+ :order_id => response.xpath('/OrderResponse/Body/Order/OrderID/text()')[0].to_s.to_i,
205
+ :price => response.xpath('/OrderResponse/Body/Order/Price/text()')[0].to_s.to_f
206
+ }
207
+ end
208
+
129
209
  private
130
210
 
131
211
  def root
@@ -135,6 +215,7 @@ private
135
215
  def transmit(location, body)
136
216
  https = Net::HTTP.new(@host, location[:port])
137
217
  https.use_ssl = true
218
+ https.read_timeout = 5 * 60
138
219
  https.verify_mode = OpenSSL::SSL::VERIFY_NONE
139
220
  response = https.start{ |http| http.post(location[:path], body) }
140
221
  raise "Response returned code #{response.code}: #{response.msg}." unless response.code == '200'
@@ -145,11 +226,29 @@ private
145
226
  def request_body
146
227
  method = caller[0][/`([^']*)'/, 1]
147
228
 
148
- ERB.new(File.read("#{root}/xml/#{method}.xml.erb")).result(binding)
229
+ Haml::Engine.new(File.read("#{root}/xml/#{method}.haml")).render(binding)
149
230
  end
150
231
 
151
232
  def header
152
- @header_xml ||= ERB.new(File.read("#{root}/xml/header.xml.erb")).result(binding)
233
+ @header_xml ||= Haml::Engine.new(File.read("#{root}/xml/_header.haml")).render(binding)
234
+ end
235
+
236
+ def auth
237
+ @auth_xml ||= Haml::Engine.new(File.read("#{root}/xml/_auth.haml")).render(binding)
238
+ end
239
+
240
+ # This is necessary as including activesupport (outside of rails) is a nightmare prior to v3.0
241
+ def group_array(array, per_group)
242
+ container = []
243
+ array.each do |item|
244
+ if container.last && container.last.size < per_group
245
+ container.last << item
246
+ else
247
+ container << [item]
248
+ end
249
+ end
250
+
251
+ container
153
252
  end
154
253
 
155
254
  end
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'netsol'
7
- spec.version = '0.1'
7
+ spec.version = '0.2.0'
8
8
  spec.authors = ['Michael Malet']
9
9
  spec.email = ['michael@tagadab.com']
10
10
  spec.description = %q{A gem to make interacting with NetSol's Partner API less painful}
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = ['lib']
19
19
 
20
20
  spec.add_dependency 'nokogiri', '~> 1.4.7'
21
+ spec.add_dependency 'haml'
21
22
 
22
23
  spec.add_development_dependency 'bundler'
23
24
  spec.add_development_dependency 'pry'
@@ -0,0 +1,4 @@
1
+ %AuthorizedAgent(SystemUserType="partner")
2
+ %SystemUser
3
+ %UserID= @user
4
+ %Password= @pass
@@ -0,0 +1,5 @@
1
+ %RequestHeader
2
+ %VERSION_6_8
3
+ %Authentication
4
+ %PartnerID= @user
5
+ %PartnerPassword= @pass
@@ -0,0 +1,11 @@
1
+ !!! XML
2
+ %LookupRequest
3
+ = header
4
+ %Body
5
+ %AuthorizedAgent(SystemUserType="partner")
6
+ %SystemUser
7
+ %UserID= @user
8
+ %Password= @pass
9
+ %LookupDomain
10
+ - @domain_names.each do |domain_name|
11
+ %DomainName= domain_name
@@ -0,0 +1,21 @@
1
+ !!! XML
2
+ %UserRequest
3
+ = header
4
+ %Body
5
+ %CreateIndividual
6
+ %LoginName= @individual[:login_name]
7
+ %Password= @individual[:password]
8
+ %FirstName= @individual[:first_name]
9
+ %MiddleName= @individual[:middle_name]
10
+ %LastName= @individual[:last_name]
11
+ %Address
12
+ %AddressLine1= @individual[:address][:line_1]
13
+ %City= @individual[:address][:city]
14
+ %State= @individual[:address][:state]
15
+ %PostalCode= @individual[:address][:post_code]
16
+ %CountryCode= @individual[:address][:country_code]
17
+ %Phone= @individual[:phone]
18
+ %Fax= @individual[:fax]
19
+ %Email= @individual[:email]
20
+ %AuthQuestion= @individual[:auth][:question]
21
+ %AuthAnswer= @individual[:auth][:answer]
@@ -0,0 +1,10 @@
1
+ !!! XML
2
+ %OrderRequest
3
+ = header
4
+ %Body
5
+ = auth
6
+ %CustomerID= @customer_id
7
+ %Product
8
+ %CreateRegistration
9
+ %DomainName= @domain[:name]
10
+ %PurchasePeriod= @domain[:purchase_period]
@@ -0,0 +1,5 @@
1
+ !!! XML
2
+ %PartnerManagerRequest
3
+ = header
4
+ %Body
5
+ %FindAllCustomersForPartner
@@ -0,0 +1,5 @@
1
+ !!! XML
2
+ %PartnerManagerRequest
3
+ = header
4
+ %Body
5
+ %FindAllDomainsForPartner