ultrasoap 0.0.5 → 0.1.0

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: ba939da1c7f279494a0088b419718a9b7f15982e
4
- data.tar.gz: ef70972332257c84824a87fd2f0e3cb9ee47eeaa
3
+ metadata.gz: 42be934e7d4210f7f31440a0861662c26caec287
4
+ data.tar.gz: 01dc2abf4e427ed01ab2fe42c41a1bf704f9f55c
5
5
  SHA512:
6
- metadata.gz: 0a6e5a79638ff07d3855c7b63d42cf3985c55a94d868696a48b07f19422af0134dbce15fdf2aa699bfac7939704a8af72300f985fd15d56f85a6f479484ad381
7
- data.tar.gz: 97c4eab1a249951a82787855eea743a934d322fe23de6df551e59f4bef3103a8ccf17aa74af4bf160c4c0f39d792a3f2aca2be9e055b524be784dfa593e8a052
6
+ metadata.gz: d1b72386af2e239a697d10bbc3e423dc2003e608e60e5083aca328f51285bb91c8e44a40679adfb80a5aea1ddcbe4cd7a97976de0859943fc732b42aadec4c01
7
+ data.tar.gz: a23b6921433a7e1c46d7ed1531a455c7f3e616ca2c9c3d0f7fda9aa0bffef68220c49717c417a2154abd01b715fceb05b2bbf423c184ac6d971835aac21c6b87
data/lib/client.rb ADDED
@@ -0,0 +1,199 @@
1
+ require 'savon'
2
+ require 'logger'
3
+
4
+ module UltraSOAP
5
+
6
+ class Client
7
+
8
+ # Class variables
9
+ @logger
10
+
11
+ @logdest = './ultrasoap.log'
12
+ @logging = false
13
+ @log_level = 'error'
14
+ @test_wsdl = 'https://testapi.ultradns.com/UltraDNS_WS/v01?wsdl'
15
+ @prod_wsdl = 'https://ultra-api.ultradns.com/UltraDNS_WS/v01?wsdl'
16
+ @environment = 'production'
17
+ @transaction_id = nil
18
+ @use_transactions = false
19
+
20
+ class << self
21
+ attr_accessor :logdest
22
+ attr_accessor :logging
23
+ attr_accessor :log_level
24
+ attr_accessor :transaction_id
25
+ attr_accessor :test_wsdl
26
+ attr_accessor :prod_wsdl
27
+ attr_accessor :environment
28
+ attr_accessor :use_transactions
29
+ end
30
+
31
+ # Instance variables
32
+ attr_accessor :logging
33
+ attr_accessor :loglevel
34
+
35
+ # Constructor
36
+ def initialize()
37
+ # Exits if username or password aren't specified.
38
+ return nil unless !(Settings.username.nil? or Settings.password.nil?)
39
+
40
+ username = Settings.username
41
+ password = Settings.password
42
+
43
+ @environment = Settings['environment'] || Client.environment
44
+
45
+ # We don't need the following to be instance variables
46
+ ultra_wsdl = (@environment == 'test' ? (Settings['test_wsdl'] || Client.test_wsdl) : (Settings['prod_wsdl'] || Client.prod_wsdl))
47
+
48
+ # Setting up parameter values, if provided. If not, defaults are assumed
49
+
50
+ @use_transactions = Settings['use_transactions'] || Client.use_transactions
51
+ @logdest = Settings['logfile'] || Client.logdest
52
+
53
+ @logger = Logger.new(@logdest)
54
+
55
+ logging = Settings['logging'] || Client.logging
56
+
57
+ log_lev = Settings['log_level'] || Client.log_level
58
+
59
+ begin
60
+ # For some reason, if I use the instance variable, Savon.client doesn't work properly
61
+
62
+ @client = Savon.client do
63
+ wsdl ultra_wsdl
64
+ env_namespace 'soapenv'
65
+ wsse_auth(username, password)
66
+ element_form_default :unqualified
67
+ log logging
68
+ log_level log_lev.to_sym
69
+ pretty_print_xml true
70
+ end
71
+ rescue Exception => e
72
+ @logger.error("Error in ultrasoap.initialize: " + e.message)
73
+ raise 'Error in ultrasoap initialization, check log file'
74
+ end
75
+ end
76
+
77
+ # Main method to send SOAP requests
78
+ #
79
+ # Parameters:
80
+ # * method: the SOAP send_request
81
+ # * message: the message hash
82
+ def send_request(method, message, strip_namespaces=true)
83
+ # If the client is using transactions, append the transaction id to the message hash
84
+ if @use_transactions == true
85
+ transaction_hash = { :transaction_id => @transaction_id }
86
+ message.merge(transaction_hash)
87
+ end
88
+
89
+ begin
90
+ @response = @client.call method, message: message
91
+ return Nokogiri::XML(@response.to_xml).remove_namespaces!
92
+ rescue Exception => e
93
+ @logger.error("Error in ultrasoap.send_request: " + e.message)
94
+ return nil
95
+ end
96
+ end
97
+
98
+ # Starts a transaction and sets the @transaction_id variable
99
+ def transaction_start
100
+ begin
101
+ response = self.send_request :start_transaction
102
+ xml_response = Nokogiri::XML(response.to_xml).remove_namespaces!
103
+ @transaction_id = xml_response.xpath("//transactionId/text()")
104
+ rescue Exception => e
105
+ @logger.error("Error in ultrasoap.transaction_start: " + e.message)
106
+ end
107
+ end
108
+
109
+ # Rolls back the current transaction
110
+ def transaction_rollback
111
+ return nil unless @transaction_id != nil
112
+
113
+ message = {
114
+ :transaction_id => @transaction_id.to_s
115
+ }
116
+
117
+ begin
118
+ trans_rollback = self.send_request :rollback_transaction, message
119
+ rescue Exception => e
120
+ @logger.error("Error in ultrasoap.transaction_rollback: " + e.message)
121
+ end
122
+ end
123
+
124
+ # Commit the current transaction
125
+ def transaction_commit
126
+ return nil unless @transaction_id != nil
127
+
128
+ message = {
129
+ :transaction_id => @transaction_id.to_s
130
+ }
131
+
132
+ begin
133
+ trans_commit = self.send_request :commit_transaction, message
134
+ rescue Exception => e
135
+ @logger.error("Error in ultrasoap.transaction_commit: " + e.message)
136
+ end
137
+ end
138
+
139
+ # Helper method to retrieve load balancing pools data
140
+ # Parameters:
141
+ # - zone (don't forget the trailing dot)
142
+ def get_lb_pools(zone)
143
+ message = {
144
+ :zone_name => zone,
145
+ :lb_pool_type => 'SB'
146
+ }
147
+
148
+ begin
149
+ response = self.send_request :get_load_balancing_pools_by_zone, message
150
+ return response
151
+ rescue Exception => e
152
+ @logger.error("Error in retrieving SB pools for the zone #{zone}: #{e.message}")
153
+ return nil
154
+ end
155
+ end
156
+
157
+ # Helper method to retrieve Pool's records
158
+ # Parameters:
159
+ # - poolID
160
+ def get_pool_records(pool_id)
161
+ message = {
162
+ :pool_id => pool_id.to_s
163
+ }
164
+
165
+ begin
166
+ return self.send_request :get_pool_records, message
167
+ rescue Exception => e
168
+ @logger.error("Error while retrieving Pool Records for the Pool ID #{pool_id.to_s}: #{e.message}")
169
+ end
170
+ end
171
+
172
+ # LOOKUP methods
173
+
174
+ def lookup_pool_type(pt_code)
175
+ case pt_code.to_s
176
+ when 'SB'
177
+ 'SiteBacker'
178
+ when 'RD'
179
+ 'Resource Distribution'
180
+ when 'TC'
181
+ 'Traffic Controller'
182
+ else
183
+ 'Other'
184
+ end
185
+ end
186
+
187
+ def lookup_response_method(rm_code)
188
+ case rm_code.to_s
189
+ when 'FX'
190
+ 'Fixed'
191
+ when 'RR'
192
+ 'Round Robin'
193
+ when 'RD'
194
+ 'Random'
195
+ end
196
+ end
197
+
198
+ end
199
+ end
data/lib/ultrasoap.rb CHANGED
@@ -1,199 +1,3 @@
1
- require 'savon'
2
- require 'logger'
3
-
4
- module UltraSOAP
5
-
6
- class Client
7
-
8
- # Class variables
9
- @logger
10
-
11
- @logdest = './ultrasoap.log'
12
- @logging = false
13
- @log_level = 'error'
14
- @test_wsdl = 'https://testapi.ultradns.com/UltraDNS_WS/v01?wsdl'
15
- @prod_wsdl = 'https://ultra-api.ultradns.com/UltraDNS_WS/v01?wsdl'
16
- @environment = 'production'
17
- @transaction_id = nil
18
- @use_transactions = false
19
-
20
- class << self
21
- attr_accessor :logdest
22
- attr_accessor :logging
23
- attr_accessor :log_level
24
- attr_accessor :transaction_id
25
- attr_accessor :test_wsdl
26
- attr_accessor :prod_wsdl
27
- attr_accessor :environment
28
- attr_accessor :use_transactions
29
- end
30
-
31
- # Instance variables
32
- attr_accessor :logging
33
- attr_accessor :loglevel
34
-
35
- # Constructor
36
- def initialize()
37
- # Exits if username or password aren't specified.
38
- return nil unless !(Settings.username.nil? or Settings.password.nil?)
39
-
40
- username = Settings.username
41
- password = Settings.password
42
-
43
- @environment = Settings['environment'] || Client.environment
44
-
45
- # We don't need the following to be instance variables
46
- ultra_wsdl = (@environment == 'test' ? (Settings['test_wsdl'] || Client.test_wsdl) : (Settings['prod_wsdl'] || Client.prod_wsdl))
47
-
48
- # Setting up parameter values, if provided. If not, defaults are assumed
49
-
50
- @use_transactions = Settings['use_transactions'] || Client.use_transactions
51
- @logdest = Settings['logfile'] || Client.logdest
52
-
53
- @logger = Logger.new(@logdest)
54
-
55
- logging = Settings['logging'] || Client.logging
56
-
57
- log_lev = Settings['log_level'] || Client.log_level
58
-
59
- begin
60
- # For some reason, if I use the instance variable, Savon.client doesn't work properly
61
-
62
- @client = Savon.client do
63
- wsdl ultra_wsdl
64
- env_namespace 'soapenv'
65
- wsse_auth(username, password)
66
- element_form_default :unqualified
67
- log logging
68
- log_level log_lev.to_sym
69
- pretty_print_xml true
70
- end
71
- rescue Exception => e
72
- @logger.error("Error in ultrasoap.initialize: " + e.message)
73
- raise 'Error in ultrasoap initialization, check log file'
74
- end
75
- end
76
-
77
- # Main method to send SOAP requests
78
- #
79
- # Parameters:
80
- # * method: the SOAP send_request
81
- # * message: the message hash
82
- def send_request(method, message, strip_namespaces=true)
83
- # If the client is using transactions, append the transaction id to the message hash
84
- if @use_transactions == true
85
- transaction_hash = { :transaction_id => @transaction_id }
86
- message.merge(transaction_hash)
87
- end
88
-
89
- begin
90
- @response = @client.call method, message: message
91
- return Nokogiri::XML(@response.to_xml).remove_namespaces!
92
- rescue Exception => e
93
- @logger.error("Error in ultrasoap.send_request: " + e.message)
94
- return nil
95
- end
96
- end
97
-
98
- # Starts a transaction and sets the @transaction_id variable
99
- def transaction_start
100
- begin
101
- response = self.send_request :start_transaction
102
- xml_response = Nokogiri::XML(response.to_xml).remove_namespaces!
103
- @transaction_id = xml_response.xpath("//transactionId/text()")
104
- rescue Exception => e
105
- @logger.error("Error in ultrasoap.transaction_start: " + e.message)
106
- end
107
- end
108
-
109
- # Rolls back the current transaction
110
- def transaction_rollback
111
- return nil unless @transaction_id != nil
112
-
113
- message = {
114
- :transaction_id => @transaction_id.to_s
115
- }
116
-
117
- begin
118
- trans_rollback = self.send_request :rollback_transaction, message
119
- rescue Exception => e
120
- @logger.error("Error in ultrasoap.transaction_rollback: " + e.message)
121
- end
122
- end
123
-
124
- # Commit the current transaction
125
- def transaction_commit
126
- return nil unless @transaction_id != nil
127
-
128
- message = {
129
- :transaction_id => @transaction_id.to_s
130
- }
131
-
132
- begin
133
- trans_commit = self.send_request :commit_transaction, message
134
- rescue Exception => e
135
- @logger.error("Error in ultrasoap.transaction_commit: " + e.message)
136
- end
137
- end
138
-
139
- # Helper method to retrieve load balancing pools data
140
- # Parameters:
141
- # - zone (don't forget the trailing dot)
142
- def get_lb_pools(zone)
143
- message = {
144
- :zone_name => zone,
145
- :lb_pool_type => 'SB'
146
- }
147
-
148
- begin
149
- response = self.send_request :get_load_balancing_pools_by_zone, message
150
- return response
151
- rescue Exception => e
152
- @logger.error("Error in retrieving SB pools for the zone #{zone}: #{e.message}")
153
- return nil
154
- end
155
- end
156
-
157
- # Helper method to retrieve Pool's records
158
- # Parameters:
159
- # - poolID
160
- def get_pool_records(pool_id)
161
- message = {
162
- :pool_id => pool_id.to_s
163
- }
164
-
165
- begin
166
- return self.send_request :get_pool_records, message
167
- rescue Exception => e
168
- @logger.error("Error while retrieving Pool Records for the Pool ID #{pool_id.to_s}: #{e.message}")
169
- end
170
- end
171
-
172
- # LOOKUP methods
173
-
174
- def lookup_pool_type(pt_code)
175
- case pt_code.to_s
176
- when 'SB'
177
- 'SiteBacker'
178
- when 'RD'
179
- 'Resource Distribution'
180
- when 'TC'
181
- 'Traffic Controller'
182
- else
183
- 'Other'
184
- end
185
- end
186
-
187
- def lookup_response_method(rm_code)
188
- case rm_code.to_s
189
- when 'FX'
190
- 'Fixed'
191
- when 'RR'
192
- 'Round Robin'
193
- when 'RD'
194
- 'Random'
195
- end
196
- end
197
-
198
- end
199
- end
1
+ require 'client.rb'
2
+ require 'settings.rb'
3
+ require 'constants.rb'
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'ultrasoap'
3
- s.version = '0.0.5'
3
+ s.version = '0.1.0'
4
4
  s.summary = "Simple Ruby client library for UltraDNS SOAP API"
5
5
  s.description = "Connect to Neustar's UltraDNS SOAP API. FKA ultrasoap-ruby"
6
6
  s.authors = ["Gabriel Sambarino"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ultrasoap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Sambarino
@@ -62,6 +62,7 @@ files:
62
62
  - Gemfile
63
63
  - LICENSE
64
64
  - README.md
65
+ - lib/client.rb
65
66
  - lib/constants.rb
66
67
  - lib/settings.rb
67
68
  - lib/ultrasoap.rb