winnie 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  pkg/*
2
2
  *.gem
3
3
  .bundle
4
+ Gemfile.lock
@@ -3,16 +3,15 @@ require 'fileutils'
3
3
  module Winnie
4
4
  module Commands
5
5
  class Auth < Base
6
- attr_accessor :api_key
7
6
 
8
7
  def initialize(*args)
9
8
  super(args)
10
- load_api_key if api_key_exists?
9
+ load_api_key if (api_key.nil? and api_key_exists?)
11
10
  end
12
11
 
13
12
  def run
14
- confirm('Do you want to change your API key?') if api_key_exists?
15
- ask_for_api_key
13
+ confirm('Do you want to change your API key?') if (api_key.nil? and api_key_exists?)
14
+ ask_for_api_key if api_key.nil?
16
15
  save_api_key
17
16
  validate_api_key
18
17
  end
@@ -20,7 +19,7 @@ module Winnie
20
19
  def ask_for_api_key
21
20
  display "Type your Winnie API key"
22
21
  display "Key: ", false
23
- self.api_key = ask
22
+ @api_key = ask
24
23
  end
25
24
 
26
25
  def save_api_key
@@ -30,11 +29,11 @@ module Winnie
30
29
  end
31
30
 
32
31
  def load_api_key
33
- self.api_key = File.read(api_key_path)
32
+ @api_key = File.read(api_key_path)
34
33
  end
35
34
 
36
35
  def validate_api_key
37
- winnie.account # If it's not correct, Winnie::Client::UnauthorizedException will be raised
36
+ winnie.account # If it's not correct, Winnie::Client::UnauthorizedException will be raised
38
37
  display 'Your winnie API key is OK!'
39
38
  end
40
39
 
@@ -1,7 +1,7 @@
1
1
  module Winnie
2
2
  module Commands
3
3
  class Base
4
- attr_reader :winnie, :args
4
+ attr_reader :winnie, :args, :api_key
5
5
 
6
6
  include Winnie::Helpers
7
7
 
@@ -17,17 +17,20 @@ module Winnie
17
17
  opts.on("-a", "--app [CODE_NAME]", :text, "Run for given application") do |a|
18
18
  @code_name = a
19
19
  end
20
+
21
+ opts.on("-k", "--api-key [API KEY]", :text, "Authorize command for given api key") do |k|
22
+ @api_key = k
23
+ end
20
24
  end.parse!(@args)
21
25
  end
22
26
 
23
27
  def code_name
24
- raise ApplicationNotSpecyfiedException.new unless @code_name
25
- @code_name
28
+ @code_name || raise(ApplicationNotSpecyfiedException.new)
26
29
  end
27
30
 
28
31
  def winnie
29
- auth = Winnie::Commands::Auth.new
30
- @winnie ||= Winnie::Client.new(auth.api_key)
32
+ @api_key ||= Winnie::Commands::Auth.new.api_key
33
+ @winnie ||= Winnie::Client.new(api_key)
31
34
  end
32
35
 
33
36
  def config_path
@@ -2,7 +2,7 @@ module Winnie
2
2
  module Commands
3
3
  class Help < Base
4
4
  def run
5
- display_columns 'auth', 'Configure your winnie username and password'
5
+ display_columns 'auth', 'Configure your winnie api key'
6
6
  display_columns 'command <command or file>', 'Run ruby command, a file with commands can be given'
7
7
  display_columns 'list', 'List your applications'
8
8
  display_columns 'help', 'Show this information'
@@ -1,3 +1,3 @@
1
1
  module Winnie
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
data/spec/client_spec.rb CHANGED
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
1
+ require "spec_helper"
2
2
 
3
3
  describe Winnie::Client do
4
4
  before do
@@ -40,10 +40,10 @@ describe Winnie::Client do
40
40
  end
41
41
 
42
42
  def request_parameters(path, method, payload = {})
43
- {:payload => ({:api_key => 'secret_one'}.merge(payload)).to_json,
44
- :method => method,
45
- :headers => {:accept => :json, :content_type => :json},
46
- :url => "https://admin.winniecloud.com#{path}"
43
+ {:method => method,
44
+ :url => "https://admin.winniecloud.com#{path}",
45
+ :headers => {:accept => :json, :content_type => :json},
46
+ :payload => ({:api_key => 'secret_one'}.merge(payload)).to_json
47
47
  }
48
48
  end
49
49
  end
data/spec/command_spec.rb CHANGED
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
1
+ require "spec_helper"
2
2
 
3
3
  describe Winnie::Command do
4
4
  describe "run" do
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
1
+ require "spec_helper"
2
2
 
3
3
  describe Winnie::Commands::App do
4
4
  before do
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
1
+ require "spec_helper"
2
2
 
3
3
  describe Winnie::Commands::Auth do
4
4
  include FakeFS::SpecHelpers
@@ -23,6 +23,14 @@ describe Winnie::Commands::Auth do
23
23
  auth.api_key.should == 'NobodyKnowsIt'
24
24
  end
25
25
  end
26
+
27
+ describe "when API key is passed as an option" do
28
+ before { @auth = Winnie::Commands::Auth.new("--api-key", "secret") }
29
+
30
+ it "should be set" do
31
+ @auth.api_key.should == "secret"
32
+ end
33
+ end
26
34
  end
27
35
 
28
36
  describe "run" do
@@ -56,11 +64,30 @@ describe Winnie::Commands::Auth do
56
64
  @auth.run
57
65
  end
58
66
  end
67
+
68
+ describe "when API key is passed as an option" do
69
+ before do
70
+ @auth = Winnie::Commands::Auth.new("--api-key", "secret")
71
+ @auth.stub(:save_api_key)
72
+ @auth.stub(:validate_api_key)
73
+ end
74
+
75
+ it "should not ask for API key" do
76
+ @auth.should_not_receive(:ask_for_api_key)
77
+ @auth.run
78
+ end
79
+
80
+ it "should not prompt confirm" do
81
+ @auth.stub(:api_key_exists? => true)
82
+ @auth.should_not_receive(:confirm)
83
+ @auth.run
84
+ end
85
+ end
59
86
  end
60
87
 
61
88
  describe "save_api_key" do
62
89
  before do
63
- @auth.api_key = 'secret_api_key'
90
+ @auth.instance_variable_set("@api_key", 'secret_api_key')
64
91
  @auth.stub(:set_credentials_permissions => true)
65
92
  end
66
93
 
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
1
+ require "spec_helper"
2
2
 
3
3
  describe Winnie::Commands::Base do
4
4
  describe "config_path" do
data/spec/winnie_spec.rb CHANGED
@@ -1 +1 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
1
+ require "spec_helper"
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: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
9
+ - 7
10
+ version: 0.0.7
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: 2011-02-23 00:00:00 +01:00
18
+ date: 2011-03-28 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -102,7 +102,6 @@ extra_rdoc_files: []
102
102
  files:
103
103
  - .gitignore
104
104
  - Gemfile
105
- - Gemfile.lock
106
105
  - LICENSE
107
106
  - README.rdoc
108
107
  - Rakefile
@@ -154,15 +153,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
153
  requirements: []
155
154
 
156
155
  rubyforge_project: winnie
157
- rubygems_version: 1.5.0
156
+ rubygems_version: 1.6.2
158
157
  signing_key:
159
158
  specification_version: 3
160
159
  summary: Winnie command line tool
161
- test_files:
162
- - spec/client_spec.rb
163
- - spec/command_spec.rb
164
- - spec/commands/app_spec.rb
165
- - spec/commands/auth_spec.rb
166
- - spec/commands/base_spec.rb
167
- - spec/spec_helper.rb
168
- - spec/winnie_spec.rb
160
+ test_files: []
161
+
data/Gemfile.lock DELETED
@@ -1,34 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- winnie (0.0.6)
5
- json
6
- rest-client
7
-
8
- GEM
9
- remote: http://rubygems.org/
10
- specs:
11
- ZenTest (4.5.0)
12
- diff-lcs (1.1.2)
13
- fakefs (0.2.1)
14
- json (1.5.1)
15
- mime-types (1.16)
16
- rest-client (1.6.1)
17
- mime-types (>= 1.16)
18
- rspec (2.2.0)
19
- rspec-core (~> 2.2)
20
- rspec-expectations (~> 2.2)
21
- rspec-mocks (~> 2.2)
22
- rspec-core (2.2.1)
23
- rspec-expectations (2.2.0)
24
- diff-lcs (~> 1.1.2)
25
- rspec-mocks (2.2.0)
26
-
27
- PLATFORMS
28
- ruby
29
-
30
- DEPENDENCIES
31
- ZenTest
32
- fakefs
33
- rspec (~> 2.2.0)
34
- winnie!