jiveapps 0.0.3

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.
@@ -0,0 +1,29 @@
1
+ module Jiveapps
2
+ module Helpers
3
+ def home_directory
4
+ running_on_windows? ? ENV['USERPROFILE'] : ENV['HOME']
5
+ end
6
+
7
+ def running_on_windows?
8
+ RUBY_PLATFORM =~ /mswin32|mingw32/
9
+ end
10
+
11
+ def running_on_a_mac?
12
+ RUBY_PLATFORM =~ /-darwin\d/
13
+ end
14
+
15
+ def display(msg, newline=true)
16
+ if newline
17
+ puts(msg)
18
+ else
19
+ print(msg)
20
+ STDOUT.flush
21
+ end
22
+ end
23
+
24
+ def error(msg)
25
+ STDERR.puts(msg)
26
+ exit 1
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,121 @@
1
+ require 'spec_helper'
2
+
3
+ describe Jiveapps::Client do
4
+
5
+ before do
6
+ @client = Jiveapps::Client.new(nil, nil)
7
+ end
8
+
9
+ it "list -> get a list of this user's apps" do
10
+ stub_api_request(:get, "/apps").to_return(:body => <<-EOXML)
11
+ [
12
+ {
13
+ "app": {
14
+ "name" : "foo",
15
+ "created_at" : "2010-10-15T23:59:10Z",
16
+ "updated_at" : "2010-10-15T23:59:10Z",
17
+ "id" : 1
18
+ }
19
+ },
20
+ {
21
+ "app": {
22
+ "name" : "bar",
23
+ "created_at" : "2010-10-16T01:12:16Z",
24
+ "updated_at" : "2010-10-16T01:12:16Z",
25
+ "id" : 2
26
+ }
27
+ }
28
+ ]
29
+ EOXML
30
+ @client.list.should == [
31
+ {
32
+ "name" => "foo",
33
+ "created_at" => "2010-10-15T23:59:10Z",
34
+ "updated_at" => "2010-10-15T23:59:10Z",
35
+ "id" => 1
36
+ },
37
+ {
38
+ "name" => "bar",
39
+ "created_at" => "2010-10-16T01:12:16Z",
40
+ "updated_at" => "2010-10-16T01:12:16Z",
41
+ "id" => 2
42
+ }
43
+ ]
44
+ end
45
+
46
+ it "info -> get app attributes" do
47
+ stub_api_request(:get, "/apps/myapp").to_return(:body => <<-EOXML)
48
+ {"app":{"name":"myapp","created_at":"2010-10-15T23:59:10Z","updated_at":"2010-10-15T23:59:10Z","id":1}}
49
+ EOXML
50
+
51
+ @client.info('myapp').should == {
52
+ "name" => "myapp",
53
+ "created_at" => "2010-10-15T23:59:10Z",
54
+ "updated_at" => "2010-10-15T23:59:10Z",
55
+ "id" => 1
56
+ }
57
+ end
58
+
59
+ it "create -> should create a new app and return it's attributes" do
60
+ stub_api_request(:post, "/apps").to_return(:body => <<-EOXML)
61
+ {"app":{"name":"myapp","created_at":"2010-10-15T23:59:10Z","updated_at":"2010-10-15T23:59:10Z","id":1}}
62
+ EOXML
63
+
64
+ @client.create('myapp').should == {
65
+ "name" => "myapp",
66
+ "created_at" => "2010-10-15T23:59:10Z",
67
+ "updated_at" => "2010-10-15T23:59:10Z",
68
+ "id" => 1
69
+ }
70
+ end
71
+
72
+ describe "ssh keys" do
73
+ it "fetches a list of the user's current keys" do
74
+ stub_api_request(:get, "/ssh_keys").to_return(:body => <<-EOXML)
75
+ [
76
+ {
77
+ "ssh_key": {
78
+ "name": "foobar",
79
+ "created_at": "2010-11-01T18:31:04Z",
80
+ "updated_at": "2010-11-01T18:31:04Z",
81
+ "username": "testuser",
82
+ "id": 3,
83
+ "key": "a b foobar"
84
+ }
85
+ }
86
+ ]
87
+ EOXML
88
+ @client.keys.should == [
89
+ {
90
+ "name" => "foobar",
91
+ "created_at" => "2010-11-01T18:31:04Z",
92
+ "updated_at" => "2010-11-01T18:31:04Z",
93
+ "username" => "testuser",
94
+ "id" => 3,
95
+ "key" => "a b foobar"
96
+ }
97
+ ]
98
+ end
99
+
100
+ it "add_key(key) -> add an ssh key (e.g., the contents of id_rsa.pub) to the user" do
101
+ stub_api_request(:post, "/ssh_keys").to_return(:body => <<-EOXML)
102
+ {"ssh_key":{"key":"a key"}}
103
+ EOXML
104
+ @client.add_key('a key')
105
+ end
106
+
107
+ it "remove_key(key) -> remove an ssh key by name (user@box)" do
108
+ ### Ugly hack - nginx/passenger unescapes the name before it gets to rails, causing routes to fail. double encode in production
109
+ stub_api_request(:delete, "/ssh_keys/joe%40workstation")
110
+ stub_api_request(:delete, "/ssh_keys/joe%2540workstation") # stub the double-encoded version too.
111
+ @client.remove_key('joe@workstation')
112
+ end
113
+
114
+ # it "remove_all_keys -> removes all ssh keys for the user" do
115
+ # stub_api_request(:delete, "/ssh_keys")
116
+ # @client.remove_all_keys
117
+ # end
118
+ end
119
+
120
+
121
+ end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ module Jiveapps::Command
4
+ describe App do
5
+ before(:each) do
6
+ @cli = prepare_command(App)
7
+ end
8
+
9
+ describe "app list" do
10
+ it "shows a list of apps" do
11
+ @cli.stub!(:args).and_return([])
12
+ @cli.jiveapps.should_receive(:list).and_return([{ 'name' => 'myapp' }, { 'name' => 'yourapp' }])
13
+ @cli.should_receive(:display).with('Your apps:')
14
+ @cli.should_receive(:display).with([" - myapp", " - yourapp"])
15
+ @cli.list
16
+ end
17
+
18
+ it "shows 'You have no apps.' if the API returns an empty list" do
19
+ @cli.stub!(:args).and_return([])
20
+ @cli.jiveapps.should_receive(:list).and_return([])
21
+ @cli.should_receive(:display).with('You have no apps.')
22
+ @cli.list
23
+ end
24
+
25
+ end
26
+
27
+ describe "app info" do
28
+ it "shows info when name specified and rest client returns an app" do
29
+ @cli.stub!(:args).and_return(['myapp'])
30
+ @cli.jiveapps.should_receive(:info).with('myapp').and_return({
31
+ 'name' => 'myapp',
32
+ 'app_url' => 'http://app_url',
33
+ 'git_url' => 'http://git_url'
34
+ })
35
+ @cli.should_receive(:display).with('=== myapp')
36
+ @cli.should_receive(:display).with("App URL: http://app_url")
37
+ @cli.should_receive(:display).with("Git URL: http://git_url")
38
+ @cli.info
39
+ end
40
+
41
+ it "shows 'App not found.' when name specified and rest client does not return an app" do
42
+ @cli.stub!(:args).and_return(['invalid_app'])
43
+ @cli.jiveapps.should_receive(:info).with('invalid_app').and_return(nil)
44
+ @cli.should_receive(:display).with('App not found.')
45
+ @cli.info
46
+ end
47
+
48
+ it "shows 'No app specified.' when no name specified" do
49
+ @cli.stub!(:args).and_return([])
50
+ @cli.jiveapps.should_not_receive(:info)
51
+ @cli.should_receive(:display).with('No app specified.')
52
+ @cli.should_receive(:display).with('Run this command from app folder or set it by running: jiveapps info <app name>')
53
+ @cli.info
54
+ end
55
+
56
+ end
57
+
58
+ end
59
+ end
@@ -0,0 +1,89 @@
1
+ require 'spec_helper'
2
+
3
+ module Jiveapps::Command
4
+ describe Keys do
5
+ before do
6
+ @keys = prepare_command(Keys)
7
+ @keys.jiveapps.stub!(:user).and_return('joe')
8
+
9
+ @key_list_response = [
10
+ {
11
+ "name" => "foobar",
12
+ "created_at" => "2010-11-01T18:31:04Z",
13
+ "updated_at" => "2010-11-01T18:31:04Z",
14
+ "username" => "testuser",
15
+ "id" => 3,
16
+ "key" => "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAp9AJD5QABmOcrkHm6SINuQkDefaR0MUrfgZ1Pxir3a4fM1fwa00dsUwbUaRuR7FEFD8n1E9WwDf8SwQTHtyZsJg09G9myNqUzkYXCmydN7oGr5IdVhRyv5ixcdiE0hj7dRnOJg2poSQ3Qi+Ka8SVJzF7nIw1YhuicHPSbNIFKi5s0D5a+nZb/E6MNGvhxoFCQX2IcNxaJMqhzy1ESwlixz45aT72mXYq0LIxTTpoTqma1HuKdRY8HxoREiivjmMQulYP+CxXFcMyV9kxTKIUZ/FXqlC6G5vSm3J4YScSatPOj9ID5HowpdlIx8F6y4p1/28r2tTl4CY40FFyoke4MQ== pablo@jive\n"
17
+ }
18
+ ]
19
+ end
20
+
21
+ it "adds a key from the default locations if no key filename is supplied" do
22
+ @keys.should_receive(:find_key).and_return('/home/joe/.ssh/id_rsa.pub')
23
+ File.should_receive(:read).with('/home/joe/.ssh/id_rsa.pub').and_return('ssh-rsa xyz')
24
+ @keys.jiveapps.should_receive(:add_key).with('ssh-rsa xyz')
25
+ @keys.should_receive(:display).with("Uploading ssh public key /home/joe/.ssh/id_rsa.pub")
26
+ @keys.add
27
+ end
28
+
29
+ it "adds a key from a specified keyfile path" do
30
+ @keys.stub!(:args).and_return(['/my/key.pub'])
31
+ @keys.should_receive(:find_key).with('/my/key.pub').and_return('/my/key.pub')
32
+ File.should_receive(:read).with('/my/key.pub').and_return('ssh-rsa xyz')
33
+ @keys.jiveapps.should_receive(:add_key).with('ssh-rsa xyz')
34
+ @keys.add
35
+ end
36
+
37
+ it "list keys, trimming the hex code for better display" do
38
+ @keys.jiveapps.should_receive(:keys).and_return(@key_list_response)
39
+ @keys.should_receive(:display).with('ssh-rsa AAAAB3NzaC...Fyoke4MQ== pablo@jive')
40
+ @keys.list
41
+ end
42
+
43
+ it "list keys showing the whole key hex with --long" do
44
+ @keys.stub!(:args).and_return(['--long'])
45
+ @keys.jiveapps.should_receive(:keys).and_return(@key_list_response)
46
+ @keys.should_receive(:display).with("ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAp9AJD5QABmOcrkHm6SINuQkDefaR0MUrfgZ1Pxir3a4fM1fwa00dsUwbUaRuR7FEFD8n1E9WwDf8SwQTHtyZsJg09G9myNqUzkYXCmydN7oGr5IdVhRyv5ixcdiE0hj7dRnOJg2poSQ3Qi+Ka8SVJzF7nIw1YhuicHPSbNIFKi5s0D5a+nZb/E6MNGvhxoFCQX2IcNxaJMqhzy1ESwlixz45aT72mXYq0LIxTTpoTqma1HuKdRY8HxoREiivjmMQulYP+CxXFcMyV9kxTKIUZ/FXqlC6G5vSm3J4YScSatPOj9ID5HowpdlIx8F6y4p1/28r2tTl4CY40FFyoke4MQ== pablo@jive")
47
+ @keys.list
48
+ end
49
+
50
+ it "removes the key matching the specified name" do
51
+ @keys.stub!(:args).and_return(['pablo@jive'])
52
+ @keys.jiveapps.should_receive(:remove_key).with('pablo@jive')
53
+ @keys.remove
54
+ end
55
+
56
+ context "key locating" do
57
+ before do
58
+ @keys.stub!(:home_directory).and_return('/home/joe')
59
+ end
60
+
61
+ it "finds the user's ssh key in ~/ssh/id_rsa.pub" do
62
+ File.should_receive(:exists?).with('/home/joe/.ssh/id_rsa.pub').and_return(true)
63
+ @keys.send(:find_key).should == '/home/joe/.ssh/id_rsa.pub'
64
+ end
65
+
66
+ it "finds the user's ssh key in ~/ssh/id_dsa.pub" do
67
+ File.should_receive(:exists?).with('/home/joe/.ssh/id_rsa.pub').and_return(false)
68
+ File.should_receive(:exists?).with('/home/joe/.ssh/id_dsa.pub').and_return(true)
69
+ @keys.send(:find_key).should == '/home/joe/.ssh/id_dsa.pub'
70
+ end
71
+
72
+ it "finds the user's ssh key in the specified path, /my/path/id_rsa.pub" do
73
+ File.should_receive(:exists?).with('/my/path/id_rsa.pub').and_return(true)
74
+ @keys.send(:find_key, '/my/path/id_rsa.pub').should == '/my/path/id_rsa.pub'
75
+ end
76
+
77
+ it "raises an exception if neither id_rsa or id_dsa were found" do
78
+ File.stub!(:exists?).and_return(false)
79
+ lambda { @keys.send(:find_key) }.should raise_error(Jiveapps::Command::CommandFailed)
80
+ end
81
+
82
+ it "raises an exception if specified path not found" do
83
+ File.stub!(:exists?).and_return(false)
84
+ lambda { @keys.send(:find_key, '/my/path/id_rsa.pub') }.should raise_error(Jiveapps::Command::CommandFailed)
85
+ end
86
+ end
87
+
88
+ end
89
+ end
@@ -0,0 +1,26 @@
1
+ require 'rspec'
2
+ require 'webmock/rspec'
3
+
4
+ Rspec.configure do |c|
5
+ c.mock_with :rspec
6
+ c.include WebMock::API
7
+ end
8
+
9
+ require 'jiveapps'
10
+ require 'jiveapps/command'
11
+ require 'jiveapps/commands/base'
12
+ Dir["#{File.dirname(__FILE__)}/../lib/jiveapps/commands/*"].each { |c| require c }
13
+ require 'jiveapps/client'
14
+
15
+ def stub_api_request(method, path)
16
+ stub_request(method, "http://#{Jiveapps::WEBHOST}#{path}")
17
+ end
18
+
19
+ def prepare_command(klass)
20
+ command = klass.new(['--app', 'myapp'])
21
+ command.stub!(:args).and_return([])
22
+ command.stub!(:display)
23
+ command.stub!(:jiveapps).and_return(mock('jiveapps client', :host => 'jiveapps.com'))
24
+ command.stub!(:extract_app).and_return('myapp')
25
+ command
26
+ end
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jiveapps
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 3
10
+ version: 0.0.3
11
+ platform: ruby
12
+ authors:
13
+ - Scott Becker
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-19 00:00:00 -08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rest-client
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: json
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: rubigen
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :runtime
62
+ version_requirements: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ name: rubyforge
65
+ prerelease: false
66
+ requirement: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 7
72
+ segments:
73
+ - 2
74
+ - 0
75
+ - 4
76
+ version: 2.0.4
77
+ type: :development
78
+ version_requirements: *id004
79
+ - !ruby/object:Gem::Dependency
80
+ name: hoe
81
+ prerelease: false
82
+ requirement: &id005 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 19
88
+ segments:
89
+ - 2
90
+ - 6
91
+ - 2
92
+ version: 2.6.2
93
+ type: :development
94
+ version_requirements: *id005
95
+ description: A set of command line tools for creating Jive Apps.
96
+ email:
97
+ - becker.scott@gmail.com
98
+ executables:
99
+ - jiveapps
100
+ extensions: []
101
+
102
+ extra_rdoc_files:
103
+ - History.txt
104
+ - Manifest.txt
105
+ - PostInstall.txt
106
+ files:
107
+ - .rspec
108
+ - History.txt
109
+ - Manifest.txt
110
+ - PostInstall.txt
111
+ - README.rdoc
112
+ - Rakefile
113
+ - app_generators/create/USAGE
114
+ - app_generators/create/create_generator.rb
115
+ - app_generators/create/templates/app.xml
116
+ - app_generators/create/templates/canvas.html
117
+ - app_generators/create/templates/hello.html
118
+ - app_generators/create/templates/home.html
119
+ - app_generators/create/templates/images/j-icon-jaf-48.png
120
+ - app_generators/create/templates/javascripts/main.js
121
+ - app_generators/create/templates/stylesheets/main.css
122
+ - autotest/discover.rb
123
+ - bin/jiveapps
124
+ - lib/jiveapps.rb
125
+ - lib/jiveapps/client.rb
126
+ - lib/jiveapps/command.rb
127
+ - lib/jiveapps/commands/app.rb
128
+ - lib/jiveapps/commands/auth.rb
129
+ - lib/jiveapps/commands/base.rb
130
+ - lib/jiveapps/commands/help.rb
131
+ - lib/jiveapps/commands/keys.rb
132
+ - lib/jiveapps/helpers.rb
133
+ - spec/client_spec.rb
134
+ - spec/commands/app_spec.rb
135
+ - spec/commands/keys_spec.rb
136
+ - spec/spec_helper.rb
137
+ has_rdoc: true
138
+ homepage: http://github.com/#{github_username}/#{project_name}
139
+ licenses: []
140
+
141
+ post_install_message: PostInstall.txt
142
+ rdoc_options:
143
+ - --main
144
+ - README.rdoc
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ none: false
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ hash: 3
153
+ segments:
154
+ - 0
155
+ version: "0"
156
+ required_rubygems_version: !ruby/object:Gem::Requirement
157
+ none: false
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ hash: 3
162
+ segments:
163
+ - 0
164
+ version: "0"
165
+ requirements: []
166
+
167
+ rubyforge_project: jiveapps
168
+ rubygems_version: 1.3.7
169
+ signing_key:
170
+ specification_version: 3
171
+ summary: A set of command line tools for creating Jive Apps.
172
+ test_files: []
173
+