netsol 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA512:
3
+ metadata.gz: 456ae34da22a474169e49e446cad41794d34fc028324d9ec2e8d83202427902b9943dafd417c2091f5cd96479632105789f8ef50b9d96963176c432e7c8df869
4
+ data.tar.gz: af1f3982e3fa2615532e68d344260e45b0a1f76ce2425a4c76efce6f0ca5b531d3b7e5234d1c6e0882a8e887b5800c861eead0ff747cb1fc20ca182988e94b65
5
+ SHA1:
6
+ metadata.gz: c5b89f6dc37ca7e3e7e32f25d069ee12b3a83263
7
+ data.tar.gz: 7f05543a30650aa955da407da61735199a20d859
@@ -0,0 +1 @@
1
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in netsol.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Malet
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,17 @@
1
+ netsol
2
+ ======
3
+
4
+ NetSol Partners API Gem
5
+
6
+ ```ruby
7
+ require 'netsol'
8
+
9
+ ns = Netsol.new('12345678', 'test_password', :test)
10
+ # ns = Netsol.new('12345678', 'live_password', :live)
11
+
12
+ customers = ns.find_all_customers_for_partner
13
+ # => {:nic_handle=>"1234567P", :type=>"Individual", :login_name=>"1234567", :first_name=>"John", :last_name=>"Smith", :user_id=>"1234567"}, ...
14
+
15
+ domains = ns.find_all_domains_for_partner
16
+ # => {:auto_renew=>false, :product_id=>"WN.D.XXXXXXX", :domain_name=>"XXXXXX.COM", :customer_id=>"1234567", :product_type=>"Registration"}, ...
17
+ ```
@@ -0,0 +1,155 @@
1
+ require 'net/https'
2
+ require 'erb'
3
+ require 'nokogiri'
4
+
5
+ class Netsol
6
+
7
+ CONFIG = {
8
+ :host => {
9
+ :test => 'partners.pte.networksolutions.com',
10
+ :live => 'partners.networksolutions.com'
11
+ },
12
+ :api => {
13
+ :availability => {
14
+ :path => '/invoke/vpp/AvailabilityService',
15
+ :port => 8010
16
+ },
17
+ :transaction => {
18
+ :path => '/invoke/vpp/TransactionService',
19
+ :port => 8020
20
+ }
21
+ }
22
+ }
23
+
24
+ def initialize(user, pass, mode = :live)
25
+ environments = [:test, :live]
26
+ unless environments.include? mode
27
+ raise "mode is invalid, must be #{environments.map(&:inspect).join(' or ')}"
28
+ end
29
+
30
+ @user,@pass,@mode = user,pass,mode
31
+ @host = CONFIG[:host][@mode]
32
+ end
33
+
34
+ def find_all_customers_for_partner
35
+ response = transmit(CONFIG[:api][:transaction], request_body)
36
+
37
+ customers = Nokogiri::XML(response.body, &:noblanks).xpath('//Customer').map do |c|
38
+ type = c.children.first.name
39
+ data = {
40
+ :type => type,
41
+ :user_id => c.xpath("#{type}/UserID/text()")[0].to_s,
42
+ :nic_handle => c.xpath("#{type}/NicHandle/text()")[0].to_s,
43
+ :login_name => c.xpath("#{type}/LoginName/text()")[0].to_s
44
+ }
45
+
46
+ case data[:type]
47
+ when 'Individual'
48
+ data.merge!(
49
+ :first_name => c.xpath("#{type}/FirstName/text()")[0].to_s,
50
+ :last_name => c.xpath("#{type}/LastName/text()")[0].to_s
51
+ )
52
+ when 'Business'
53
+ data.merge!(
54
+ :company_name => c.xpath("#{type}/CompanyName/text()")[0].to_s,
55
+ :legal_contact => {
56
+ :first_name => c.xpath("#{type}/LegalContactFirstName/text()")[0].to_s,
57
+ :last_name => c.xpath("#{type}/LegalContactLastName/text()")[0].to_s
58
+ }
59
+ )
60
+ end
61
+
62
+ data
63
+ end
64
+ end
65
+
66
+ def find_all_domains_for_partner
67
+ response = transmit(CONFIG[:api][:transaction], request_body)
68
+
69
+ domains = Nokogiri::XML(response.body, &:noblanks).xpath('//Domain').map do |domain|
70
+ {
71
+ :product_id => domain.xpath('ProductID/text()')[0].to_s,
72
+ :domain_name => domain.xpath('DomainName/text()')[0].to_s,
73
+ :customer_id => domain.xpath('CustomerID/text()')[0].to_s,
74
+ :product_type => domain.xpath('ProductType/text()')[0].to_s,
75
+ :auto_renew => (domain.xpath('AutoRenew/text()')[0].to_s == 'Y')
76
+ }
77
+ end
78
+ end
79
+
80
+ def modify_registration
81
+ raise 'Not yet implemented'
82
+ # @domain_name = nil
83
+ # @customer_id = nil
84
+ # @auto_renew = nil
85
+ end
86
+
87
+ def create_individual(individual)
88
+ @individual = {
89
+ :login_name => nil,
90
+ :password => nil,
91
+ :first_name => nil,
92
+ :middle_name => nil,
93
+ :last_name => nil,
94
+ :address => {
95
+ :line_1 => nil,
96
+ :city => nil,
97
+ :state => nil,
98
+ :post_code => nil,
99
+ :country_code => nil
100
+ },
101
+ :phone => nil,
102
+ :fax => nil,
103
+ :email => nil,
104
+ :auth => {
105
+ :question => nil,
106
+ :answer => nil
107
+ }
108
+ }.merge(individual)
109
+
110
+ response = Nokogiri::XML(transmit(CONFIG[:api][:transaction], request_body).body, &:noblanks)
111
+
112
+ status = response.xpath('/UserResponse/Body/Status')
113
+ status_code = status.xpath('StatusCode/text()')[0].to_s.to_i
114
+ status_desc = status.xpath('Description/text()')[0].to_s
115
+ success_codes = [5700, 5703]
116
+
117
+ raise "Unable to create individual: [#{status_code}] #{status_desc}" unless success_codes.include?(status_code)
118
+
119
+ {
120
+ :status => {
121
+ :code => status_code,
122
+ :message => status_desc
123
+ },
124
+ :user_id => response.xpath('/UserResponse/Body/UserID/text()')[0].to_s.to_i,
125
+ :login_name => response.xpath('/UserResponse/Body/LoginName/text()')[0].to_s
126
+ }
127
+ end
128
+
129
+ private
130
+
131
+ def root
132
+ @@root ||= File.expand_path('../..', __FILE__)
133
+ end
134
+
135
+ def transmit(location, body)
136
+ https = Net::HTTP.new(@host, location[:port])
137
+ https.use_ssl = true
138
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
139
+ response = https.start{ |http| http.post(location[:path], body) }
140
+ raise "Response returned code #{response.code}: #{response.msg}." unless response.code == '200'
141
+
142
+ response
143
+ end
144
+
145
+ def request_body
146
+ method = caller[0][/`([^']*)'/, 1]
147
+
148
+ ERB.new(File.read("#{root}/xml/#{method}.xml.erb")).result(binding)
149
+ end
150
+
151
+ def header
152
+ @header_xml ||= ERB.new(File.read("#{root}/xml/header.xml.erb")).result(binding)
153
+ end
154
+
155
+ end
@@ -0,0 +1,24 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'netsol'
7
+ spec.version = '0.1'
8
+ spec.authors = ['Michael Malet']
9
+ spec.email = ['michael@tagadab.com']
10
+ spec.description = %q{A gem to make interacting with NetSol's Partner API less painful}
11
+ spec.summary = spec.description
12
+ spec.homepage = 'http://www.tagadab.com'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_dependency 'nokogiri', '~> 1.4.7'
21
+
22
+ spec.add_development_dependency 'bundler'
23
+ spec.add_development_dependency 'pry'
24
+ end
@@ -0,0 +1,25 @@
1
+ <?xml version='1.0' encoding='UTF-8' standalone='yes'?>
2
+ <UserRequest>
3
+ <%= header %>
4
+ <Body>
5
+ <CreateIndividual>
6
+ <LoginName><%= @individual[:login_name] %></LoginName>
7
+ <Password><%= @individual[:password] %></Password>
8
+ <FirstName><%= @individual[:first_name] %></FirstName>
9
+ <MiddleName><%= @individual[:middle_name] %></MiddleName>
10
+ <LastName><%= @individual[:last_name] %></LastName>
11
+ <Address>
12
+ <AddressLine1><%= @individual[:address][:line_1] %></AddressLine1>
13
+ <City><%= @individual[:address][:city] %></City>
14
+ <State><%= @individual[:address][:state] %></State>
15
+ <PostalCode><%= @individual[:address][:post_code] %></PostalCode>
16
+ <CountryCode><%= @individual[:address][:country_code] %></CountryCode>
17
+ </Address>
18
+ <Phone><%= @individual[:phone] %></Phone>
19
+ <Fax><%= @individual[:fax] %></Fax>
20
+ <Email><%= @individual[:email] %></Email>
21
+ <AuthQuestion><%= @individual[:auth][:question] %></AuthQuestion>
22
+ <AuthAnswer><%= @individual[:auth][:answer] %></AuthAnswer>
23
+ </CreateIndividual>
24
+ </Body>
25
+ </UserRequest>
@@ -0,0 +1,7 @@
1
+ <?xml version='1.0' encoding='UTF-8' standalone='yes'?>
2
+ <PartnerManagerRequest>
3
+ <%= header %>
4
+ <Body>
5
+ <FindAllCustomersForPartner/>
6
+ </Body>
7
+ </PartnerManagerRequest>
@@ -0,0 +1,7 @@
1
+ <?xml version='1.0' encoding='UTF-8' standalone='yes'?>
2
+ <PartnerManagerRequest>
3
+ <%= header %>
4
+ <Body>
5
+ <FindAllDomainsForPartner/>
6
+ </Body>
7
+ </PartnerManagerRequest>
@@ -0,0 +1,7 @@
1
+ <RequestHeader>
2
+ <VERSION_6_7/>
3
+ <Authentication>
4
+ <PartnerID><%= @user %></PartnerID>
5
+ <PartnerPassword><%= @pass %></PartnerPassword>
6
+ </Authentication>
7
+ </RequestHeader>
@@ -0,0 +1,21 @@
1
+ <?xml version='1.0' encoding='UTF-8' standalone='yes'?>
2
+ <OrderRequest>
3
+ <%= header %>
4
+ <Body>
5
+ <AuthorizedAgent SystemUserType="partner">
6
+ <SystemUser>
7
+ <UserID><%= @user %></UserID>
8
+ <Password><%= @pass %></Password>
9
+ </SystemUser>
10
+ </AuthorizedAgent>
11
+ <CustomerID><%= @customer_id %></CustomerID>
12
+ <Billing>
13
+ <AutoRenew><%= @auto_renew %></AutoRenew>
14
+ </Billing>
15
+ <Product>
16
+ <ModifyRegistration>
17
+ <DomainName><%= @domain_name %></DomainName>
18
+ </ModifyRegistration>
19
+ </Product>
20
+ </Body>
21
+ </OrderRequest>
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: netsol
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.1"
5
+ platform: ruby
6
+ authors:
7
+ - Michael Malet
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2014-04-29 00:00:00 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nokogiri
16
+ prerelease: false
17
+ requirement: &id001 !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.4.7
22
+ type: :runtime
23
+ version_requirements: *id001
24
+ - !ruby/object:Gem::Dependency
25
+ name: bundler
26
+ prerelease: false
27
+ requirement: &id002 !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - &id003
30
+ - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id002
35
+ - !ruby/object:Gem::Dependency
36
+ name: pry
37
+ prerelease: false
38
+ requirement: &id004 !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - *id003
41
+ type: :development
42
+ version_requirements: *id004
43
+ description: A gem to make interacting with NetSol's Partner API less painful
44
+ email:
45
+ - michael@tagadab.com
46
+ executables: []
47
+
48
+ extensions: []
49
+
50
+ extra_rdoc_files: []
51
+
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE
56
+ - README.md
57
+ - lib/netsol.rb
58
+ - netsol.gemspec
59
+ - xml/create_individual.xml.erb
60
+ - xml/find_all_customers_for_partner.xml.erb
61
+ - xml/find_all_domains_for_partner.xml.erb
62
+ - xml/header.xml.erb
63
+ - xml/modify_registration.xml.erb
64
+ homepage: http://www.tagadab.com
65
+ licenses:
66
+ - MIT
67
+ metadata: {}
68
+
69
+ post_install_message:
70
+ rdoc_options: []
71
+
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - *id003
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - *id003
80
+ requirements: []
81
+
82
+ rubyforge_project:
83
+ rubygems_version: 2.0.14
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: A gem to make interacting with NetSol's Partner API less painful
87
+ test_files: []
88
+
89
+ has_rdoc: