hmx_client 0.0.3 → 0.0.4

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.
data/bin/hmx ADDED
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
4
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
5
+
6
+ require 'rubygems'
7
+ require 'optparse'
8
+ require 'hmx_client'
9
+
10
+ include HmxClient
11
+
12
+ $stdout.sync = true
13
+ $debug = false
14
+
15
+ options = {
16
+ :api => 'http://localhost:9999',
17
+ :user => 'amkimian',
18
+ :password => 'password'
19
+ }
20
+
21
+ ARGV.options do |o|
22
+ o.on("-a apiUrl", "--api") { |api| options[:api] = api }
23
+ o.on("-u user", "--user") { |user| options[:user] = user }
24
+ o.on("-d", "--debug") { $debug = true }
25
+ o.parse!
26
+ end
27
+
28
+ begin
29
+ args = ARGV.dup
30
+ ARGV.clear
31
+ h = Client.new(args, options).run!
32
+ puts "Hello mum" if $debug
33
+ rescue Client::CommandInvalid
34
+ abort File.read(__FILE__).split('__END__').last
35
+ end
36
+
37
+ __END__
38
+ Usage: hmx [OPTIONS] command
39
+
40
+ hmx test alan
41
+
data/hmx_client.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
- require "hmx_client/version"
3
+ require "hmx/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "hmx_client"
data/lib/hmx/client.rb ADDED
@@ -0,0 +1,78 @@
1
+ require 'digest/md5'
2
+
3
+ module HmxClient
4
+ class Client
5
+ FILE = File.expand_path("~/.hmxConfig")
6
+
7
+ def initialize(args, options)
8
+ @args = args
9
+ @options = options
10
+ loadConfig!
11
+ end
12
+
13
+ class CommandInvalid < Exception; end
14
+
15
+ def loadConfig!
16
+ # Load the config from the save file
17
+ @config = {}
18
+ @config = Marshal.load(File.read(FILE)) if File.exist?(FILE)
19
+ end
20
+ def storeConfig(keyName, keyValue)
21
+ # Update the config hashMap and persist it
22
+ @config[keyName] = keyValue
23
+ File.open(FILE, 'w+') { |f| f.write(Marshal.dump(@config)) }
24
+ end
25
+ def run!
26
+ command = @args.shift || @options[:command]
27
+ raise CommandInvalid unless command && respond_to?(command)
28
+ send(command)
29
+ end
30
+ def getapi
31
+ hmx = Hmx.new
32
+ hmx.login(@config)
33
+ hmx
34
+ end
35
+ def config
36
+ case prop = @args.shift
37
+ when "user"
38
+ storeConfig(:user, @args.shift)
39
+ when "password"
40
+ storeConfig(:password, Digest::MD5.hexdigest(@args.shift)) # Really ask on the command line later
41
+ when "url"
42
+ storeConfig(:url, @args.shift)
43
+ when "apiUrl"
44
+ storeConifg(:apiKey, @args.shift)
45
+ when "api"
46
+ storeConfig(:api, @args.shift)
47
+ when "partition"
48
+ storeConfig(:partition, @args.shift)
49
+ else
50
+ abort "Unknown config command"
51
+ end
52
+ end
53
+ def get
54
+ h = getapi
55
+ puts h.getData(@args.shift)
56
+ end
57
+ def getData
58
+ h = getapi
59
+ puts h.getContent(@args.shift)
60
+ end
61
+ def putSimpleData
62
+ h = getapi
63
+ puts h.putSimpleData(@args.shift, @args.shift)
64
+ end
65
+ def query
66
+ h = getapi
67
+ puts h.query(@args.shift, nil)
68
+ end
69
+ def test
70
+ case check = @args.shift
71
+ when "alan"
72
+ puts "Test Alan complete"
73
+ else
74
+ abort "Unknown test command"
75
+ end
76
+ end
77
+ end
78
+ end
data/lib/hmx/hmx.rb ADDED
@@ -0,0 +1,97 @@
1
+ require 'rubygems'
2
+ require 'rest_client'
3
+ require 'json'
4
+ require 'digest/md5'
5
+
6
+ class Hmx
7
+ def loginApi(url, urlapi)
8
+ @urlapi = urlapi
9
+ @context = JSON.parse (RestClient.get url).to_str
10
+ end
11
+ def login(config)
12
+ puts config if $debug
13
+ @urlapi = config[:api]
14
+ session = requestSession(config[:partition], config[:user])
15
+ salty = session['MXSession']['salty']
16
+ sendString = config[:password] + ':' + salty
17
+ digestToSend = Digest::MD5.hexdigest(sendString)
18
+ @context = validateUser(config[:partition], config[:user], digestToSend, session['MXSession']['sessionId'])
19
+ end
20
+ def initialize
21
+ @distMap = {
22
+ :getData => [ 'user', 'GETDATA', 'data', [ { :pos => 0, :name => 'displayName' } ]],
23
+ :getContent => [ 'user', 'GETCONTENT', 'content', [ { :pos => 0, :name => 'displayName' }]],
24
+ :putData => ['user', 'PUTDATA', 'data', [ { :pos => 0, :name => 'data' }]],
25
+ :putSimpleData => [ 'user', 'PUTSIMPLEDATA', 'data', [ { :pos => 0, :name => 'displayName'}, { :pos => 1, :name => 'content'}]],
26
+ :query => [ 'user', 'QUERY', 'result', [ { :pos => 0, :name => 'index' }, { :pos => 1, :name => 'params' }]],
27
+ :dynquery => ['user', 'DYNQUERY', 'result', [ { :pos => 0, :name => 'typeName' }, { :pos => 1, :name => 'filterFn' }, { :pos => 2, :name => 'mapFn' } ]],
28
+ :deleteData => [ 'user', 'DELETEDATA', 'data', [ { :pos => 0, :name => 'displayName' } ]],
29
+ :getSequenceSize => [ 'user', 'GETSEQUENCESIZE', 'size', [ { :pos => 0, :name => 'typeName' }]],
30
+ :execPartSeq => [ 'user', 'EXECPARTIALSEQUENCE', 'response', [ { :pos => 0, :name => 'typeName' },
31
+ { :pos => 1, :name => 'fn' },
32
+ { :pos => 2, :name => 'start' },
33
+ { :pos => 3, :name => 'size' } ] ] ,
34
+ :requestSession => [ 'user', 'REQUESTSESSION', 'session', [ { :pos => 0, :name => 'partition' }, { :pos => 1, :name => 'user'}]],
35
+ :validateUser => [ 'user', 'VALIDATEUSER', 'context', [ { :pos => 0, :name => 'partition' },
36
+ { :pos => 1, :name => 'user' },
37
+ { :pos => 2, :name => 'hashPassword' },
38
+ { :pos => 3, :name => 'session' }
39
+ ]]
40
+
41
+ }
42
+ end
43
+ def performDistRequest(cmd, args)
44
+ spec = @distMap[cmd]
45
+ hash = getSenderHash()
46
+ spec[3].each { | param | hash[param[:name]] = args[param[:pos]] }
47
+ standardRequest(spec[0], spec[1], hash, spec[2])
48
+ end
49
+ def performRequest(prefix, function, command)
50
+ puts "Send data #{ JSON.generate(command) }" if $debug
51
+ response = RestClient.post @urlapi+'/'+prefix, :function=>function, :params=>JSON.generate(command), :multipart=>true
52
+ puts "Raw response is #{ response.to_str }" if $debug
53
+ return JSON.parse(response.to_str)
54
+ end
55
+ def standardRequest(prefix, commandName, params, returnPart)
56
+ response = performRequest(prefix, commandName, params)
57
+ return response[returnPart]
58
+ end
59
+ def getSenderHash()
60
+ hash = Hash.new
61
+ hash['context'] = @context if @context
62
+ return hash
63
+ end
64
+ def getData(*args)
65
+ performDistRequest(:getData, args)
66
+ end
67
+ def getContent(*args)
68
+ performDistRequest(:getContent, args)
69
+ end
70
+ def putData(*args)
71
+ performDistRequest(:putData, args)
72
+ end
73
+ def putSimpleData(*args)
74
+ performDistRequest(:putSimpleData, args)
75
+ end
76
+ def query(*args)
77
+ performDistRequest(:query, args)
78
+ end
79
+ def dynquery(*args)
80
+ performDistRequest(:dynquery, args)
81
+ end
82
+ def deleteData(*args)
83
+ performDistRequest(:deleteData, args)
84
+ end
85
+ def getSequenceSize(*args)
86
+ performDistRequest(:getSequenceSize, args)
87
+ end
88
+ def execPartialSequence(*args)
89
+ performDistRequest(:execPartSeq, args)
90
+ end
91
+ def requestSession(*args)
92
+ performDistRequest(:requestSession, args)
93
+ end
94
+ def validateUser(*args)
95
+ performDistRequest(:validateUser, args)
96
+ end
97
+ end
@@ -1,3 +1,3 @@
1
1
  module HmxClient
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/hmx_client.rb CHANGED
@@ -1,5 +1,7 @@
1
- require "hmx_client/version"
2
- require "hmx_client/hmx"
1
+ base_path = File.dirname(__FILE__)
2
+ %w{client hmx}.each do |lib|
3
+ require "#{base_path}/hmx/#{lib}"
4
+ end
3
5
  module HmxClient
