Class: HmxClient::Hmx
- Inherits:
-
Object
- Object
- HmxClient::Hmx
- Defined in:
- lib/hmx/hmx.rb
Constant Summary collapse
- @@distMap =
{ :GetPartitions => [ 'admin', 'GETPARTITIONS', 'partitions', []], :ClonePartition => [ 'admin', 'CLONEPARTITION', 'partition', [ { :pos => 0, :name => 'destination' }, { :pos => 1, :name => 'copyStyle' } ] ], :Info => [ 'user', 'INFO', 'response', []], :GetData => [ 'user', 'GETDATA', 'data', [ { :pos => 0, :name => 'displayName' } ]], :GetContent => [ 'user', 'GETCONTENT', 'content', [ { :pos => 0, :name => 'displayName' }]], :PutData => ['user', 'PUTDATA', 'data', [ { :pos => 0, :name => 'data', :file => 1, :json => 1 }]], :PutSimpleData => [ 'user', 'PUTSIMPLEDATA', 'data', [ { :pos => 0, :name => 'displayName'}, { :pos => 1, :name => 'content', :file => 1}]], :Query => [ 'user', 'QUERY', 'result', [ { :pos => 0, :name => 'index' }, { :pos => 1, :name => 'params' }]], :Dynquery => ['user', 'DYNQUERY', 'result', [ { :pos => 0, :name => 'typeName' }, { :pos => 1, :name => 'filterFn' }, { :pos => 2, :name => 'mapFn' } ]], :DeleteData => [ 'user', 'DELETEDATA', 'data', [ { :pos => 0, :name => 'displayName' } ]], :GetSequenceSize => [ 'user', 'GETSEQUENCESIZE', 'size', [ { :pos => 0, :name => 'typeName' }]], :ExecPartSeq => [ 'user', 'EXECPARTIALSEQUENCE', 'response', [ { :pos => 0, :name => 'typeName' }, { :pos => 1, :name => 'fn' }, { :pos => 2, :name => 'start' }, { :pos => 3, :name => 'size' } ] ] , :RequestSession => [ 'user', 'REQUESTSESSION', 'session', [ { :pos => 0, :name => 'partition' }, { :pos => 1, :name => 'user'}]], :ValidateUser => [ 'user', 'VALIDATEUSER', 'context', [ { :pos => 0, :name => 'partition' }, { :pos => 1, :name => 'user' }, { :pos => 2, :name => 'hashPassword' }, { :pos => 3, :name => 'session' } ]], :SubmitTask => [ 'user', 'SUBMITTASK', 'task', [ { :pos => 0, :name => 'task' } ]], :RunView => [ 'user', 'RUNVIEW', 'response', [ { :pos => 0, :name => 'view' }, { :pos => 1, :name => 'params' } ] ], :GetTypes => [ 'admin', 'GETTYPES', 'types', []], :GetType => [ 'admin', 'GETTYPE', 'type', [ { :pos => 0, :name => 'typeName' } ]], :UpdateType => [ 'admin', 'UPDATETYPE', 'type', [ { :pos => 0, :name => 'type' }]], :GetFn => [ 'user', 'GETFN', 'fnContent', [ { :pos =>0, :name => 'fnName' } ]], :PutFn => [ 'user', 'PUTFN', 'response', [ { :pos => 0, :name => 'fnName' }, { :pos => 1, :name => 'fnContent', :file => 1 }, { :pos => 2, :name => 'fnLanguage'} ]], :ExpireSessions => [ 'admin', 'EXPIRESESSIONS', 'sessions', []], :GetAllTasks => [ 'task', 'GETALLTASKS', 'tasks', []], :GetTask => [ 'task', 'GETTASK', 'task', [ { :pos=> 0, :name => 'taskId' } ]], :PurgeTasks => [ 'task', 'PURGETASKS', 'response', []], :GetFountainState => [ 'admin', 'GETFOUNTAINSTATE', 'state', []], :SetFountainId => [ 'admin', 'SETFOUNTAINID', 'dummy', [ { :pos => 0, :name => 'fountain' }, { :pos => 1, :name=> 'value' }]], :GetFountain => [ 'user', 'AUTOID', 'id', [ { :pos => 0, :name => 'fountain' } ]], :Bootstrap => ['special', 'BOOTSTRAP', 'response', []] }
Instance Method Summary collapse
- #getSenderHash ⇒ Object
-
#initialize ⇒ Hmx
constructor
A new instance of Hmx.
- #login(config) ⇒ Object
- #loginApi(url, urlapi) ⇒ Object
-
#performDistRequest(cmd, args) ⇒ Object
Implementation note - the doXXX commands are defined in the section above and basically call performDistRequest for the symbol :XXX with the arguments provided.
- #performRequest(prefix, function, command) ⇒ Object
- #standardRequest(prefix, commandName, params, returnPart) ⇒ Object
Constructor Details
#initialize ⇒ Hmx
Returns a new instance of Hmx.
90 91 |
# File 'lib/hmx/hmx.rb', line 90 def initialize end |
Instance Method Details
#getSenderHash ⇒ Object
142 143 144 145 146 |
# File 'lib/hmx/hmx.rb', line 142 def getSenderHash() hash = Hash.new hash['context'] = @context if @context return hash end |
#login(config) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/hmx/hmx.rb', line 23 def login(config) puts config if $debug @context = nil; @urlapi = config[:api] if config.has_key?(:context) @context = JSON.parse(config[:context]) #Do a null check begin doInfo([]) rescue => e @context = nil; end end if (@context.nil?) session = doRequestSession([config[:partition], config[:user]]) salty = session['MXSession']['salty'] sendString = config[:password] + ':' + salty digestToSend = Digest::MD5.hexdigest(sendString) @context = doValidateUser([config[:partition], config[:user], digestToSend, session['MXSession']['sessionId']]) config[:context] = JSON.generate(@context) end end |
#loginApi(url, urlapi) ⇒ Object
19 20 21 22 |
# File 'lib/hmx/hmx.rb', line 19 def loginApi(url, urlapi) @urlapi = urlapi @context = JSON.parse (RestClient.get url).to_str end |
#performDistRequest(cmd, args) ⇒ Object
Implementation note - the doXXX commands are defined in the section above and basically call performDistRequest for the symbol :XXX with the arguments provided. So by adding to @@distMap we automatically provide hmx.doXXX support for that call
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/hmx/hmx.rb', line 95 def performDistRequest(cmd, args) spec = @@distMap[cmd] hash = getSenderHash() spec[3].each { | param | # if the args has enough , use that # otherwise, prompt for the parameter if (args.length > param[:pos]) hash[param[:name]] = args[param[:pos]] elsif (param.has_key?(:file) && !HmxClient::Command.fileIn.nil?) # Content comes from file realFile = File.(HmxClient::Command.fileIn) puts "Reading #{ realFile } to get parameter #{ param[:name] }" hash[param[:name]] = File.open(realFile) { | f | c = '' while(line = f.gets) c = c + line end c } else hash[param[:name]] = getFromUser("Please enter the value of #{ param[:name] }") end if (param.has_key?(:json)) hash[param[:name]] = JSON.parse(hash[param[:name]]) end } standardRequest(spec[0], spec[1], hash, spec[2]) end |
#performRequest(prefix, function, command) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/hmx/hmx.rb', line 123 def performRequest(prefix, function, command) puts "Send data #{ JSON.generate(command) }" if HmxClient::Command.debug? puts "URL is #{ @urlapi+'/'+prefix } " if HmxClient::Command.debug? response = RestClient.post @urlapi+'/'+prefix, :function=>function, :params=>JSON.generate(command), :multipart=>true puts "Raw response is #{ response.to_str }" if HmxClient::Command.debug? if (response.length > 0) return JSON.parse(response.to_str) else return "" end end |
#standardRequest(prefix, commandName, params, returnPart) ⇒ Object
134 135 136 137 138 139 140 141 |
# File 'lib/hmx/hmx.rb', line 134 def standardRequest(prefix, commandName, params, returnPart) response = performRequest(prefix, commandName, params) puts "JSON response is #{ response }" if HmxClient::Command.debug? if response['inError'] raise HmxException.new(response['exception']), "Error returned from server" end return response[returnPart] end |