Class: Aspera::ApiDetector
- Inherits:
-
Object
- Object
- Aspera::ApiDetector
- Defined in:
- lib/aspera/api_detector.rb
Overview
detect Aspera product by calling API
Class Method Summary collapse
-
.discover_product(url) ⇒ Object
if not found: :product=>:unknown,:version=>‘unknown’.
Class Method Details
.discover_product(url) ⇒ Object
if not found: :product=>:unknown,:version=>‘unknown’
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/aspera/api_detector.rb', line 9 def self.discover_product(url) #uri=URI.parse(url) api=Rest.new({:base_url=>url}) # Node begin result=api.call({:operation=>'GET',:subpath=>'ping'}) if result[:http].body.eql?('') return {:product=>:node,:version=>'unknown'} end rescue SocketError => e raise e rescue => e Log.log.debug("not node (#{e.class}: #{e})") end # AoC begin result=api.call({:operation=>'GET',:subpath=>'',:headers=>{'Accept'=>'text/html'}}) if result[:http].body.include?('content="AoC"') return {:product=>:aoc,:version=>'unknown'} end rescue SocketError => e raise e rescue => e Log.log.debug("not aoc (#{e.class}: #{e})") end # Faspex begin result=api.call({:operation=>'POST',:subpath=>'aspera/faspex',:headers=>{'Accept'=>'application/xrds+xml'},:text_body_params=>''}) if result[:http].body.start_with?('<?xml') res_s=XmlSimple.xml_in(result[:http].body, {"ForceArray" => false}) version=res_s['XRD']['application']['version'] #return JSON.pretty_generate(res_s) end return {:product=>:faspex,:version=>version} rescue Log.log.debug("not faspex") end # Shares begin result=api.read('node_api/app') Log.log.warn("not supposed to work") rescue RestCallError => e if e.response.code.to_s.eql?('401') and e.response.body.eql?('{"error":{"user_message":"API user authentication failed"}}') return {:product=>:shares,:version=>'unknown'} end Log.log.warn("not shares: #{e.response.code} #{e.response.body}") rescue end return {:product=>:unknown,:version=>'unknown'} end |