4
- # Your code goes here...
5
6
  end
7
+ require "hmx/version"
@@ -0,0 +1,5 @@
1
+ gem install bundler
2
+ bundle install
3
+ rake install
4
+ gem build hmx_client.gemspec
5
+ gem push hmx_client-0.0.2.gem
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hmx_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-23 00:00:00.000000000Z
12
+ date: 2011-10-25 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
16
- requirement: &70213555802660 !ruby/object:Gem::Requirement
16
+ requirement: &70303683777700 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70213555802660
24
+ version_requirements: *70303683777700
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: json
27
- requirement: &70213555802240 !ruby/object:Gem::Requirement
27
+ requirement: &70303683777220 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,21 +32,25 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70213555802240
35
+ version_requirements: *70303683777220
36
36
  description: Gives a client the ability to interact fully with the API for HMX
37
37
  email:
38
38
  - ukmoore@gmail.com
39
- executables: []
39
+ executables:
40
+ - hmx
40
41
  extensions: []
41
42
  extra_rdoc_files: []
42
43
  files:
43
44
  - .gitignore
44
45
  - Gemfile
45
46
  - Rakefile
47
+ - bin/hmx
46
48
  - hmx_client.gemspec
49
+ - lib/hmx/client.rb
50
+ - lib/hmx/hmx.rb
51
+ - lib/hmx/version.rb
47
52
  - lib/hmx_client.rb
48
- - lib/hmx_client/hmx.rb
49
- - lib/hmx_client/version.rb
53
+ - sampleCommands.txt
50
54
  homepage: http://rubygems.org/gems/hmx_client
51
55
  licenses: []
52
56
  post_install_message:
@@ -1,30 +0,0 @@
1
- require 'rubygems'
2
- require 'rest_client'
3
- require 'json'
4
-
5
- class Hmx
6
- def initialize(url, urlapi)
7
- @urlapi = urlapi
8
- response = RestClient.get url
9
- @context = JSON.parse(response.to_str)
10
- end
11
- def get(displayName)
12
- hash = Hash.new
13
- hash['context'] = @context
14
- hash['displayName'] = displayName
15
- response = performRequest('user', 'GETDATA', hash)
16
- return response.to_str
17
- end
18
- def put(displayName, content)
19
- hash = Hash.new
20
- hash['context'] = @context
21
- hash['displayName'] = displayName
22
- hash['content'] = content
23
- response = performRequest('user', 'PUTSIMPLEDATA', hash)
24
- return response.to_str
25
- end
26
- def performRequest(prefix, function, command)
27
- response = RestClient.post @urlapi+'/'+prefix, :function=>function, :params=>JSON.generate(command), :multipart=>true
28
- return response
29
- end
30
- end