Class: Request
Constant Summary
Constants inherited from MESD
Instance Attribute Summary
Attributes inherited from MESD
#curobj, #current_body, #last_error, #session
Instance Method Summary collapse
- #data(*args) ⇒ Object
-
#initialize(args) ⇒ Request
constructor
A new instance of Request.
Methods inherited from MESD
#get_all_requests, #get_last_requests, #session_healthy?
Constructor Details
#initialize(args) ⇒ Request
Returns a new instance of Request.
203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/me_sd.rb', line 203 def initialize(args) if args[:id] @id = args[:id] elsif args[:url] if args[:url] =~ /WorkOrder\.do\?woMode=viewWO&woID=(?<ID>\d+)&&fromListView=true/ @id = Regexp.last_match("ID") else return false end end @session = args[:session] true end |
Instance Method Details
#data(*args) ⇒ Object
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 |
# File 'lib/me_sd.rb', line 217 def data(*args) unless self.id @last_error = "id error" return false end if args.size == 0 only = [] else only = args end unless session_healthy?(@session) @last_error = "session error" return false end props = [ { name: :description, url: "WorkOrder.do?woMode=viewWO&woID=#{self.id}", search_function: { name: "value_between", args: ["<td style=\"padding-left:10px;\" colspan=\"3\" valign=\"top\" class=\"fontBlack textareadesc\">", "</td>"], }, post_processing_functions: [:strip], }, { name: :resolution, url: "AddResolution.do?mode=viewWOResolution&woID=#{self.id}", search_function: { name: "value_between", args: ["<td colspan=\"3\" valign=\"top\" class=\"fontBlack textareadesc\">", "</td>"], }, post_processing_functions: [:strip], }, { name: :status, url: "WorkOrder.do?woMode=viewWO&woID=#{self.id}", search_function: { name: "html_parse", args: [["css", "#WOHeaderSummary_DIV"], ["css", "#status_PH"], "text"], }, post_processing_functions: [:semicolon_space_value, :symbolize], }, { name: :priority, url: "WorkOrder.do?woMode=viewWO&woID=#{self.id}", search_function: { name: "html_parse", args: [["css", "#WOHeaderSummary_DIV"], ["css", "#priority_PH"], "text"], }, post_processing_functions: [:semicolon_space_value, :symbolize], }, { name: :author_name, url: "WorkOrder.do?woMode=viewWO&woID=#{self.id}", search_function: { name: "html_parse", args: [["css", "#requesterName_PH"], "text"], }, }, { name: :create_date, url: "WorkOrder.do?woMode=viewWO&woID=#{self.id}", search_function: { name: "html_parse", args: [["css", "#CREATEDTIME_CUR"], "text"], }, post_processing_functions: [:parse_date], }, { name: :name, url: "WorkOrder.do?woMode=viewWO&woID=#{self.id}", search_function: { name: "html_parse", args: [["css", "#requestSubject_ID"], "text"], }, post_processing_functions: [:strip], }, ] props.each do |property| next if !only.empty? && !only.include?(property[:name]) uri = URI("http://#{@session[:host]}:#{@session[:port]}/#{property[:url]}") begin Net::HTTP.start(uri.host, uri.port) do |http| http_request = Net::HTTP::Get.new(uri) http_request.add_field("Cookie", "#{@session[:cookie]}") http_request = http.request(http_request) @current_body = http_request.response.body auth_error_pos = @current_body.index("AuthError") if auth_error_pos @last_error = "auth error" return false end permitions_error_pos = @current_body.index("Request does not fall under your permitted scope") if permitions_error_pos @last_error = "no permitions error" return false end operational_error_pos = @current_body.index("failurebox") if operational_error_pos @last_error = "operational error" return false end value = self.method(property[:search_function][:name]).call(property[:search_function][:args]) if property[:post_processing_functions] functions = property[:post_processing_functions] functions.each do |function| if value.methods.include?(function) value = value.method(function).call elsif self.private_methods.include?(function) value = self.method(function).call(value) end end end self.send("#{property[:name]}=", value) end rescue *EXCEPTIONS => @last_error end end self end |