hmx_client 0.0.7 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,4 +1,4 @@
1
- *.gem
2
- .bundle
3
- Gemfile.lock
4
- pkg/*
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "http://rubygems.org"
2
-
3
- # Specify your gem's dependencies in hmx_client.gemspec
4
- gemspec
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in hmx_client.gemspec
4
+ gemspec
data/Rakefile CHANGED
@@ -1 +1 @@
1
- require "bundler/gem_tasks"
1
+ require "bundler/gem_tasks"
data/bin/hmx CHANGED
@@ -1,33 +1,33 @@
1
- #!/usr/bin/env ruby
2
- begin
3
- require 'Win32/Console/ANSI' if RUBY_PLATFORM =~ /mingw32/
4
- rescue Exception => e
5
- puts e.message
6
- end
7
-
8
- require 'cli-colorize'
9
-
10
- lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
11
- $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
12
-
13
- require 'rubygems'
14
- require 'optparse'
15
- require 'hmx_client'
16
-
17
- include HmxClient
18
-
19
- $stdout.sync = true
20
- $folder = nil
21
- $file = nil
22
- $outFile = nil
23
- $debug = false
24
-
25
- begin
26
- args = ARGV.dup
27
- ARGV.clear
28
- command = args.shift.strip rescue 'help'
29
- HmxClient::Command.load
30
- HmxClient::Command.run(command, args)
31
- rescue HmxException => info
32
- abort "General HMX Exception - #{info.msg['message']}"
33
- end
1
+ #!/usr/bin/env ruby
2
+ begin
3
+ require 'Win32/Console/ANSI' if RUBY_PLATFORM =~ /mingw32/
4
+ rescue Exception => e
5
+ puts e.message
6
+ end
7
+
8
+ require 'cli-colorize'
9
+
10
+ lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
11
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
12
+
13
+ require 'rubygems'
14
+ require 'optparse'
15
+ require 'hmx_client'
16
+
17
+ include HmxClient
18
+
19
+ $stdout.sync = true
20
+ $folder = nil
21
+ $file = nil
22
+ $outFile = nil
23
+ $debug = false
24
+
25
+ begin
26
+ args = ARGV.dup
27
+ ARGV.clear
28
+ command = args.shift.strip rescue 'help'
29
+ HmxClient::Command.load
30
+ HmxClient::Command.run(command, args)
31
+ rescue HmxException => info
32
+ abort "General HMX Exception - #{info.msg['message']}"
33
+ end
@@ -1,27 +1,27 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "hmx/version"
4
-
5
- Gem::Specification.new do |s|
6
- s.name = "hmx_client"
7
- s.version = HmxClient::VERSION
8
- s.authors = ["Alan Moore"]
9
- s.email = ["ukmoore@gmail.com"]
10
- s.homepage = "http://rubygems.org/gems/hmx_client"
11
- s.summary = %q{HMX Client is used to interact with the Jagwire HMX environment, usually hosted as an addon to Heroku}
12
- s.description = %q{Gives a client the ability to interact fully with the API for HMX}
13
-
14
- s.rubyforge_project = "hmx_client"
15
-
16
- s.files = `git ls-files`.split("\n")
17
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
- s.require_paths = ["lib"]
20
-
21
- # specify any dependencies here; for example:
22
- # s.add_development_dependency "rspec"
23
- s.add_runtime_dependency "rest-client"
24
- s.add_runtime_dependency "json"
25
- s.add_runtime_dependency "cli-colorize"
26
- s.add_runtime_dependency "term-ansicolor"
27
- end
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "hmx/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "hmx_client"
7
+ s.version = HmxClient::VERSION
8
+ s.authors = ["Alan Moore"]
9
+ s.email = ["ukmoore@gmail.com"]
10
+ s.homepage = "http://rubygems.org/gems/hmx_client"
11
+ s.summary = %q{HMX Client is used to interact with the Jagwire HMX environment, usually hosted as an addon to Heroku}
12
+ s.description = %q{Gives a client the ability to interact fully with the API for HMX}
13
+
14
+ s.rubyforge_project = "hmx_client"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ s.add_runtime_dependency "rest-client"
24
+ s.add_runtime_dependency "json"
25
+ s.add_runtime_dependency "cli-colorize"
26
+ s.add_runtime_dependency "term-ansicolor"
27
+ end
@@ -1,167 +1,167 @@
1
- require 'digest/md5'
2
-
3
- module HmxClient
4
- class Client
5
- FILE = File.expand_path("~/.hmxConfig")
6
-
7
- def initialize(args)
8
- @args = args
9
- loadConfig!
10
- end
11
-
12
- class CommandInvalid < Exception; end
13
-
14
- def loadConfig!
15
- # Load the config from the save file
16
- @config = if File.exist?(FILE)
17
- File.open(FILE) { |file| Marshal.load(file) }
18
- else
19
- {}
20
- end
21
- RestClient.proxy = @config[:proxy] if @config.has_key?(:proxy)
22
- end
23
- def storeConfig(keyName, keyValue)
24
- # Update the config hashMap and persist it
25
- @config[keyName] = keyValue
26
- File.open(FILE, 'w+') { |f| Marshal.dump(@config, f) }
27
- end
28
- def run!
29
- command = @args.shift || @options[:command]
30
- raise CommandInvalid unless command && respond_to?(command)
31
- send(command)
32
- end
33
- def getapi
34
- hmx = Hmx.new
35
- hmx.login(@config)
36
- hmx
37
- end
38
- def config
39
- case prop = @args.shift
40
- when "user"
41
- storeConfig(:user, @args.shift)
42
- when "password"
43
- storeConfig(:password, Digest::MD5.hexdigest(@args.shift)) # Really ask on the command line later
44
- when "url"
45
- storeConfig(:url, @args.shift)
46
- when "apiUrl"
47
- storeConifg(:apiKey, @args.shift)
48
- when "api"
49
- storeConfig(:api, @args.shift)
50
- when "partition"
51
- storeConfig(:partition, @args.shift)
52
- when "proxy"
53
- proxy = @args.shift
54
- storeConfig(:proxy, proxy)
55
- RestClient.proxy = proxy
56
- else
57
- abort "Unknown config command"
58
- end
59
- end
60
- def genout(content)
61
- puts content
62
- File.open($outFile, 'w') { | f | puts "And writing to #{$outFile} "
63
- f.write(content) } unless $outFile.nil?
64
- end
65
- def get
66
- h = getapi
67
- genout JSON.pretty_generate(h.getData(@args))
68
- end
69
- def getData
70
- h = getapi
71
- genout h.getContent(@args)
72
- end
73
- def putSimpleData
74
- h = getapi
75
- genout JSON.pretty_generate(h.putSimpleData(@args))
76
- end
77
- def put
78
- h = getapi
79
- genout JSON.pretty_generate(h.putData(@args))
80
- end
81
- def query
82
- h = getapi
83
- genout h.query(@args.shift, nil)
84
- end
85
- def view
86
- h = getapi
87
- viewData = h.runView(@args.shift, JSON.parse(@args.shift))
88
- resp = ''
89
- viewData.each { | line |
90
- line.each { | cell | resp = resp + "%20.20s\t" % cell }
91
- resp = resp + "\n"
92
- }
93
- genout resp
94
- end
95
- # Take all of the documents for a type and put it into the folder passed, one per file
96
- def dumpType
97
- h = getapi
98
- displayNames = h.query(@args.shift, nil)
99
- puts displayNames
100
- displayNames.each { | displayName |
101
- fileName = $folder + "/" + displayName
102
- puts "FileName will be #{ fileName } "
103
- Dir.mkdir(File.dirname(fileName)) if !Dir.exist?(File.dirname(fileName))
104
- puts "DisplayName is #{ displayName } "
105
- File.open(fileName, 'w') { |f| f.write(h.getData([displayName])) } }
106
- end
107
- # Take all of the documents in a folder for a type (the opposite of dumpType above)
108
- # and simply put them back in
109
- def loadType
110
- h = getapi
111
- typeName = @args.shift
112
- folderName = $folder + "/" + typeName
113
- Dir.foreach(folderName) { | f |
114
- puts "Working with #{ f }"
115
- fullFile = folderName + "/" + f
116
- if (File.file?(fullFile))
117
- content = File.open(fullFile) { | h |
118
- c = '';
119
- while(line = h.gets)
120
- c = c + line
121
- end
122
- c
123
- }
124
- puts "Content is #{ content } "
125
- h.putData(JSON.parse(content))
126
- end
127
- }
128
- end
129
- def deleteData
130
- h = getapi
131
- h.deleteData(@args.shift)
132
- end
133
- def getTypes
134
- h = getapi
135
- genout JSON.pretty_generate(h.getTypes)
136
- end
137
- def getType
138
- h = getapi
139
- genout JSON.pretty_generate(h.getType(@args.shift))
140
- end
141
- def getFn
142
- h = getapi
143
- genout h.getFn(@args)
144
- end
145
- def putFn
146
- h = getapi
147
- genout h.putFn(@args)
148
- end
149
- # Add a user, given a name (more can be added through a low level api)
150
- def user
151
- h = getapi
152
- case command = @args.shift
153
- when "add"
154
- username = @args.shift
155
- password = Digest::MD5::hexdigest(@args.shift)
156
-
157
- user = { "MXUser" => { "hashPassword" => password , "apiKey" => false, "userName" => username, "fullName" => username }}
158
- genout JSON.pretty_generate(h.putSimpleData([ "sys.user/#{ username}", JSON.generate(user)]))
159
- when "delete"
160
- username = @args.shift
161
- h.deleteData("sys.user/#{username}")
162
- when "list"
163
- puts h.query("sys.user", nil)
164
- end
165
- end
166
- end
167
- end
1
+ require 'digest/md5'
2
+
3
+ module HmxClient
4
+ class Client
5
+ FILE = File.expand_path("~/.hmxConfig")
6
+
7
+ def initialize(args)
8
+ @args = args
9
+ loadConfig!
10
+ end
11
+
12
+ class CommandInvalid < Exception; end
13
+
14
+ def loadConfig!
15
+ # Load the config from the save file
16
+ @config = if File.exist?(FILE)
17
+ File.open(FILE) { |file| Marshal.load(file) }
18
+ else
19
+ {}
20
+ end
21
+ RestClient.proxy = @config[:proxy] if @config.has_key?(:proxy)
22
+ end
23
+ def storeConfig(keyName, keyValue)
24
+ # Update the config hashMap and persist it
25
+ @config[keyName] = keyValue
26
+ File.open(FILE, 'w+') { |f| Marshal.dump(@config, f) }
27
+ end
28
+ def run!
29
+ command = @args.shift || @options[:command]
30
+ raise CommandInvalid unless command && respond_to?(command)
31
+ send(command)
32
+ end
33
+ def getapi
34
+ hmx = Hmx.new
35
+ hmx.login(@config)
36
+ hmx
37
+ end
38
+ def config
39
+ case prop = @args.shift
40
+ when "user"
41
+ storeConfig(:user, @args.shift)
42
+ when "password"
43
+ storeConfig(:password, Digest::MD5.hexdigest(@args.shift)) # Really ask on the command line later
44
+ when "url"
45
+ storeConfig(:url, @args.shift)
46
+ when "apiUrl"
47
+ storeConifg(:apiKey, @args.shift)
48
+ when "api"
49
+ storeConfig(:api, @args.shift)
50
+ when "partition"
51
+ storeConfig(:partition, @args.shift)
52
+ when "proxy"
53
+ proxy = @args.shift
54
+ storeConfig(:proxy, proxy)
55
+ RestClient.proxy = proxy
56
+ else
57
+ abort "Unknown config command"
58
+ end
59
+ end
60
+ def genout(content)
61
+ puts content
62
+ File.open($outFile, 'w') { | f | puts "And writing to #{$outFile} "
63
+ f.write(content) } unless $outFile.nil?
64
+ end
65
+ def get
66
+ h = getapi
67
+ genout JSON.pretty_generate(h.getData(@args))
68
+ end
69
+ def getData
70
+ h = getapi
71
+ genout h.getContent(@args)
72
+ end
73
+ def putSimpleData
74
+ h = getapi
75
+ genout JSON.pretty_generate(h.putSimpleData(@args))
76
+ end
77
+ def put
78
+ h = getapi
79
+ genout JSON.pretty_generate(h.putData(@args))
80
+ end
81
+ def query
82
+ h = getapi
83
+ genout h.query(@args.shift, nil)
84
+ end
85
+ def view
86
+ h = getapi
87
+ viewData = h.runView(@args.shift, JSON.parse(@args.shift))
88
+ resp = ''
89
+ viewData.each { | line |
90
+ line.each { | cell | resp = resp + "%20.20s\t" % cell }
91
+ resp = resp + "\n"
92
+ }
93
+ genout resp
94
+ end
95
+ # Take all of the documents for a type and put it into the folder passed, one per file
96
+ def dumpType
97
+ h = getapi
98
+ displayNames = h.query(@args.shift, nil)
99
+ puts displayNames
100
+ displayNames.each { | displayName |
101
+ fileName = $folder + "/" + displayName
102
+ puts "FileName will be #{ fileName } "
103
+ Dir.mkdir(File.dirname(fileName)) if !Dir.exist?(File.dirname(fileName))
104
+ puts "DisplayName is #{ displayName } "
105
+ File.open(fileName, 'w') { |f| f.write(h.getData([displayName])) } }
106
+ end
107
+ # Take all of the documents in a folder for a type (the opposite of dumpType above)
108
+ # and simply put them back in
109
+ def loadType
110
+ h = getapi
111
+ typeName = @args.shift
112
+ folderName = $folder + "/" + typeName
113
+ Dir.foreach(folderName) { | f |
114
+ puts "Working with #{ f }"
115
+ fullFile = folderName + "/" + f
116
+ if (File.file?(fullFile))
117
+ content = File.open(fullFile) { | h |
118
+ c = '';
119
+ while(line = h.gets)
120
+ c = c + line
121
+ end
122
+ c
123
+ }
124
+ puts "Content is #{ content } "
125
+ h.putData(JSON.parse(content))
126
+ end
127
+ }
128
+ end
129
+ def deleteData
130
+ h = getapi
131
+ h.deleteData(@args.shift)
132
+ end
133
+ def getTypes
134
+ h = getapi
135
+ genout JSON.pretty_generate(h.getTypes)
136
+ end
137
+ def getType
138
+ h = getapi
139
+ genout JSON.pretty_generate(h.getType(@args.shift))
140
+ end
141
+ def getFn
142
+ h = getapi
143
+ genout h.getFn(@args)
144
+ end
145
+ def putFn
146
+ h = getapi
147
+ genout h.putFn(@args)
148
+ end
149
+ # Add a user, given a name (more can be added through a low level api)
150
+ def user
151
+ h = getapi
152
+ case command = @args.shift
153
+ when "add"
154
+ username = @args.shift
155
+ password = Digest::MD5::hexdigest(@args.shift)
156
+
157
+ user = { "MXUser" => { "hashPassword" => password , "apiKey" => false, "userName" => username, "fullName" => username }}
158
+ genout JSON.pretty_generate(h.putSimpleData([ "sys.user/#{ username}", JSON.generate(user)]))
159
+ when "delete"
160
+ username = @args.shift
161
+ h.deleteData("sys.user/#{username}")
162
+ when "list"
163
+ puts h.query("sys.user", nil)
164
+ end
165
+ end
166
+ end
167
+ end