ugc 0.0.1 → 0.0.2
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/.gitignore +18 -0
- data/.rvmrc +2 -0
- data/Gemfile +2 -0
- data/README.md +31 -0
- data/Rakefile +46 -0
- data/examples.jpeg +0 -0
- data/features/step_definitions/ugc_steps.rb +6 -0
- data/features/support/env.rb +15 -0
- data/features/ugc.feature +8 -0
- data/lib/ugc/application.rb +25 -0
- data/lib/ugc/commands/delete.rb +10 -0
- data/lib/ugc/commands/get.rb +10 -0
- data/lib/ugc/commands/list.rb +47 -0
- data/lib/ugc/commands/login.rb +28 -0
- data/lib/ugc/commands/post.rb +11 -0
- data/lib/ugc/commands/profile.rb +32 -0
- data/lib/ugc/commands/put.rb +11 -0
- data/lib/ugc/commands/query.rb +54 -0
- data/lib/ugc/commands/target.rb +47 -0
- data/lib/ugc/helpers/formatters.rb +91 -0
- data/lib/ugc/helpers/uri.rb +7 -0
- data/lib/ugc/management.rb +20 -0
- data/lib/ugc/settings.rb +110 -0
- data/lib/ugc/version.rb +1 -1
- data/test/default_test.rb +14 -0
- data/test/test_helper.rb +9 -0
- data/ugc.gemspec +25 -0
- metadata +32 -6
data/.gitignore
ADDED
data/.rvmrc
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Usergrid Command Line (ugc)
|
|
2
|
+
|
|
3
|
+
ugc enables convenient terminal access to Apigee's App Services (aka Usergrid).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
$ gem install ugc
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
### Help
|
|
12
|
+
|
|
13
|
+
$ ugc help
|
|
14
|
+
|
|
15
|
+
### Setup
|
|
16
|
+
|
|
17
|
+
Connect to an Apigee administrator account:
|
|
18
|
+
|
|
19
|
+
$ ugc profile apigee
|
|
20
|
+
$ ugc target organization scottganyo
|
|
21
|
+
organization = scottganyo
|
|
22
|
+
$ ugc target app messagee
|
|
23
|
+
application = messagee
|
|
24
|
+
$ ugc login -a scott@ganyo.com
|
|
25
|
+
password: **********
|
|
26
|
+
logged in user: scott@ganyo.com
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### Examples
|
|
30
|
+
|
|
31
|
+

