Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit 799b496057ecc9d50a47ef3c630c28fe5479c53b @theganyo committed Jan 1, 2013
@@ -0,0 +1,18 @@
+*.gem
+*.rbc
+.bundle
+.config
+.yardoc
+Gemfile.lock
+InstalledFiles
+_yardoc
+coverage
+doc/
+lib/bundler/man
+pkg
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp
+.idea
2 .rvmrc
@@ -0,0 +1,2 @@
+rvm_gemset_create_on_use_flag=1
+rvm gemset use 'ugc'
@@ -0,0 +1,2 @@
+source :rubygems
+gemspec
@@ -0,0 +1,31 @@
+# Usergrid Command Line (ugc)
+
+ugc enables convenient terminal access to Apigee's App Services (aka Usergrid).
+
+## Installation
+
+ $ gem install ugc
+
+## Usage
+
+### Help
+
+ $ ugc help
+
+### Setup
+
+Connect to an Apigee administrator account:
+
+ $ ugc profile apigee
+ $ ugc target organization scottganyo
+ organization = scottganyo
+ $ ugc target app messagee
+ application = messagee
+ $ ugc login -a scott@ganyo.com
+ password: **********
+ logged in user: scott@ganyo.com
+
+
+### Examples
+
+![image](examples.jpeg)
@@ -0,0 +1,6 @@
+= ugc
+
+Describe your project here
+
+:include:ugc.rdoc
+
@@ -0,0 +1,46 @@
+require "bundler/gem_tasks"
+
+require 'rake/clean'
+require 'rubygems'
+require 'rubygems/package_task'
+require 'rdoc/task'
+require 'cucumber'
+require 'cucumber/rake/task'
+Rake::RDocTask.new do |rd|
+ rd.main = "README.rdoc"
+ rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
+ rd.title = 'Your application title'
+end
+
+spec = eval(File.read('ugc.gemspec'))
+
+Gem::PackageTask.new(spec) do |pkg|
+end
+CUKE_RESULTS = 'results.html'
+CLEAN << CUKE_RESULTS
+desc 'Run features'
+Cucumber::Rake::Task.new(:features) do |t|
+ opts = "features --format html -o #{CUKE_RESULTS} --format progress -x"
+ opts += " --tags #{ENV['TAGS']}" if ENV['TAGS']
+ t.cucumber_opts = opts
+ t.fork = false
+end
+
+desc 'Run features tagged as work-in-progress (@wip)'
+Cucumber::Rake::Task.new('features:wip') do |t|
+ tag_opts = ' --tags ~@pending'
+ tag_opts = ' --tags @wip'
+ t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty -x -s#{tag_opts}"
+ t.fork = false
+end
+
+task :cucumber => :features
+task 'cucumber:wip' => 'features:wip'
+task :wip => 'features:wip'
+require 'rake/testtask'
+Rake::TestTask.new do |t|
+ t.libs << "test"
+ t.test_files = FileList['test/*_test.rb']
+end
+
+task :default => [:test,:features]
70 bin/ugc
@@ -0,0 +1,70 @@
+#!/usr/bin/env ruby
+
+require 'gli'
+require 'yaml'
+require 'usergrid_iron'
+require 'highline/import'
+require 'command_line_reporter'
+include CommandLineReporter
+require 'ugc'
+include GLI::App
+
+program_desc 'Usergrid Command Line'
+version Ugc::VERSION
+
+desc 'verbose'
+switch [:v,:verbose]
+
+desc 'settings directory'
+arg_name 'settings directory'
+default_value File.join(ENV['HOME'], '.ugc')
+flag [:s,:settings]
+
+# load helpers && commands
+commands_from '../lib/ugc/helpers'
+commands_from '../lib/ugc/commands'
+
+pre_login = [:info, :target, :profile]
+
+pre do |global_options,command,options,args|
+ if global_options[:verbose]
+ RestClient.log=Logger.new(STDOUT)
+ else
+ Usergrid::LOG.level = Logger::WARN
+ end
+
+ $settings = Ugc::Settings.new global_options[:settings]
+ if pre_login.include? command.name
+ true
+ elsif command.name == :login && $settings.configured?
+ true
+ else
+ if $settings.configured? && $settings.logged_in?
+ $application = Ugc::Application.new
+ true
+ else
+ if $settings.configured?
+ puts "not logged in"
+ else
+ puts "not configured"
+ end
+ false
+ end
+ end
+end
+
+post do |global_options,command,options,args|
+ # post-run logic here
+end
+
+on_error do |e|
+ # return false to skip default error handling
+ if e.is_a? RestClient::Exception
+ puts e.response.data['error_description']
+ false
+ else
+ true
+ end
+end
+
+exit run(ARGV)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,6 @@
+When /^I get help for "([^"]*)"$/ do |app_name|
+ @app_name = app_name
+ step %(I run `#{app_name} help`)
+end
+
+# Add more step definitions here
@@ -0,0 +1,15 @@
+require 'aruba/cucumber'
+
+ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
+LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)),'..','..','lib')
+
+Before do
+ # Using "announce" causes massive warnings on 1.9.2
+ @puts = true
+ @original_rubylib = ENV['RUBYLIB']
+ ENV['RUBYLIB'] = LIB_DIR + File::PATH_SEPARATOR + ENV['RUBYLIB'].to_s
+end
+
+After do
+ ENV['RUBYLIB'] = @original_rubylib
+end
@@ -0,0 +1,8 @@
+Feature: My bootstrapped app kinda works
+ In order to get going on coding my awesome app
+ I want to have aruba and cucumber setup
+ So I don't have to do it myself
+
+ Scenario: App just runs
+ When I get help for "ugc"
+ Then the exit status should be 0
@@ -0,0 +1,8 @@
+require 'ugc/version.rb'
+
+# Add requires for other files you add to your project here, so
+# you just need to require this one file in your bin file
+
+require 'ugc/settings.rb'
+require 'ugc/application.rb'
+require 'ugc/management.rb'
@@ -0,0 +1,25 @@
+module Ugc
+ class Application < Usergrid::Application
+
+ def initialize
+ super application_url
+ self.auth_token = $settings.access_token
+ end
+
+ def application_url
+ url = $settings.base_url
+ org = $settings.organization
+ app = $settings.application
+
+ raise "not configured" unless url && org && app
+
+ concat_urls url, "#{org}/#{app}"
+ end
+
+ def login(username, password)
+ super username, password
+ $settings.access_token = auth_token
+ end
+
+ end
+end
@@ -0,0 +1,10 @@
+desc 'http delete'
+arg_name 'url'
+
+command :delete do |c|
+
+ c.action do |global_options,options,args|
+ format_result resource(args[0]).delete
+ end
+
+end
@@ -0,0 +1,10 @@
+desc 'http get'
+arg_name 'url'
+
+command :get do |c|
+
+ c.action do |global_options,options,args|
+ format_result resource(args[0]).get
+ end
+
+end
@@ -0,0 +1,47 @@
+desc 'list'
+command :ls,:list do |c|
+
+ c.desc 'collections'
+ c.command [:collections] do |c2|
+
+ c2.action do |global_options,options,args|
+ app = $application.entity
+ collections = app['metadata']['collections']
+ table border: true do
+ row header: true do
+ collections.first[1].each_key do |k|
+ column k
+ end
+ end
+ collections.each_value do |coll|
+ row do
+ coll.each_value do |v|
+ column v
+ end
+ end
+ end
+ end
+ end
+ end
+
+ default_names = %w(assets users events roles folders activities devices groups)
+ default_names.each do |e|
+ c.desc e
+ c.command [e.to_sym] do |c2|
+ c2.action do |global_options,options,args|
+ format_collection($application[e].collection)
+ end
+ end
+ end
+
+ c.desc 'whatevers'
+ c.command [:whatevers] do |c2|
+ c2.action do |global_options,options,args|
+ whatevers = $application[args[0]].collection
+ format_collection(whatevers)
+ end
+ end
+
+ c.default_command :whatevers
+
+end
@@ -0,0 +1,28 @@
+require 'io/console'
+
+desc 'Describe login here'
+arg_name 'username'
+
+command :login do |c|
+
+ c.switch [:a,:admin]
+ c.action do |global_options,options,args|
+
+ if args[0]
+ password = ask('password: ') { |q| q.echo = '*' }
+
+ if password
+ if options[:admin]
+ management = Ugc::Management.new
+ management.login args[0], password
+ else
+ application = Ugc::Application.new
+ application.login args[0], password
+ end
+ end
+ puts "logged in user: #{args[0]}"
+ else
+ raise 'username required'
+ end
+ end
+end
@@ -0,0 +1,11 @@
+desc 'http post'
+arg_name 'url [data]'
+
+command :post do |c|
+ c.flag [:d,:data]
+
+ c.action do |global_options,options,args|
+ format_result resource(args[0]).post (options[:data] || args[1])
+ end
+
+end
@@ -0,0 +1,32 @@
+desc 'set the current profile'
+arg_name 'profile name'
+
+command :profile,:profiles do |c|
+ c.switch :d,:delete
+ c.action do |global_options,options,args|
+ if args[0]
+ if options[:delete]
+ $settings.delete_profile args[0]
+ puts "Deleted profile: " + args[0]
+ else
+ $settings.active_profile_name = args[0]
+ puts 'Set active profile:'
+ show_profile(args[0])
+ end
+ else
+ puts "Saved profiles:"
+ $settings.profiles.each_key do |name|
+ show_profile(name)
+ end
+ end
+ end
+end
+
+def show_profile(name)
+ profile = $settings.profile(name)
+ print $settings.active_profile_name == name ? ' *' : ' '
+ puts name
+ $settings.profile(name).each_pair do |k,v|
+ puts " #{k}: #{v}"
+ end
+end
Oops, something went wrong.

0 comments on commit 799b496

Please sign in to comment.