gemcutter 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,8 @@
1
+ require 'rubygems/local_remote_options'
2
+
1
3
  class Gem::AbstractCommand < Gem::Command
4
+ include Gem::LocalRemoteOptions
5
+
2
6
  def api_key
3
7
  Gem.configuration[:gemcutter_key]
4
8
  end
@@ -22,14 +26,9 @@ class Gem::AbstractCommand < Gem::Command
22
26
  email = ask("Email: ")
23
27
  password = ask_for_password("Password: ")
24
28
 
25
- url = URI.parse("#{gemcutter_url}/api_key")
26
-
27
- http = Net::HTTP.new(url.host, url.port)
28
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
29
- http.use_ssl = (url.scheme == 'https')
30
- request = Net::HTTP::Get.new(url.path)
31
- request.basic_auth email, password
32
- response = http.request(request)
29
+ response = make_request(:get, "api_key") do |request|
30
+ request.basic_auth email, password
31
+ end
33
32
 
34
33
  case response
35
34
  when Net::HTTPSuccess
@@ -42,6 +41,36 @@ class Gem::AbstractCommand < Gem::Command
42
41
  end
43
42
  end
44
43
 
44
+ def make_request(method, path)
45
+ require 'net/http'
46
+ require 'net/https'
47
+
48
+ url = URI.parse("#{gemcutter_url}/#{path}")
49
+
50
+ http = proxy_class.new(url.host, url.port)
51
+
52
+ if url.scheme == 'https'
53
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
54
+ http.use_ssl = true
55
+ end
56
+
57
+ request_method =
58
+ case method
59
+ when :get
60
+ proxy_class::Get
61
+ when :post
62
+ proxy_class::Post
63
+ when :put
64
+ proxy_class::Put
65
+ else
66
+ raise ArgumentError
67
+ end
68
+
69
+ request = request_method.new(url.path)
70
+ yield request if block_given?
71
+ http.request(request)
72
+ end
73
+
45
74
  def use_proxy!
46
75
  proxy_uri = http_proxy
47
76
  @proxy_class = Net::HTTP::Proxy(proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password)
@@ -1,8 +1,3 @@
1
- require 'open-uri'
2
- require 'net/scp'
3
- require 'json'
4
- require 'tempfile'
5
-
6
1
  class Gem::Commands::MigrateCommand < Gem::AbstractCommand
7
2
  attr_reader :rubygem
8
3
 
@@ -27,30 +22,31 @@ class Gem::Commands::MigrateCommand < Gem::AbstractCommand
27
22
  end
28
23
 
29
24
  def find(name)
30
- begin
31
- data = open("#{gemcutter_url}/gems/#{name}.json")
32
- @rubygem = JSON.parse(data.string)
33
- rescue OpenURI::HTTPError
25
+ require 'json'
26
+
27
+ response = make_request(:get, "gems/#{name}.json")
28
+
29
+ case response
30
+ when Net::HTTPSuccess
31
+ begin
32
+ @rubygem = JSON.parse(response.body)
33
+ rescue JSON::ParserError => json_error
34
+ say "There was a problem parsing the data: #{json_error}"
35
+ terminate_interaction
36
+ end
37
+ else
34
38
  say "This gem is currently not hosted on Gemcutter."
35
39
  terminate_interaction
36
- rescue JSON::ParserError => json_error
37
- say "There was a problem parsing the data: #{json_error}"
38
- terminate_interaction
39
40
  end
40
41
  end
41
42
 
42
43
  def get_token
43
44
  say "Starting migration of #{rubygem["name"]} from RubyForge..."
44
45
 
45
- url = URI.parse("#{gemcutter_url}/gems/#{rubygem["slug"]}/migrate")
46
-
47
- http = proxy_class.new(url.host, url.port)
48
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
49
- http.use_ssl = (url.scheme == 'https')
50
- request = proxy_class::Post.new(url.path)
51
- request.add_field("Content-Length", 0)
52
- request.add_field("Authorization", api_key)
53
- response = http.request(request)
46
+ response = make_request(:post, "gems/#{rubygem["slug"]}/migrate") do |request|
47
+ request.add_field("Content-Length", 0)
48
+ request.add_field("Authorization", api_key)
49
+ end
54
50
 
55
51
  case response
56
52
  when Net::HTTPSuccess
@@ -63,6 +59,9 @@ class Gem::Commands::MigrateCommand < Gem::AbstractCommand
63
59
  end
64
60
 
65
61
  def upload_token(token)
62
+ require 'tempfile'
63
+ require 'net/scp'
64
+
66
65
  url = "#{self.rubygem['rubyforge_project']}.rubyforge.org"
67
66
  say "Uploading the migration token to #{url}. Please enter your RubyForge login:"
