gemcutter 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,5 +13,3 @@ class Gem::Commands::DowngradeCommand < Gem::Command
13
13
  Gem.configuration.write
14
14
  end
15
15
  end
16
-
17
- Gem::CommandManager.instance.register_command :downgrade
data/lib/commands/push.rb CHANGED
@@ -1,8 +1,6 @@
1
- require 'yaml'
2
1
  require 'net/http'
3
2
 
4
3
  class Gem::Commands::PushCommand < Gem::Command
5
-
6
4
  def description
7
5
  'Push a gem up to Gemcutter'
8
6
  end
@@ -20,6 +18,21 @@ class Gem::Commands::PushCommand < Gem::Command
20
18
  end
21
19
 
22
20
  def execute
21
+ sign_in unless api_key
22
+ send_gem
23
+ end
24
+
25
+ def ask_for_password(message)
26
+ password = ui.ask_for_password(message)
27
+ ui.say("\n")
28
+ password
29
+ end
30
+
31
+ def api_key
32
+ Gem.configuration[:gemcutter_key]
33
+ end
34
+
35
+ def send_gem
23
36
  say "Pushing gem to Gemcutter..."
24
37
 
25
38
  name = get_one_gem_name
@@ -29,11 +42,42 @@ class Gem::Commands::PushCommand < Gem::Command
29
42
  request = Net::HTTP::Post.new(url.path)
30
43
  request.body = File.open(name).read
31
44
  request.content_length = request.body.size
32
- request.initialize_http_header("HTTP_AUTHORIZATION" => Gem.configuration[:gemcutter_key])
45
+ request.initialize_http_header("HTTP_AUTHORIZATION" => api_key)
33
46
 
34
47
  response = Net::HTTP.new(url.host, url.port).start { |http| http.request(request) }
35
48
  say response.body
36
49
  end
50
+
51
+ def sign_in
52
+ say "Enter your Gemcutter credentials. Don't have an account yet? Create one at #{URL}/sign_up"
53
+
54
+ email = ask("Email: ")
55
+ password = ask_for_password("Password: ")
56
+
57
+ site = ENV['TEST'] ? "local" : "org"
58
+ url = URI.parse("http://gemcutter.#{site}/api_key")
59
+
60
+ request = Net::HTTP::Get.new(url.path)
61
+ request.basic_auth email, password
62
+ response = Net::HTTP.new(url.host, url.port).start { |http| http.request(request) }
63
+
64
+ case response
65
+ when Net::HTTPSuccess
66
+ Gem.configuration[:gemcutter_key] = response.body
67
+ Gem.configuration.write
68
+ say "Signed in. Your api key has been stored in ~/.gemrc"
69
+ else
70
+ say response.body
71
+ terminate_interaction
72
+ end
73
+ end
37
74
  end
38
75
 
39
- Gem::CommandManager.instance.register_command :push
76
+ class Gem::StreamUI
77
+ def ask_for_password(message)
78
+ system "stty -echo"
79
+ password = ask(message)
80
+ system "stty echo"
81
+ password
82
+ end
83
+ end
@@ -1,62 +1,19 @@
1
- class Gem::StreamUI
2
- def ask_for_password(message)
3
- system "stty -echo"
4
- password = ask(message)
5
- system "stty echo"
6
- password
7
- end
8
- end
9
-
10
1
  class Gem::Commands::UpgradeCommand < Gem::Command
11
2
  def description
12
3
  'Upgrade your gem source to Gemcutter'
13
4
  end
14
5
 
15
- def ask_for_password(message)
16
- ui.ask_for_password(message)
17
- end
18
-
19
6
  def initialize
20
7
  super 'upgrade', description
21
8
  end
22
9
 
23
10
  def execute
24
- add_source
25
- sign_in
26
- end
27
-
28
- def add_source
29
11
  if Gem.sources.include?(URL)
30
12
  say "Gemcutter is already your primary gem source. Please use `gem downgrade` if you wish to no longer use Gemcutter."
31
13
  else
32
- say "Upgrading your primary gem source to gemcutter.org"
33
14
  Gem.sources.unshift URL
34
15
  Gem.configuration.write
16
+ say "Your primary gem source is now gemcutter.org"
35
17
  end
36
18
  end
37
-
38
- def sign_in
39
- say "Enter your Gemcutter credentials. Don't have an account yet? Create one at #{URL}/sign_up"
40
-
41
- email = ask("Email: ")
42
- password = ask_for_password("Password: ")
43
-
44
- site = ENV['TEST'] ? "local" : "org"
45
- url = URI.parse("http://gemcutter.#{site}/api_key")
46
-
47
- request = Net::HTTP::Get.new(url.path)
48
- request.basic_auth email, password
49
- response = Net::HTTP.new(url.host, url.port).start { |http| http.request(request) }
50
-
51
- case response
52
- when Net::HTTPSuccess
53
- Gem.configuration[:gemcutter_key] = response.body
54
- Gem.configuration.write
55
- else
56
- say response.body
57
- end
58
- end
59
-
60
19
  end
61
-
62
- Gem::CommandManager.instance.register_command :upgrade
@@ -4,4 +4,8 @@ require 'commands/downgrade'
4
4
  require 'commands/push'
5
5
  require 'commands/upgrade'
6
6
 
7
+ Gem::CommandManager.instance.register_command :downgrade
8
+ Gem::CommandManager.instance.register_command :push
9
+ Gem::CommandManager.instance.register_command :upgrade
10
+
7
11
  URL = "http://gemcutter.org" unless defined?(URL)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemcutter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Quaranto
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-13 00:00:00 -04:00
12
+ date: 2009-06-15 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -54,6 +54,6 @@ rubyforge_project: gemcutter
54
54
  rubygems_version: 1.3.4
55
55
  signing_key:
56
56
  specification_version: 3
57
- summary: Kickass gem hosting
57
+ summary: Awesome gem hosting
58
58
  test_files: []
59
59