winnie 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +13 -3
- data/Rakefile +2 -4
- data/bin/winnie +1 -1
- data/lib/winnie/client.rb +1 -5
- data/lib/winnie/command.rb +5 -5
- data/lib/winnie/version.rb +1 -1
- data/lib/{winnie/winnie.rb → winnie.rb} +3 -3
- data/spec/client_spec.rb +29 -30
- data/spec/spec_helper.rb +5 -5
- data/winnie.gemspec +3 -3
- metadata +12 -14
- data/spec/spec.opts +0 -1
data/Gemfile.lock
CHANGED
@@ -1,19 +1,29 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
winnie (0.0.
|
4
|
+
winnie (0.0.2)
|
5
5
|
json
|
6
6
|
rest-client
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: http://rubygems.org/
|
10
10
|
specs:
|
11
|
+
diff-lcs (1.1.2)
|
11
12
|
fakefs (0.2.1)
|
12
13
|
json (1.4.6)
|
13
14
|
mime-types (1.16)
|
14
15
|
rest-client (1.6.1)
|
15
16
|
mime-types (>= 1.16)
|
16
|
-
rspec (
|
17
|
+
rspec (2.0.1)
|
18
|
+
rspec-core (~> 2.0.1)
|
19
|
+
rspec-expectations (~> 2.0.1)
|
20
|
+
rspec-mocks (~> 2.0.1)
|
21
|
+
rspec-core (2.0.1)
|
22
|
+
rspec-expectations (2.0.1)
|
23
|
+
diff-lcs (>= 1.1.2)
|
24
|
+
rspec-mocks (2.0.1)
|
25
|
+
rspec-core (~> 2.0.1)
|
26
|
+
rspec-expectations (~> 2.0.1)
|
17
27
|
|
18
28
|
PLATFORMS
|
19
29
|
ruby
|
@@ -22,5 +32,5 @@ DEPENDENCIES
|
|
22
32
|
fakefs
|
23
33
|
json
|
24
34
|
rest-client
|
25
|
-
rspec (
|
35
|
+
rspec (~> 2.0.0)
|
26
36
|
winnie!
|
data/Rakefile
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
require 'bundler'
|
2
2
|
Bundler::GemHelper.install_tasks
|
3
3
|
|
4
|
-
require '
|
5
|
-
|
6
|
-
spec.libs << 'lib' << 'spec'
|
7
|
-
spec.spec_files = FileList['spec/**/*_spec.rb']
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
8
6
|
end
|
9
7
|
|
10
8
|
task :default => :spec
|
data/bin/winnie
CHANGED
data/lib/winnie/client.rb
CHANGED
data/lib/winnie/command.rb
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
module Winnie
|
2
2
|
class Command
|
3
3
|
extend Helpers
|
4
|
-
|
4
|
+
|
5
5
|
def self.run(name, *args)
|
6
6
|
begin
|
7
7
|
class_name, command_name = name.split(':')
|
8
8
|
command_name ||= 'run'
|
9
|
-
|
9
|
+
|
10
10
|
begin
|
11
11
|
command_class = eval("Winnie::Commands::#{class_name.capitalize}")
|
12
12
|
rescue NameError
|
13
13
|
command_class = Winnie::Commands::App
|
14
14
|
command_name = class_name
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
command = command_class.new(args)
|
18
|
-
|
18
|
+
|
19
19
|
if command.respond_to?(command_name)
|
20
20
|
command.send(command_name)
|
21
21
|
else
|
22
22
|
raise UnknownCommandException.new
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
rescue UnknownCommandException
|
26
26
|
error 'Unknown command'
|
27
27
|
rescue Winnie::Client::UnauthorizedException
|
data/lib/winnie/version.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# TODO: loop here, and load all commands
|
2
|
-
module Winnie; end
|
3
2
|
require 'rubygems'
|
4
3
|
require 'rest_client'
|
5
4
|
require 'json'
|
6
5
|
require 'optparse'
|
6
|
+
require 'winnie/version'
|
7
7
|
require 'winnie/helpers'
|
8
8
|
require 'winnie/client'
|
9
|
-
require 'winnie/command'
|
10
9
|
require 'winnie/commands/base'
|
11
|
-
|
10
|
+
require 'winnie/command'
|
11
|
+
Dir["#{File.dirname(__FILE__)}/winnie/commands/*"].each { |c| require c }
|
data/spec/client_spec.rb
CHANGED
@@ -6,7 +6,7 @@ describe Winnie::Client do
|
|
6
6
|
@client = Winnie::Client.new('secret_one')
|
7
7
|
RestClient::Request.stub!(:execute)
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
describe "request" do
|
11
11
|
it "should make a request to give URL" do
|
12
12
|
RestClient::Request.should_receive(:execute).with(
|
@@ -14,82 +14,81 @@ describe Winnie::Client do
|
|
14
14
|
)
|
15
15
|
@client.request('/account', :get)
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
it "should include provided parameters in the request" do
|
19
19
|
RestClient::Request.should_receive(:execute).with(
|
20
|
-
request_parameters('/account', :post,
|
20
|
+
request_parameters('/account', :post,
|
21
21
|
:payload => {:api_key => 'secret_one', :name => 'test'}
|
22
22
|
)
|
23
23
|
)
|
24
24
|
@client.request('/account', :post, :name => 'test')
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
it "should include api_key in the request parameters" do
|
28
28
|
@client = Winnie::Client.new('AABBCC')
|
29
29
|
RestClient::Request.should_receive(:execute).with(
|
30
|
-
request_parameters('/account', :get,
|
30
|
+
request_parameters('/account', :get,
|
31
31
|
:payload => {:api_key => 'AABBCC'}
|
32
32
|
)
|
33
33
|
)
|
34
34
|
@client.request('/account', :get)
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
it "should accept json responses only" do
|
38
38
|
RestClient::Request.should_receive(:execute).with(
|
39
|
-
request_parameters('/account', :get,
|
39
|
+
request_parameters('/account', :get,
|
40
40
|
:headers => {:accept => 'application/json'}
|
41
41
|
)
|
42
42
|
)
|
43
43
|
@client.request('/account', :get)
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
it "should pass response to process_response method" do
|
47
47
|
response = mock(RestClient::Response)
|
48
48
|
request = mock(RestClient::Request)
|
49
49
|
@client.should_receive(:process_response).with(response)
|
50
50
|
RestClient::Request.should_receive(:execute).with(request_parameters('/account', :get)).and_yield(response, request)
|
51
|
-
|
51
|
+
|
52
52
|
@client.request('/account', :get)
|
53
53
|
end
|
54
|
-
|
55
|
-
|
54
|
+
|
56
55
|
def request_parameters(path, method, params = {})
|
57
|
-
{:payload => {:api_key => 'secret_one'},
|
58
|
-
:method => method,
|
59
|
-
:headers => {:accept => 'application/json'},
|
60
|
-
:url => "
|
56
|
+
{:payload => {:api_key => 'secret_one'},
|
57
|
+
:method => method,
|
58
|
+
:headers => {:accept => 'application/json'},
|
59
|
+
:url => "https://admin.winniecloud.com#{path}"
|
61
60
|
}.merge(params)
|
62
61
|
end
|
63
62
|
end
|
64
|
-
|
63
|
+
|
65
64
|
describe "process_response" do
|
66
65
|
before do
|
67
66
|
@response = mock(RestClient::Response, :code => 200, :body => '{}', :return! => nil)
|
68
67
|
@request = mock(RestClient::Request)
|
69
68
|
RestClient::Request.stub(:execute).and_yield(@response, @request)
|
70
69
|
end
|
71
|
-
|
70
|
+
|
72
71
|
it "should not follow redirections" do
|
73
72
|
@response.should_receive(:return!)
|
74
73
|
@client.get('/account')
|
75
74
|
end
|
76
|
-
|
75
|
+
|
77
76
|
it "should raise UnauthorizedException when response has 401 code" do
|
78
77
|
@response.stub(:code).and_return(401)
|
79
78
|
lambda {
|
80
79
|
@client.get('/account')
|
81
80
|
}.should raise_error(Winnie::Client::UnauthorizedException)
|
82
81
|
end
|
83
|
-
|
82
|
+
|
84
83
|
it "should raise UnauthorizedException when it gets redirected to login page" do
|
85
84
|
@response.stub(:args).and_return({:url => 'user_session'})
|
86
85
|
@response.stub(:code).and_return(302)
|
87
|
-
|
86
|
+
|
88
87
|
lambda {
|
89
88
|
@client.get('/account')
|
90
89
|
}.should raise_error(Winnie::Client::UnauthorizedException)
|
91
90
|
end
|
92
|
-
|
91
|
+
|
93
92
|
it "should raise ResourceNotFoundException when response has 404 code" do
|
94
93
|
@response.stub(:code).and_return(404)
|
95
94
|
@response.stub(:body).and_return({'error' => 'App not found'}.to_json)
|
@@ -98,45 +97,45 @@ describe Winnie::Client do
|
|
98
97
|
@client.post('/apps/flower/command', :body => 'puts User.count')
|
99
98
|
}.should raise_error(Winnie::Client::ResourceNotFoundException, 'App not found')
|
100
99
|
end
|
101
|
-
|
100
|
+
|
102
101
|
it "should raise CommandFailedException when response has 500 code" do
|
103
102
|
@response.stub(:code).and_return(500)
|
104
103
|
@response.stub(:body).and_return({'error' => 'random error happened'}.to_json)
|
105
|
-
|
104
|
+
|
106
105
|
lambda {
|
107
106
|
@client.post('/apps/flower/command', :body => 'puts User.count')
|
108
107
|
}.should raise_error(Winnie::Client::CommandFailedException, 'random error happened')
|
109
108
|
end
|
110
109
|
end
|
111
|
-
|
110
|
+
|
112
111
|
it "should make GET request to given path" do
|
113
112
|
@client.should_receive(:request).with('/account', :get)
|
114
113
|
@client.get('/account')
|
115
114
|
end
|
116
|
-
|
115
|
+
|
117
116
|
it "should make POST request to given path with parameters" do
|
118
117
|
@client.should_receive(:request).with('/account', :post, :name => 'pink-one')
|
119
118
|
@client.post('/account', :name => 'pink-one')
|
120
119
|
end
|
121
|
-
|
120
|
+
|
122
121
|
describe "API methods" do
|
123
122
|
it "should get the list of user applications" do
|
124
123
|
@client.should_receive(:get).with('/apps')
|
125
124
|
@client.apps
|
126
125
|
end
|
127
|
-
|
126
|
+
|
128
127
|
it "should get account info" do
|
129
128
|
@client.should_receive(:get).with('/account')
|
130
129
|
@client.account
|
131
130
|
end
|
132
|
-
|
131
|
+
|
133
132
|
it "should send command to winnie" do
|
134
133
|
@client.should_receive(:post).with('/apps/flower-16/command', :body => 'User[:bob].destroy')
|
135
134
|
@client.command('User[:bob].destroy', 'flower-16')
|
136
135
|
end
|
137
136
|
end
|
138
|
-
|
137
|
+
|
139
138
|
it "should return winnie-app URL" do
|
140
|
-
@client.winnie_url.should == "
|
139
|
+
@client.winnie_url.should == "https://admin.winniecloud.com"
|
141
140
|
end
|
142
141
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
2
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
3
|
require 'rubygems'
|
4
|
-
require 'winnie
|
5
|
-
require '
|
6
|
-
require '
|
4
|
+
require 'winnie'
|
5
|
+
require 'rspec'
|
6
|
+
require 'rspec/autorun'
|
7
7
|
require 'fakefs'
|
8
8
|
require 'fakefs/spec_helpers'
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.color_enabled = true
|
12
12
|
end
|
data/winnie.gemspec
CHANGED
@@ -8,11 +8,11 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ["winnie"]
|
10
10
|
s.email = ["winnie-devs@ragnarson.com"]
|
11
|
-
s.homepage = "http://
|
11
|
+
s.homepage = "http://winniecloud.com"
|
12
12
|
s.summary = %Q{Winnie command line tool}
|
13
13
|
s.description = %Q{Command line tool which allows interacting with winnie's API}
|
14
14
|
|
15
|
-
s.rubyforge_project = "
|
15
|
+
s.rubyforge_project = "winnie"
|
16
16
|
|
17
17
|
s.files = `git ls-files`.split("\n")
|
18
18
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
|
|
21
21
|
|
22
22
|
s.add_dependency "json"
|
23
23
|
s.add_dependency "rest-client"
|
24
|
-
s.add_development_dependency "rspec", "
|
24
|
+
s.add_development_dependency "rspec", "~> 2.0.0"
|
25
25
|
s.add_development_dependency "fakefs"
|
26
26
|
|
27
27
|
# TODO: remove after few releases
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: winnie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- winnie
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-26 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -52,14 +52,14 @@ dependencies:
|
|
52
52
|
requirement: &id003 !ruby/object:Gem::Requirement
|
53
53
|
none: false
|
54
54
|
requirements:
|
55
|
-
- -
|
55
|
+
- - ~>
|
56
56
|
- !ruby/object:Gem::Version
|
57
|
-
hash:
|
57
|
+
hash: 15
|
58
58
|
segments:
|
59
|
-
- 1
|
60
59
|
- 2
|
61
|
-
-
|
62
|
-
|
60
|
+
- 0
|
61
|
+
- 0
|
62
|
+
version: 2.0.0
|
63
63
|
type: :development
|
64
64
|
version_requirements: *id003
|
65
65
|
- !ruby/object:Gem::Dependency
|
@@ -93,6 +93,7 @@ files:
|
|
93
93
|
- README.rdoc
|
94
94
|
- Rakefile
|
95
95
|
- bin/winnie
|
96
|
+
- lib/winnie.rb
|
96
97
|
- lib/winnie/client.rb
|
97
98
|
- lib/winnie/command.rb
|
98
99
|
- lib/winnie/commands/app.rb
|
@@ -101,18 +102,16 @@ files:
|
|
101
102
|
- lib/winnie/commands/help.rb
|
102
103
|
- lib/winnie/helpers.rb
|
103
104
|
- lib/winnie/version.rb
|
104
|
-
- lib/winnie/winnie.rb
|
105
105
|
- spec/client_spec.rb
|
106
106
|
- spec/command_spec.rb
|
107
107
|
- spec/commands/app_spec.rb
|
108
108
|
- spec/commands/auth_spec.rb
|
109
109
|
- spec/commands/base_spec.rb
|
110
|
-
- spec/spec.opts
|
111
110
|
- spec/spec_helper.rb
|
112
111
|
- spec/winnie_spec.rb
|
113
112
|
- winnie.gemspec
|
114
113
|
has_rdoc: true
|
115
|
-
homepage: http://
|
114
|
+
homepage: http://winniecloud.com
|
116
115
|
licenses: []
|
117
116
|
|
118
117
|
post_install_message: |
|
@@ -151,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
150
|
version: "0"
|
152
151
|
requirements: []
|
153
152
|
|
154
|
-
rubyforge_project:
|
153
|
+
rubyforge_project: winnie
|
155
154
|
rubygems_version: 1.3.7
|
156
155
|
signing_key:
|
157
156
|
specification_version: 3
|
@@ -162,6 +161,5 @@ test_files:
|
|
162
161
|
- spec/commands/app_spec.rb
|
163
162
|
- spec/commands/auth_spec.rb
|
164
163
|
- spec/commands/base_spec.rb
|
165
|
-
- spec/spec.opts
|
166
164
|
- spec/spec_helper.rb
|
167
165
|
- spec/winnie_spec.rb
|
data/spec/spec.opts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--color
|