68
67
  login = ask("Login: ")
@@ -84,15 +83,11 @@ class Gem::Commands::MigrateCommand < Gem::AbstractCommand
84
83
 
85
84
  def check_for_approved
86
85
  say "Asking Gemcutter to verify the upload..."
87
- url = URI.parse("#{gemcutter_url}/gems/#{rubygem["slug"]}/migrate")
88
-
89
- http = proxy_class.new(url.host, url.port)
90
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
91
- http.use_ssl = (url.scheme == 'https')
92
- request = proxy_class::Put.new(url.path)
93
- request.add_field("Content-Length", 0)
94
- request.add_field("Authorization", api_key)
95
- response = http.request(request)
86
+
87
+ response = make_request(:put, "gems/#{rubygem["slug"]}/migrate") do |request|
88
+ request.add_field("Content-Length", 0)
89
+ request.add_field("Authorization", api_key)
90
+ end
96
91
 
97
92
  say response.body
98
93
  end
data/lib/commands/push.rb CHANGED
@@ -1,11 +1,5 @@
1
- require 'net/http'
2
- require 'net/https'
3
- require 'rubygems/local_remote_options'
4
-
5
1
  class Gem::Commands::PushCommand < Gem::AbstractCommand
6
2
 
7
- include Gem::LocalRemoteOptions
8
-
9
3
  def description
10
4
  'Push a gem up to Gemcutter'
11
5
  end
@@ -32,17 +26,11 @@ class Gem::Commands::PushCommand < Gem::AbstractCommand
32
26
  say "Pushing gem to Gemcutter..."
33
27
 
34
28
  name = get_one_gem_name
35
- url = URI.parse("#{gemcutter_url}/gems")
36
-
37
- http = proxy_class.new(url.host, url.port)
38
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
39
- http.use_ssl = (url.scheme == 'https')
40
- request = proxy_class::Post.new(url.path)
41
- request.body = File.open(name).read
42
- request.add_field("Content-Length", request.body.size)
43
- request.add_field("Authorization", api_key)
44
-
45
- response = http.request(request)
29
+ response = make_request(:post, "gems") do |request|
30
+ request.body = File.open(name).read
31
+ request.add_field("Content-Length", request.body.size)
32
+ request.add_field("Authorization", api_key)
33
+ end
46
34
 
47
35
  say response.body
48
36
  end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../command_helper'
1
+ require File.dirname(__FILE__) + '/../command_helper'
2
2
 
3
3
  class Gem::Commands::FakeCommand < Gem::AbstractCommand
4
4
  def description
@@ -1,4 +1,5 @@
1
- require File.dirname(__FILE__) + '/../../command_helper'
1
+ require File.dirname(__FILE__) + '/../command_helper'
2
+ require 'net/scp'
2
3
 
3
4
  class MigrateCommandTest < CommandTest
4
5
  context "executing the command" do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../command_helper'
1
+ require File.dirname(__FILE__) + '/../command_helper'
2
2
 
3
3
  class PushCommandTest < CommandTest
4
4
  context "pushing" do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../command_helper'
1
+ require File.dirname(__FILE__) + '/../command_helper'
2
2
 
3
3
  class TumbleCommandTest < CommandTest
4
4
  context "with a tumbler and some sources" do
@@ -9,9 +9,9 @@ class TumbleCommandTest < CommandTest
9
9
  end
10
10
 
11
11
  should "show sources" do
12
- mock(@command).puts("Your gem sources are now:")
13
- mock(@command).puts("- #{@sources.first}")
14
- mock(@command).puts("- #{URL}")
12
+ mock(@command).say("Your gem sources are now:")
13
+ mock(@command).say("- #{@sources.first}")
14
+ mock(@command).say("- #{URL}")
15
15
  @command.show_sources
16
16
  end
17
17
  end
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.7
4
+ version: 0.0.8
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-08-10 00:00:00 -04:00
12
+ date: 2009-08-11 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -22,6 +22,16 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: "0"
24
24
  version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: net-scp
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
25
35
  description:
26
36
  email: nick@quaran.to
27
37
  executables: []
@@ -77,7 +87,7 @@ specification_version: 3
77
87
  summary: Awesome gem hosting
78
88
  test_files:
79
89
  - test/command_helper.rb
80
- - test/unit/commands/migrate_command_test.rb
81
- - test/unit/commands/tumble_command_test.rb
82
- - test/unit/commands/push_command_test.rb
83
- - test/unit/commands/abstract_command_test.rb
90
+ - test/commands/migrate_command_test.rb
91
+ - test/commands/tumble_command_test.rb
92
+ - test/commands/push_command_test.rb
93
+ - test/commands/abstract_command_test.rb