|
data/Rakefile
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
|
2
|
+
|
|
3
|
+
require 'rake/clean'
|
|
4
|
+
require 'rubygems'
|
|
5
|
+
require 'rubygems/package_task'
|
|
6
|
+
require 'rdoc/task'
|
|
7
|
+
require 'cucumber'
|
|
8
|
+
require 'cucumber/rake/task'
|
|
9
|
+
Rake::RDocTask.new do |rd|
|
|
10
|
+
rd.main = "README.rdoc"
|
|
11
|
+
rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
|
|
12
|
+
rd.title = 'Your application title'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
spec = eval(File.read('ugc.gemspec'))
|
|
16
|
+
|
|
17
|
+
Gem::PackageTask.new(spec) do |pkg|
|
|
18
|
+
end
|
|
19
|
+
CUKE_RESULTS = 'results.html'
|
|
20
|
+
CLEAN << CUKE_RESULTS
|
|
21
|
+
desc 'Run features'
|
|
22
|
+
Cucumber::Rake::Task.new(:features) do |t|
|
|
23
|
+
opts = "features --format html -o #{CUKE_RESULTS} --format progress -x"
|
|
24
|
+
opts += " --tags #{ENV['TAGS']}" if ENV['TAGS']
|
|
25
|
+
t.cucumber_opts = opts
|
|
26
|
+
t.fork = false
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
desc 'Run features tagged as work-in-progress (@wip)'
|
|
30
|
+
Cucumber::Rake::Task.new('features:wip') do |t|
|
|
31
|
+
tag_opts = ' --tags ~@pending'
|
|
32
|
+
tag_opts = ' --tags @wip'
|
|
33
|
+
t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty -x -s#{tag_opts}"
|
|
34
|
+
t.fork = false
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
task :cucumber => :features
|
|
38
|
+
task 'cucumber:wip' => 'features:wip'
|
|
39
|
+
task :wip => 'features:wip'
|
|
40
|
+
require 'rake/testtask'
|
|
41
|
+
Rake::TestTask.new do |t|
|
|
42
|
+
t.libs << "test"
|
|
43
|
+
t.test_files = FileList['test/*_test.rb']
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
task :default => [:test,:features]
|
data/examples.jpeg
ADDED
|
Binary file
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'aruba/cucumber'
|
|
2
|
+
|
|
3
|
+
ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
|
|
4
|
+
LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)),'..','..','lib')
|
|
5
|
+
|
|
6
|
+
Before do
|
|
7
|
+
# Using "announce" causes massive warnings on 1.9.2
|
|
8
|
+
@puts = true
|
|
9
|
+
@original_rubylib = ENV['RUBYLIB']
|
|
10
|
+
ENV['RUBYLIB'] = LIB_DIR + File::PATH_SEPARATOR + ENV['RUBYLIB'].to_s
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
After do
|
|
14
|
+
ENV['RUBYLIB'] = @original_rubylib
|
|
15
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module Ugc
|
|
2
|
+
class Application < Usergrid::Application
|
|
3
|
+
|
|
4
|
+
def initialize
|
|
5
|
+
super application_url
|
|
6
|
+
self.auth_token = $settings.access_token
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def application_url
|
|
10
|
+
url = $settings.base_url
|
|
11
|
+
org = $settings.organization
|
|
12
|
+
app = $settings.application
|
|
13
|
+
|
|
14
|
+
raise "not configured" unless url && org && app
|
|
15
|
+
|
|
16
|
+
concat_urls url, "#{org}/#{app}"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def login(username, password)
|
|
20
|
+
super username, password
|
|
21
|
+
$settings.access_token = auth_token
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
whatevers = $application[args[0]].collection
|
|
41
|
+
format_collection(whatevers)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
c.default_command :whatevers
|
|
46
|
+
|
|
47
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require 'io/console'
|
|
2
|
+
|
|
3
|
+
desc 'Describe login here'
|
|
4
|
+
arg_name 'username'
|
|
5
|
+
|
|
6
|
+
command :login do |c|
|
|
7
|
+
|
|
8
|
+
c.switch [:a,:admin]
|
|
9
|
+
c.action do |global_options,options,args|
|
|
10
|
+
|
|
11
|
+
if args[0]
|
|
12
|
+
password = ask('password: ') { |q| q.echo = '*' }
|
|
13
|
+
|
|
14
|
+
if password
|
|
15
|
+
if options[:admin]
|
|
16
|
+
management = Ugc::Management.new
|
|
17
|
+
management.login args[0], password
|
|
18
|
+
else
|
|
19
|
+
application = Ugc::Application.new
|
|
20
|
+
application.login args[0], password
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
puts "logged in user: #{args[0]}"
|
|
24
|
+
else
|
|
25
|
+
raise 'username required'
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
desc 'set the current profile'
|
|
2
|
+
arg_name 'profile name'
|
|
3
|
+
|
|
4
|
+
command :profile,:profiles do |c|
|
|
5
|
+
c.switch :d,:delete
|
|
6
|
+
c.action do |global_options,options,args|
|
|
7
|
+
if args[0]
|
|
8
|
+
if options[:delete]
|
|
9
|
+
$settings.delete_profile args[0]
|
|
10
|
+
puts "Deleted profile: " + args[0]
|
|
11
|
+
else
|
|
12
|
+
$settings.active_profile_name = args[0]
|
|
13
|
+
puts 'Set active profile:'
|
|
14
|
+
show_profile(args[0])
|
|
15
|
+
end
|
|
16
|
+
else
|
|
17
|
+
puts "Saved profiles:"
|
|
18
|
+
$settings.profiles.each_key do |name|
|
|
19
|
+
show_profile(name)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def show_profile(name)
|
|
26
|
+
profile = $settings.profile(name)
|
|
27
|
+
print $settings.active_profile_name == name ? ' *' : ' '
|
|
28
|
+
puts name
|
|
29
|
+
$settings.profile(name).each_pair do |k,v|
|
|
30
|
+
puts " #{k}: #{v}"
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
desc 'query'
|
|
2
|
+
long_desc 'note: query may contain a "from" clause instead of specifying collection_name'
|
|
3
|
+
arg_name '[collection_name] query'
|
|
4
|
+
|
|
5
|
+
command :query do |c|
|
|
6
|
+
c.action do |global_options,options,args|
|
|
7
|
+
|
|
8
|
+
case args.size
|
|
9
|
+
when 2
|
|
10
|
+
type = args[0]
|
|
11
|
+
query = args[1]
|
|
12
|
+
when 1
|
|
13
|
+
query = args[0]
|
|
14
|
+
else
|
|
15
|
+
help_now!
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
parsed_query = parse_sql query
|
|
19
|
+
|
|
20
|
+
if type == nil && parsed_query['from']
|
|
21
|
+
type = parsed_query['from']
|
|
22
|
+
query.gsub! /from\s+#{type}/i, ''
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
result = $application[type].query query
|
|
26
|
+
|
|
27
|
+
collection = result.collection
|
|
28
|
+
format_collection collection, parsed_query['select']
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def parse_sql(query)
|
|
34
|
+
result = {}
|
|
35
|
+
keywords = %w(select from where)
|
|
36
|
+
current = nil
|
|
37
|
+
query.downcase.split(/[\s,*]/).each do |ea|
|
|
38
|
+
next if ea == ''
|
|
39
|
+
if keywords.include? ea
|
|
40
|
+
current = ea
|
|
41
|
+
elsif current
|
|
42
|
+
if result[current]
|
|
43
|
+
if result[current].is_a? Array
|
|
44
|
+
result[current] << ea
|
|
45
|
+
else
|
|
46
|
+
result[current] = [result[current]] << ea
|
|
47
|
+
end
|
|
48
|
+
else
|
|
49
|
+
result[current] = ea
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
result
|
|
54
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
desc 'set the base url, org, and app'
|
|
2
|
+
|
|
3
|
+
command :target do |c|
|
|
4
|
+
|
|
5
|
+
c.desc 'set base url'
|
|
6
|
+
c.command [:base,:base_url] do |ep|
|
|
7
|
+
ep.action do |global_options,options,args|
|
|
8
|
+
$settings.base_url = args[0]
|
|
9
|
+
puts "base_url = #{$settings.base_url}"
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
c.desc 'set organization'
|
|
14
|
+
c.command [:org,:organization] do |ep|
|
|
15
|
+
ep.action do |global_options,options,args|
|
|
16
|
+
$settings.organization = args[0]
|
|
17
|
+
puts "organization = #{$settings.organization}"
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
c.desc 'set application'
|
|
22
|
+
c.command [:app,:application] do |ep|
|
|
23
|
+
ep.action do |global_options,options,args|
|
|
24
|
+
$settings.application = args[0]
|
|
25
|
+
puts "application = #{$settings.application}"
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
c.desc 'set full url - parses base, org, and app'
|
|
30
|
+
c.command [:url] do |url|
|
|
31
|
+
url.action do |global_options,options,args|
|
|
32
|
+
if args[0]
|
|
33
|
+
app_name = args[0].split('/')[-1]
|
|
34
|
+
org_name = args[0].split('/')[-2]
|
|
35
|
+
base_url = args[0][0..url.index(org_name)-2]
|
|
36
|
+
$settings.base_url = base_url
|
|
37
|
+
$settings.organization = org_name
|
|
38
|
+
$settings.application = app_name
|
|
39
|
+
end
|
|
40
|
+
puts "base_url = #{$settings.base_url}"
|
|
41
|
+
puts "organization = #{$settings.organization}"
|
|
42
|
+
puts "application = #{$settings.application}"
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
c.default_command :url
|
|
47
|
+
end
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
SKIP_ATTRS = %w(metadata uri type)
|
|
2
|
+
|
|
3
|
+
def format_result(result)
|
|
4
|
+
if result.multiple_entities? && result.collection.size > 1
|
|
5
|
+
format_collection(result.collection)
|
|
6
|
+
else
|
|
7
|
+
format_entity(result.entity)
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
INDEX_COL_WIDTH = 2
|
|
12
|
+
COL_OVERHEAD = 3
|
|
13
|
+
|
|
14
|
+
def format_collection(collection, headers=nil)
|
|
15
|
+
if collection && collection.size > 0
|
|
16
|
+
table border: true do
|
|
17
|
+
row header: true do
|
|
18
|
+
headers ||= collection.first.keys.reject{|e| SKIP_ATTRS.include? e}
|
|
19
|
+
column '#', width: INDEX_COL_WIDTH
|
|
20
|
+
headers.each do |r|
|
|
21
|
+
column r, width: equal_column_size(headers.size)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
collection.each_with_index do |entity, index|
|
|
25
|
+
row do
|
|
26
|
+
column index
|
|
27
|
+
if entity.is_a? Array
|
|
28
|
+
entity.each do |v|
|
|
29
|
+
column v
|
|
30
|
+
end
|
|
31
|
+
else
|
|
32
|
+
entity.reject{|k,v| SKIP_ATTRS.include? k}.each_value do |v|
|
|
33
|
+
column v
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
else
|
|
40
|
+
puts "0 results"
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def format_entity(entity)
|
|
45
|
+
if entity
|
|
46
|
+
table border: true do
|
|
47
|
+
row header: true do
|
|
48
|
+
column 'name', width: 20
|
|
49
|
+
column 'value', width: (terminal_columns - 28)
|
|
50
|
+
end
|
|
51
|
+
entity.data.reject{|k,v| SKIP_ATTRS.include? k}.each do |k,v|
|
|
52
|
+
row do
|
|
53
|
+
column(k)
|
|
54
|
+
column(v)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
else
|
|
59
|
+
puts "no data"
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def equal_column_size(num_cols)
|
|
64
|
+
((terminal_columns - COL_OVERHEAD - (INDEX_COL_WIDTH + COL_OVERHEAD)) / num_cols).to_i - COL_OVERHEAD
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def terminal_columns
|
|
68
|
+
size = detect_terminal_size
|
|
69
|
+
size ? size[0] : 80
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Returns [width, height] of terminal when detected, nil if not detected.
|
|
73
|
+
# Think of this as a simpler version of Highline's Highline::SystemExtensions.terminal_size()
|
|
74
|
+
def detect_terminal_size
|
|
75
|
+
if (ENV['COLUMNS'] =~ /^\d+$/) && (ENV['LINES'] =~ /^\d+$/)
|
|
76
|
+
[ENV['COLUMNS'].to_i, ENV['LINES'].to_i]
|
|
77
|
+
elsif (RUBY_PLATFORM =~ /java/ || (!STDIN.tty? && ENV['TERM'])) && command_exists?('tput')
|
|
78
|
+
[`tput cols`.to_i, `tput lines`.to_i]
|
|
79
|
+
elsif STDIN.tty? && command_exists?('stty')
|
|
80
|
+
`stty size`.scan(/\d+/).map { |s| s.to_i }.reverse
|
|
81
|
+
else
|
|
82
|
+
nil
|
|
83
|
+
end
|
|
84
|
+
rescue
|
|
85
|
+
nil
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Determines if a shell command exists by searching for it in ENV['PATH'].
|
|
89
|
+
def command_exists?(command)
|
|
90
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).any? {|d| File.exists? File.join(d, command) }
|
|
91
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module Ugc
|
|
2
|
+
class Management < Usergrid::Management
|
|
3
|
+
|
|
4
|
+
def initialize
|
|
5
|
+
super management_url
|
|
6
|
+
auth_token = $settings.access_token
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def management_url
|
|
10
|
+
raise "not configured" unless $settings.base_url
|
|
11
|
+
$settings.base_url
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def login(username, password)
|
|
15
|
+
super username, password
|
|
16
|
+
$settings.access_token = auth_token
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
end
|
data/lib/ugc/settings.rb
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
module Ugc
|
|
2
|
+
class Settings
|
|
3
|
+
|
|
4
|
+
SETTINGS_FILE = 'settings.yml'
|
|
5
|
+
|
|
6
|
+
def initialize(directory)
|
|
7
|
+
@file = File.join directory, SETTINGS_FILE
|
|
8
|
+
@settings = YAML.load_file(@file) rescue default_settings
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def active_profile_name
|
|
12
|
+
@settings['active_profile'] || 'local'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def active_profile_name=(name)
|
|
16
|
+
raise "unknown profile: #{name}" unless profile(name)
|
|
17
|
+
@settings['active_profile'] = name
|
|
18
|
+
save
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def delete_profile(name)
|
|
22
|
+
raise "cannot delete active profile" if active_profile_name == name
|
|
23
|
+
raise "unknown profile: #{name}" unless profiles[name]
|
|
24
|
+
profiles.delete name
|
|
25
|
+
save
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def profile(name=nil)
|
|
29
|
+
name ||= active_profile_name
|
|
30
|
+
profiles[name] || profiles[name] = {}
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def profiles
|
|
34
|
+
@settings['profiles'] || @settings['profiles'] = {}
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def base_url
|
|
38
|
+
profile['base_url']
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def base_url=(url)
|
|
42
|
+
URI.parse url
|
|
43
|
+
set_profile 'base_url', url
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def organization
|
|
47
|
+
profile['organization']
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def organization=(org)
|
|
51
|
+
set_profile 'organization', org
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def application
|
|
55
|
+
profile['application']
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def application=(app)
|
|
59
|
+
set_profile 'application', app
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def access_token
|
|
63
|
+
profile['access_token']
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def access_token=(token)
|
|
67
|
+
set_profile 'access_token', token
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def configured?
|
|
71
|
+
base_url && organization && application
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def logged_in?
|
|
75
|
+
!!access_token
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
private
|
|
79
|
+
|
|
80
|
+
def set_profile(prop, value)
|
|
81
|
+
profile[prop] = value
|
|
82
|
+
save
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def save
|
|
86
|
+
Dir.mkdir(File.dirname(@file)) unless Dir.exist?(File.dirname(@file))
|
|
87
|
+
File.open(@file, 'w') do |out|
|
|
88
|
+
YAML.dump(@settings, out)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def default_settings
|
|
93
|
+
{
|
|
94
|
+
'target' => 'https://api.usergrid.com',
|
|
95
|
+
'active_profile' => 'local',
|
|
96
|
+
'profiles' => {
|
|
97
|
+
'local' => {
|
|
98
|
+
'base_url' => 'http://localhost:8080',
|
|
99
|
+
'organization' => 'test-organization',
|
|
100
|
+
'application' => 'test-app'
|
|
101
|
+
},
|
|
102
|
+
'apigee' => {
|
|
103
|
+
'base_url' => 'https://api.usergrid.com'
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
end
|
|
110
|
+
end
|
data/lib/ugc/version.rb
CHANGED
data/test/test_helper.rb
ADDED
data/ugc.gemspec
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Ensure we require the local version and not one we might have installed already
|
|
2
|
+
require File.join([File.dirname(__FILE__),'lib','ugc','version.rb'])
|
|
3
|
+
spec = Gem::Specification.new do |s|
|
|
4
|
+
s.name = 'ugc'
|
|
5
|
+
s.version = Ugc::VERSION
|
|
6
|
+
s.author = 'Scott Ganyo'
|
|
7
|
+
s.email = 'scott@ganyo.com'
|
|
8
|
+
s.homepage = 'http://ganyo.com'
|
|
9
|
+
s.platform = Gem::Platform::RUBY
|
|
10
|
+
s.summary = 'Usergrid Command Line'
|
|
11
|
+
s.files = `git ls-files`.split($\)
|
|
12
|
+
s.require_paths << 'lib'
|
|
13
|
+
s.has_rdoc = true
|
|
14
|
+
s.extra_rdoc_files = ['README.rdoc','ugc.rdoc']
|
|
15
|
+
s.rdoc_options << '--title' << 'ugc' << '--main' << 'README.rdoc' << '-ri'
|
|
16
|
+
s.bindir = 'bin'
|
|
17
|
+
s.executables << 'ugc'
|
|
18
|
+
s.add_development_dependency('rake')
|
|
19
|
+
s.add_development_dependency('rdoc')
|
|
20
|
+
s.add_development_dependency('aruba')
|
|
21
|
+
s.add_runtime_dependency('gli','2.5.0')
|
|
22
|
+
s.add_runtime_dependency('usergrid_iron')
|
|
23
|
+
s.add_runtime_dependency('highline')
|
|
24
|
+
s.add_runtime_dependency('command_line_reporter')
|
|
25
|
+
end
|
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.2
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -132,10 +132,36 @@ extra_rdoc_files:
|
|
|
132
132
|
- README.rdoc
|
|
133
133
|
- ugc.rdoc
|
|
134
134
|
files:
|
|
135
|
+
- .gitignore
|
|
136
|
+
- .rvmrc
|
|
137
|
+
- Gemfile
|
|
138
|
+
- README.md
|
|
139
|
+
- README.rdoc
|
|
140
|
+
- Rakefile
|
|
135
141
|
- bin/ugc
|
|
136
|
-
-
|
|
142
|
+
- examples.jpeg
|
|
143
|
+
- features/step_definitions/ugc_steps.rb
|
|
144
|
+
- features/support/env.rb
|
|
145
|
+
- features/ugc.feature
|
|
137
146
|
- lib/ugc.rb
|
|
138
|
-
-
|
|
147
|
+
- lib/ugc/application.rb
|
|
148
|
+
- lib/ugc/commands/delete.rb
|
|
149
|
+
- lib/ugc/commands/get.rb
|
|
150
|
+
- lib/ugc/commands/list.rb
|
|
151
|
+
- lib/ugc/commands/login.rb
|
|
152
|
+
- lib/ugc/commands/post.rb
|
|
153
|
+
- lib/ugc/commands/profile.rb
|
|
154
|
+
- lib/ugc/commands/put.rb
|
|
155
|
+
- lib/ugc/commands/query.rb
|
|
156
|
+
- lib/ugc/commands/target.rb
|
|
157
|
+
- lib/ugc/helpers/formatters.rb
|
|
158
|
+
- lib/ugc/helpers/uri.rb
|
|
159
|
+
- lib/ugc/management.rb
|
|
160
|
+
- lib/ugc/settings.rb
|
|
161
|
+
- lib/ugc/version.rb
|
|
162
|
+
- test/default_test.rb
|
|
163
|
+
- test/test_helper.rb
|
|
164
|
+
- ugc.gemspec
|
|
139
165
|
- ugc.rdoc
|
|
140
166
|
homepage: http://ganyo.com
|
|
141
167
|
licenses: []
|
|
@@ -157,7 +183,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
157
183
|
version: '0'
|
|
158
184
|
segments:
|
|
159
185
|
- 0
|
|
160
|
-
hash:
|
|
186
|
+
hash: -2123078772774079119
|
|
161
187
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
188
|
none: false
|
|
163
189
|
requirements:
|
|
@@ -166,11 +192,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
166
192
|
version: '0'
|
|
167
193
|
segments:
|
|
168
194
|
- 0
|
|
169
|
-
hash:
|
|
195
|
+
hash: -2123078772774079119
|
|
170
196
|
requirements: []
|
|
171
197
|
rubyforge_project:
|
|
172
198
|
rubygems_version: 1.8.24
|
|
173
199
|
signing_key:
|
|
174
200
|
specification_version: 3
|
|
175
|
-
summary: Usergrid
|
|
201
|
+
summary: Usergrid Command Line
|
|
176
202
|
test_files: []
|