gemwhois 0.1

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.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 John Nunemaker
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,35 @@
1
+ = gemwhois
2
+
3
+ Whois for gems, because gem names are like domains in the 90's
4
+
5
+ == Install
6
+
7
+ gem install gemwhois
8
+
9
+ == Usage
10
+
11
+ $ gem whois httparty
12
+
13
+ gem name: httparty
14
+ owners: John Nunemaker, Sandro Turriate
15
+ info: Makes http fun! Also, makes consuming restful web services dead easy.
16
+ version: 0.5.2
17
+ downloads: 40714
18
+
19
+ $ gem whois somenonexistantgem
20
+
21
+ Gem not found. It will be mine. Oh yes. It will be mine. *sinister laugh*
22
+
23
+ == Note on Patches/Pull Requests
24
+
25
+ * Fork the project.
26
+ * Make your feature addition or bug fix.
27
+ * Add tests for it. This is important so I don't break it in a
28
+ future version unintentionally.
29
+ * Commit, do not mess with rakefile, version, or history.
30
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
31
+ * Send me a pull request. Bonus points for topic branches.
32
+
33
+ == Copyright
34
+
35
+ Copyright (c) 2010 John Nunemaker. See LICENSE for details.
@@ -0,0 +1,35 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'jeweler'
4
+ require File.dirname(__FILE__) + '/lib/gemwhois/version'
5
+
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = 'gemwhois'
8
+ gem.summary = "whois for gems, because gem names are like domains in the 90's"
9
+ gem.description = "whois for gems, because gem names are like domains in the 90's"
10
+ gem.email = 'nunemaker@gmail.com'
11
+ gem.homepage = 'http://github.com/jnunemaker/gemwhois'
12
+ gem.authors = ["John Nunemaker"]
13
+ gem.version = Gemwhois::Version
14
+ gem.files = FileList['lib/**/*.rb', 'bin/*', '[A-Z]*', 'test/**/*'].to_a
15
+
16
+ gem.add_dependency 'crack'
17
+ gem.add_dependency 'unindent'
18
+
19
+ gem.add_development_dependency 'shoulda'
20
+ gem.add_development_dependency 'jeweler'
21
+ gem.add_development_dependency 'fakeweb'
22
+ gem.add_development_dependency 'mocha'
23
+ end
24
+ Jeweler::GemcutterTasks.new
25
+
26
+ require 'rake/testtask'
27
+ Rake::TestTask.new(:test) do |test|
28
+ test.libs << 'lib' << 'test'
29
+ test.ruby_opts << '-rubygems'
30
+ test.pattern = 'test/**/test_*.rb'
31
+ test.verbose = true
32
+ end
33
+
34
+ task :test => :check_dependencies
35
+ task :default => :test
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'rubygems/command_manager'
3
+ require 'rubygems/commands/whois'
4
+ require 'crack'
5
+ require 'unindent'
6
+
7
+ Gem::CommandManager.instance.register_command(:whois)
@@ -0,0 +1,3 @@
1
+ module Gemwhois
2
+ Version = '0.1'
3
+ end
@@ -0,0 +1,57 @@
1
+ require 'rubygems/gemcutter_utilities'
2
+
3
+ class Gem::Commands::WhoisCommand < Gem::Command
4
+ include Gem::GemcutterUtilities
5
+
6
+ def description
7
+ 'Perform a whois lookup based on a gem name so you can see if it is available or not'
8
+ end
9
+
10
+ def arguments
11
+ "GEM name of gem"
12
+ end
13
+
14
+ def usage
15
+ "#{program_name} GEM"
16
+ end
17
+
18
+ def initialize
19
+ super 'whois', description
20
+ end
21
+
22
+ def execute
23
+ whois get_one_gem_name
24
+ end
25
+
26
+ def whois(gem_name)
27
+ response = rubygems_api_request(:get, "api/v1/gems/#{gem_name}.json") do |request|
28
+ request.set_form_data("gem_name" => gem_name)
29
+ end
30
+
31
+ with_response(response) do |resp|
32
+ json = Crack::JSON.parse(resp.body)
33
+ puts <<-STR.unindent
34
+
35
+ gem name: #{json['name']}
36
+ owners: #{json['authors']}
37
+ info: #{json['info']}
38
+ version: #{json['version']}
39
+ downloads: #{json['downloads']}
40
+
41
+ STR
42
+ end
43
+ end
44
+
45
+ def with_response(resp)
46
+ case resp
47
+ when Net::HTTPSuccess
48
+ block_given? ? yield(resp) : say(resp.body)
49
+ else
50
+ if resp.body == 'This rubygem could not be found.'
51
+ puts '','Gem not found. It will be mine. Oh yes. It will be mine. *sinister laugh*',''
52
+ else
53
+ say resp.body
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,3 @@
1
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.3.6')
2
+ require File.join(File.dirname(__FILE__), 'gemwhois')
3
+ end
@@ -0,0 +1 @@
1
+ {"dependencies":{"runtime":[{"name":"crack","requirements":"= 0.1.6"}],"development":[{"name":"rspec","requirements":"= 1.2.9"},{"name":"mongrel","requirements":"~> 1.1"},{"name":"fakeweb","requirements":"~> 1.2"},{"name":"cucumber","requirements":"~> 0.4"},{"name":"activesupport","requirements":"~> 2.3"}]},"name":"httparty","downloads":40707,"info":"Makes http fun! Also, makes consuming restful web services dead easy.","version_downloads":12964,"version":"0.5.2","gem_uri":"http://rubygems.org/gems/httparty-0.5.2.gem","project_uri":"http://rubygems.org/gems/httparty","authors":"John Nunemaker, Sandro Turriate"}
@@ -0,0 +1 @@
1
+ This rubygem could not be found.
@@ -0,0 +1,24 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'fakeweb'
5
+ require 'mocha'
6
+ require 'helpers/output'
7
+
8
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
9
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
10
+ require 'gemwhois'
11
+
12
+ FakeWeb.allow_net_connect = false
13
+
14
+ class Test::Unit::TestCase
15
+ include Helpers::Output
16
+
17
+ def stub_gem(gem_name, options={})
18
+ FakeWeb.register_uri(:get, "https://rubygems.org/api/v1/gems/#{gem_name}.json", options.merge(:body => fixture_file(gem_name)))
19
+ end
20
+
21
+ def fixture_file(gem_name)
22
+ File.read(File.join(File.dirname(__FILE__), 'fixtures', "#{gem_name}.json"))
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ module Helpers
2
+ module Output
3
+ def assert_output(expected, &block)
4
+ keep_stdout do |stdout|
5
+ block.call
6
+ if expected.is_a?(Regexp)
7
+ assert_match expected, stdout.string
8
+ else
9
+ assert_equal expected.to_s, stdout.string
10
+ end
11
+ end
12
+ end
13
+
14
+ def keep_stdout(&block)
15
+ begin
16
+ orig_stream, $stdout = $stdout, StringIO.new
17
+ block.call($stdout)
18
+ ensure
19
+ s, $stdout = $stdout.string, orig_stream
20
+ s
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,43 @@
1
+ require 'helper'
2
+
3
+ class TestGemwhois < Test::Unit::TestCase
4
+ context 'Whois for found gem' do
5
+ setup do
6
+ @gem = 'httparty'
7
+ stub_gem(@gem)
8
+ @command = Gem::Commands::WhoisCommand.new
9
+ @command.handle_options([@gem])
10
+ end
11
+
12
+ should "work" do
13
+ output = <<-STR.unindent
14
+
15
+ gem name: httparty
16
+ owners: John Nunemaker, Sandro Turriate
17
+ info: Makes http fun! Also, makes consuming restful web services dead easy.
18
+ version: 0.5.2
19
+ downloads: 40707
20
+
21
+ STR
22
+ assert_output(output) { @command.execute }
23
+ end
24
+ end
25
+
26
+ context "Whois for missing gem" do
27
+ setup do
28
+ @gem = 'missing'
29
+ stub_gem(@gem, :status => ["404", "Not Found"])
30
+ @command = Gem::Commands::WhoisCommand.new
31
+ @command.handle_options([@gem])
32
+ end
33
+
34
+ should "work" do
35
+ output = <<-STR.unindent
36
+
37
+ Gem not found. It will be mine. Oh yes. It will be mine. *sinister laugh*
38
+
39
+ STR
40
+ assert_output(output) { @command.execute }
41
+ end
42
+ end
43
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gemwhois
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ version: "0.1"
9
+ platform: ruby
10
+ authors:
11
+ - John Nunemaker
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2010-03-30 00:00:00 -04:00
17
+ default_executable:
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: crack
21
+ prerelease: false
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ segments:
27
+ - 0
28
+ version: "0"
29
+ type: :runtime
30
+ version_requirements: *id001
31
+ - !ruby/object:Gem::Dependency
32
+ name: unindent
33
+ prerelease: false
34
+ requirement: &id002 !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ segments:
39
+ - 0
40
+ version: "0"
41
+ type: :runtime
42
+ version_requirements: *id002
43
+ - !ruby/object:Gem::Dependency
44
+ name: shoulda
45
+ prerelease: false
46
+ requirement: &id003 !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ segments:
51
+ - 0
52
+ version: "0"
53
+ type: :development
54
+ version_requirements: *id003
55
+ - !ruby/object:Gem::Dependency
56
+ name: jeweler
57
+ prerelease: false
58
+ requirement: &id004 !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ type: :development
66
+ version_requirements: *id004
67
+ - !ruby/object:Gem::Dependency
68
+ name: fakeweb
69
+ prerelease: false
70
+ requirement: &id005 !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ type: :development
78
+ version_requirements: *id005
79
+ - !ruby/object:Gem::Dependency
80
+ name: mocha
81
+ prerelease: false
82
+ requirement: &id006 !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ type: :development
90
+ version_requirements: *id006
91
+ description: whois for gems, because gem names are like domains in the 90's
92
+ email: nunemaker@gmail.com
93
+ executables: []
94
+
95
+ extensions: []
96
+
97
+ extra_rdoc_files:
98
+ - LICENSE
99
+ - README.rdoc
100
+ files:
101
+ - LICENSE
102
+ - README.rdoc
103
+ - Rakefile
104
+ - lib/gemwhois.rb
105
+ - lib/gemwhois/version.rb
106
+ - lib/rubygems/commands/whois.rb
107
+ - lib/rubygems_plugin.rb
108
+ - test/fixtures/httparty.json
109
+ - test/fixtures/missing.json
110
+ - test/helper.rb
111
+ - test/helpers/output.rb
112
+ - test/test_gemwhois.rb
113
+ has_rdoc: true
114
+ homepage: http://github.com/jnunemaker/gemwhois
115
+ licenses: []
116
+
117
+ post_install_message:
118
+ rdoc_options:
119
+ - --charset=UTF-8
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ segments:
127
+ - 0
128
+ version: "0"
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ segments:
134
+ - 0
135
+ version: "0"
136
+ requirements: []
137
+
138
+ rubyforge_project:
139
+ rubygems_version: 1.3.6
140
+ signing_key:
141
+ specification_version: 3
142
+ summary: whois for gems, because gem names are like domains in the 90's
143
+ test_files:
144
+ - test/helper.rb
145
+ - test/helpers/output.rb
146
+ - test/test_gemwhois.rb