gemfeed 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Aubrey Holland
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.
data/README.rdoc ADDED
@@ -0,0 +1,18 @@
1
+ = gemfeed
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but
13
+ bump version in a commit by itself I can ignore when I pull)
14
+ * Send me a pull request. Bonus points for topic branches.
15
+
16
+ == Copyright
17
+
18
+ Copyright (c) 2009 Aubrey Holland. See LICENSE for details.
data/lib/gemfeed.rb ADDED
@@ -0,0 +1,99 @@
1
+ module Gemfeed
2
+
3
+ GEMFEED_URL = 'http://gemfeed.com'
4
+
5
+ class GemfeedLoginError < StandardError; end;
6
+
7
+ def self.subscribe_to_gem(gem_name)
8
+ check_gemfeed_login
9
+ url = URI.join(GEMFEED_URL, 'subscriptions.xml')
10
+ req = prepare_request(:post, url)
11
+ req.body = "<package name=\"#{gem_name}\"/>"
12
+
13
+ make_request(url, req, gem_name) do |body|
14
+ puts "!!! Gemfeed has subscribed you to #{gem_name}"
15
+ end
16
+ end
17
+
18
+ def self.unsubscribe_from_gem(gem_name)
19
+ check_gemfeed_login
20
+ url = URI.join(GEMFEED_URL, get_subscription_url(gem_name))
21
+ req = prepare_request(:delete, url)
22
+
23
+ make_request(url, req, gem_name) do |body|
24
+ puts "!!! Gemfeed has unsubscribed you from #{gem_name}"
25
+ end
26
+ end
27
+
28
+ def self.check_gemfeed_login
29
+ unless Gem.configuration['gemfeed_login']
30
+ puts '!!! You gemfeed login is not configured correctly. Please add a line like:'
31
+ puts '!!! gemfeed_login: aubreyholland@gmail.com'
32
+ puts '!!! to your ~/.gemrc file. If you have a password with gemfeed, you should also add a line like:'
33
+ puts '!!! gemfeed_password: super_secret'
34
+ puts '!!! If you just want to stop receiving this message, remove the gemfeed gem:'
35
+ puts '!!! gem uninstall gemfeed'
36
+ raise GemfeedLoginError.new
37
+ end
38
+ end
39
+
40
+ def self.print_unauthorized_error
41
+ puts '!!! Unable to log in to gemfeed with the given login and password. Check your'
42
+ puts '!!! ~/.gemrc file and make sure that gemfeed_login and gemfeed_password are'
43
+ puts '!!! configured correctly, like:'
44
+ puts '!!! gemfeed_login: aubreyholland@gmail.com'
45
+ puts '!!! gemfeed_password: super_secret'
46
+ puts '!!! If you just want to stop receiving this message, remove the gemfeed gem:'
47
+ puts '!!! gem uninstall gemfeed'
48
+ raise GemfeedLoginError.new
49
+ end
50
+
51
+ def self.prepare_request(type, url)
52
+ case type
53
+ when :post then req = Net::HTTP::Post.new(url.path)
54
+ when :get then req = Net::HTTP::Get.new(url.path)
55
+ when :delete then req = Net::HTTP::Delete.new(url.path)
56
+ when :put then req = Net::HTTP::Put.new(url.path)
57
+ end
58
+ req.basic_auth Gem.configuration['gemfeed_login'], Gem.configuration['gemfeed_password']
59
+ req['Content-Type'] = 'text/xml'
60
+ req
61
+ end
62
+
63
+ def self.make_request(url, req, gem_name, &block)
64
+ begin
65
+ res = Net::HTTP.new(url.host, url.port).start { |http| http.request(req) }
66
+ case res
67
+ when Net::HTTPSuccess
68
+ block.call(res.body)
69
+ when Net::HTTPUnauthorized:
70
+ print_unauthorized_error
71
+ when Net::HTTPClientError:
72
+ doc = REXML::Document.new(res.body)
73
+ doc.elements.each('errors/error') do |error|
74
+ if error.text == 'User has already been taken'
75
+ puts "!!! You are already subscribed to #{gem_name} on gemfeed."
76
+ elsif error.text == 'Package can\'t be blank'
77
+ puts "!!! Gemfeed cannot find the gem #{gem_name}"
78
+ end
79
+ end
80
+ else
81
+ puts '!!! There was a server error while subscribing you to this gem on gemfeed.'
82
+ end
83
+ rescue Errno::ECONNREFUSED
84
+ puts '!!! There was an error when connecting to the server.'
85
+ end
86
+ end
87
+
88
+ def self.get_subscription_url(name)
89
+ url = URI.join(GEMFEED_URL, 'subscriptions.xml')
90
+ req = prepare_request(:get, url)
91
+
92
+ make_request(url, req, name) do |body|
93
+ doc = REXML::Document.new(body)
94
+ doc.elements.each('subscriptions/subscription') do |subscription|
95
+ return subscription.elements['path'].text if subscription.elements['package/name']
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,24 @@
1
+ require 'rubygems/command'
2
+ require 'gemfeed'
3
+
4
+ class Gem::Commands::GemfeedCommand < Gem::Command
5
+
6
+ def initialize
7
+ super 'gemfeed', 'Export subscribed gems to your gemfeed account'
8
+ end
9
+
10
+ def execute
11
+ begin
12
+ Gemfeed.check_gemfeed_login
13
+ gem_names = Gem.source_index.gems.collect { |k,v| v.name }.uniq.sort
14
+ say "Subscribing you to #{gem_names.size} gems on gemfeed..."
15
+ gem_names.each do |name|
16
+ say "Subscribing to #{name}"
17
+ Gemfeed.subscribe_to_gem(name)
18
+ end
19
+ rescue
20
+ exit()
21
+ end
22
+ end
23
+ end
24
+
@@ -0,0 +1,32 @@
1
+ require 'gemfeed'
2
+ require 'net/http'
3
+ require 'rubygems/command_manager'
4
+ require 'uri'
5
+ require 'rexml/document'
6
+
7
+ require 'ruby-debug'
8
+
9
+ Gem::CommandManager.instance.register_command :gemfeed
10
+
11
+ Gem.post_install do |installer|
12
+ begin
13
+ unless installer.spec.name == 'gemfeed'
14
+ Gemfeed.subscribe_to_gem(installer.spec.name)
15
+ end
16
+ rescue Exception => e
17
+ # just trying to make absolutely sure that we can't block
18
+ # the gem installation at the moment.
19
+ end
20
+ end
21
+
22
+ Gem.post_uninstall do |uninstaller|
23
+ begin
24
+ unless uninstaller.spec.name == 'gemfeed'
25
+ Gemfeed.unsubscribe_from_gem(uninstaller.spec.name)
26
+ end
27
+ rescue Exception => e
28
+ # just trying to make absolutely sure that we can't block
29
+ # the gem installation at the moment.
30
+ end
31
+ end
32
+
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Gemfeed" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'gemfeed'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gemfeed
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Aubrey Holland
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-13 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: This gem provides automatic post install and uninstall hooks to allow you to subscribe to gems with gemfeed. It also provides a command that allows you to automatically install to all gems that are currently installed.
26
+ email: aubreyholland@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - lib/gemfeed.rb
36
+ - lib/rubygems/commands/gemfeed_command.rb
37
+ - lib/rubygems_plugin.rb
38
+ - LICENSE
39
+ - README.rdoc
40
+ has_rdoc: true
41
+ homepage: http://github.com/aub/gemfeed
42
+ licenses: []
43
+
44
+ post_install_message: |
45
+ **************************************************
46
+
47
+ The gemfeed gem is now installed. You need to configure it by
48
+ editing your ~/.gemrc file and adding lines like:
49
+
50
+ gemfeed_login: {your gemfeed login}
51
+ gemfeed_password: {your gemfeed password, if you have one}
52
+
53
+ Now, you can use "gem gemfeed" to subscribe to all existing gems, and
54
+ subscriptions will automatically be created and removed as gems are
55
+ installed and removed.
56
+
57
+ **************************************************
58
+
59
+ rdoc_options:
60
+ - --charset=UTF-8
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ version:
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
75
+ requirements: []
76
+
77
+ rubyforge_project: gemfeed
78
+ rubygems_version: 1.3.3
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: A gem for managing gemfeed subscriptions
82
+ test_files:
83
+ - spec/gemfeed_spec.rb
84
+ - spec/spec_helper.rb