ugc 0.0.5 → 0.0.6
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/Gemfile.lock +1 -1
- data/README.md +12 -3
- data/lib/ugc/commands/delete.rb +1 -1
- data/lib/ugc/commands/get.rb +44 -6
- data/lib/ugc/commands/post.rb +3 -3
- data/lib/ugc/commands/put.rb +3 -3
- data/lib/ugc/helpers/{formatters.rb → format.rb} +7 -2
- data/lib/ugc/helpers/{sql.rb → parse.rb} +14 -0
- data/lib/ugc/version.rb +1 -1
- metadata +6 -7
- data/lib/ugc/commands/list.rb +0 -49
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -49,13 +49,22 @@ Connect to an Apigee administrator account:
|
|
|
49
49
|
|
|
50
50
|
## Release notes
|
|
51
51
|
|
|
52
|
+
### 0.0.6
|
|
53
|
+
* New features
|
|
54
|
+
1. Ruby eval of data in put and post commands
|
|
55
|
+
* eg. may now use "key: 'value'" for json instead of '{"key": "value"}'
|
|
56
|
+
2. Added alias: 'show' for 'get'
|
|
57
|
+
3. Made 'list' an alias of 'get' and updated get to include 'list' functionality
|
|
58
|
+
4. smart column width for entities
|
|
59
|
+
5. Added aliases 'create' and 'update' for 'post' and 'put' (yes, I am aware this isn't technically correct)
|
|
60
|
+
|
|
52
61
|
### 0.0.5
|
|
53
62
|
* New features
|
|
54
|
-
1. smart column widths
|
|
55
|
-
|
|
63
|
+
1. smart column widths for collections
|
|
64
|
+
2. add "limit" keyword to sql syntax
|
|
56
65
|
* Bug fixes
|
|
57
66
|
1. fixed issue with selecting a single column
|
|
58
|
-
|
|
67
|
+
2. fixed formatting of entities with heterogeneous attributes
|
|
59
68
|
|
|
60
69
|
### 0.0.4
|
|
61
70
|
* Bug fixes
|
data/lib/ugc/commands/delete.rb
CHANGED
data/lib/ugc/commands/get.rb
CHANGED
|
@@ -1,12 +1,50 @@
|
|
|
1
|
-
desc '
|
|
2
|
-
arg_name 'url'
|
|
1
|
+
desc 'retrieve a collection or entity'
|
|
3
2
|
|
|
4
|
-
command :get do |c|
|
|
3
|
+
command :get,:show,:ls,:list do |c|
|
|
5
4
|
|
|
6
|
-
c.
|
|
7
|
-
|
|
5
|
+
c.desc 'url'
|
|
6
|
+
c.command [:url] do |c2|
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
c2.action do |global_options,options,args|
|
|
9
|
+
help_now! unless args[0]
|
|
10
|
+
|
|
11
|
+
format_result $application[args[0]].get
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
c.desc 'collections'
|
|
16
|
+
c.command [:collections] do |c2|
|
|
17
|
+
|
|
18
|
+
c2.action do |global_options,options,args|
|
|
19
|
+
app = $application.entity
|
|
20
|
+
collections = app['metadata']['collections']
|
|
21
|
+
table border: true do
|
|
22
|
+
row header: true do
|
|
23
|
+
collections.first[1].each_key do |k|
|
|
24
|
+
column k
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
collections.each_value do |coll|
|
|
28
|
+
row do
|
|
29
|
+
coll.each_value do |v|
|
|
30
|
+
column v
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
10
36
|
end
|
|
11
37
|
|
|
38
|
+
default_names = %w(assets users events roles folders activities devices groups)
|
|
39
|
+
default_names.each do |e|
|
|
40
|
+
c.desc e
|
|
41
|
+
c.command [e.to_sym] do |c2|
|
|
42
|
+
c2.action do |global_options,options,args|
|
|
43
|
+
format_collection($application[e].collection)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
c.default_command :url
|
|
49
|
+
|
|
12
50
|
end
|
data/lib/ugc/commands/post.rb
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
desc '
|
|
1
|
+
desc 'non-idempotent create or update (usually create)'
|
|
2
2
|
arg_name 'url [data]'
|
|
3
3
|
|
|
4
|
-
command :post do |c|
|
|
4
|
+
command :post,:create do |c|
|
|
5
5
|
c.flag [:d,:data]
|
|
6
6
|
|
|
7
7
|
c.action do |global_options,options,args|
|
|
8
8
|
help_now! unless args[0]
|
|
9
9
|
|
|
10
|
-
format_result resource(args[0]).post (options[:data] || args[1])
|
|
10
|
+
format_result resource(args[0]).post parse_data(options[:data] || args[1])
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
end
|
data/lib/ugc/commands/put.rb
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
desc '
|
|
1
|
+
desc 'idempotent create or update (usually an update)'
|
|
2
2
|
arg_name 'url [data]'
|
|
3
3
|
|
|
4
|
-
command :put do |c|
|
|
4
|
+
command :put,:update do |c|
|
|
5
5
|
c.flag [:d,:data]
|
|
6
6
|
|
|
7
7
|
c.action do |global_options,options,args|
|
|
8
8
|
help_now! unless args[0]
|
|
9
9
|
|
|
10
|
-
format_result resource(args[0]).put (options[:data] || args[1])
|
|
10
|
+
format_result resource(args[0]).put parse_data(options[:data] || args[1])
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
end
|
|
@@ -41,10 +41,15 @@ end
|
|
|
41
41
|
|
|
42
42
|
def format_entity(entity)
|
|
43
43
|
if entity
|
|
44
|
+
name_cols = value_cols = 0
|
|
45
|
+
entity.data.reject{|k,v| SKIP_ATTRS.include? k}.each do |k,v|
|
|
46
|
+
name_cols = [name_cols, k.size].max
|
|
47
|
+
value_cols = [value_cols, v.to_s.size].max
|
|
48
|
+
end
|
|
44
49
|
table border: true do
|
|
45
50
|
row header: true do
|
|
46
|
-
column 'name', width: 20
|
|
47
|
-
column 'value', width:
|
|
51
|
+
column 'name', width: [name_cols, 20].min
|
|
52
|
+
column 'value', width: [value_cols, HighLine.new.output_cols - 28].min
|
|
48
53
|
end
|
|
49
54
|
entity.data.reject{|k,v| SKIP_ATTRS.include? k}.each do |k,v|
|
|
50
55
|
row do
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
1
3
|
def parse_sql(query)
|
|
2
4
|
result = {}
|
|
3
5
|
keywords = %w(select from where limit)
|
|
@@ -20,3 +22,15 @@ def parse_sql(query)
|
|
|
20
22
|
end
|
|
21
23
|
result
|
|
22
24
|
end
|
|
25
|
+
|
|
26
|
+
# returns a json string
|
|
27
|
+
def parse_data(input)
|
|
28
|
+
# must be wrapped in {}
|
|
29
|
+
input = "{#{input}}" unless input.start_with? '{'
|
|
30
|
+
# must be a json string or 1.9 hash format
|
|
31
|
+
begin
|
|
32
|
+
MultiJson.dump(eval(input))
|
|
33
|
+
rescue SyntaxError
|
|
34
|
+
input
|
|
35
|
+
end
|
|
36
|
+
end
|
data/lib/ugc/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ugc
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.6
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2013-01-
|
|
12
|
+
date: 2013-01-04 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: rake
|
|
@@ -148,15 +148,14 @@ files:
|
|
|
148
148
|
- lib/ugc/application.rb
|
|
149
149
|
- lib/ugc/commands/delete.rb
|
|
150
150
|
- lib/ugc/commands/get.rb
|
|
151
|
-
- lib/ugc/commands/list.rb
|
|
152
151
|
- lib/ugc/commands/login.rb
|
|
153
152
|
- lib/ugc/commands/post.rb
|
|
154
153
|
- lib/ugc/commands/profile.rb
|
|
155
154
|
- lib/ugc/commands/put.rb
|
|
156
155
|
- lib/ugc/commands/query.rb
|
|
157
156
|
- lib/ugc/commands/target.rb
|
|
158
|
-
- lib/ugc/helpers/
|
|
159
|
-
- lib/ugc/helpers/
|
|
157
|
+
- lib/ugc/helpers/format.rb
|
|
158
|
+
- lib/ugc/helpers/parse.rb
|
|
160
159
|
- lib/ugc/helpers/uri.rb
|
|
161
160
|
- lib/ugc/management.rb
|
|
162
161
|
- lib/ugc/settings.rb
|
|
@@ -185,7 +184,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
185
184
|
version: '0'
|
|
186
185
|
segments:
|
|
187
186
|
- 0
|
|
188
|
-
hash: -
|
|
187
|
+
hash: -2161769601695807419
|
|
189
188
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
190
189
|
none: false
|
|
191
190
|
requirements:
|
|
@@ -194,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
194
193
|
version: '0'
|
|
195
194
|
segments:
|
|
196
195
|
- 0
|
|
197
|
-
hash: -
|
|
196
|
+
hash: -2161769601695807419
|
|
198
197
|
requirements: []
|
|
199
198
|
rubyforge_project:
|
|
200
199
|
rubygems_version: 1.8.24
|
data/lib/ugc/commands/list.rb
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
desc 'list'
|
|
2
|
-
command :ls,:list do |c|
|
|
3
|
-
|
|
4
|
-
c.desc 'collections'
|
|
5
|
-
c.command [:collections] do |c2|
|
|
6
|
-
|
|
7
|
-
c2.action do |global_options,options,args|
|
|
8
|
-
app = $application.entity
|
|
9
|
-
collections = app['metadata']['collections']
|
|
10
|
-
table border: true do
|
|
11
|
-
row header: true do
|
|
12
|
-
collections.first[1].each_key do |k|
|
|
13
|
-
column k
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
collections.each_value do |coll|
|
|
17
|
-
row do
|
|
18
|
-
coll.each_value do |v|
|
|
19
|
-
column v
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
default_names = %w(assets users events roles folders activities devices groups)
|
|
28
|
-
default_names.each do |e|
|
|
29
|
-
c.desc e
|
|
30
|
-
c.command [e.to_sym] do |c2|
|
|
31
|
-
c2.action do |global_options,options,args|
|
|
32
|
-
format_collection($application[e].collection)
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
c.desc 'whatevers'
|
|
38
|
-
c.command [:whatevers] do |c2|
|
|
39
|
-
c2.action do |global_options,options,args|
|
|
40
|
-
help_now! unless args[0]
|
|
41
|
-
|
|
42
|
-
whatevers = $application[args[0]].collection
|
|
43
|
-
format_collection(whatevers)
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
c.default_command :whatevers
|
|
48
|
-
|
|
49
|
-
end
|