ba-webby-pingback 1.0

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/README.textile ADDED
@@ -0,0 +1,75 @@
1
+ h2. Why and what?
2
+
3
+ I like webby and the idea of having a blog with static pages, not that I ever think I need the speed of it but I at least save some RAM on a daily basis. :)
4
+
5
+ So this gem can send pingbacks and also receive pingbacks through "Disqus":http://www.disqus.com. What we're actually doing when receiving is just validating it as a "pingback":http://en.wikipedia.org/wiki/Pingback and then send a "trackback":http://en.wikipedia.org/wiki/Trackback to the Disqus page for the post.
6
+
7
+ h2. Usage
8
+
9
+ Make sure that all your posts that you want to be able to ping
10
+ other sites have a meta-data key that is called _trackback_done_ and
11
+ set it to false. When the ping has been done, successful or otherwise,
12
+ it will be set to true. Eg:
13
+
14
+ <pre>
15
+ <code>
16
+ ---
17
+ title: a spiffy blogpost
18
+ trackback_done: false
19
+ ---
20
+ </code>
21
+ </pre>
22
+
23
+ Write your posts, deploy and then run:
24
+
25
+ @webby pingback:ping@
26
+
27
+ *Note:* _You've to deploy because of how the pingback protocol works._
28
+
29
+ h2. Installation
30
+
31
+ Install it through rubygems:
32
+
33
+ @gem install ba-webby-pingback --source gems.github.com@
34
+
35
+ h3. Installing the sender
36
+
37
+ Now you've to install the rake tasks. Do this by either copying the
38
+ pingback.rake file from the gem installation directory or create a new
39
+ file with this content:
40
+
41
+ @require 'webby-pingback-rake'@
42
+
43
+ h3. Installing the receiver
44
+
45
+ To receive pingbacks you've to run a script that can act as a XML-RPC server, I've written a CGI-script using Rubys built-in XML-RPC package (which also can run it as a standalone server or WEBrick servlet), which can be used with a CGI-script that looks like this: (a copy exists in the _ext_ folder)
46
+
47
+ <pre>
48
+ <code>
49
+ #!/usr/bin/env ruby
50
+ # -*- coding: utf-8 -*-
51
+ $KCODE = 'u'
52
+
53
+ module Pingback
54
+ Conf = {
55
+ :db => 'path-to-sqlite-datbase-that-is-writable-by-server'
56
+ :forum_api_key => 'long string from disqus, use rake task to get'
57
+ }
58
+ end
59
+
60
+ require 'rubygems'
61
+ require 'webby-pingback-xmlrpc.cgi'
62
+ </code>
63
+ </pre>
64
+
65
+ *Note*: _The pingback database, a sqlite database, has to be writable by the server running the cgi-script._
66
+
67
+ To get the Disqus forum api key you can use a rake-task that is included in the rakefale for this gem. Just run:
68
+
69
+ @webby pingback:fetch_disqus_forum_key@
70
+
71
+ The user key you can get at http://disqus.com/api/get_my_key/ when you're logged in.
72
+
73
+ When the CGI-script is setup and is working you only have to add a @<link>@ tag to your blogposts that points to the CGI-script and we're done:
74
+
75
+ @<link rel="pingback" href="http://example.com/cgi-bin/pingback-xmlrpc.cgi.rb" />@
data/ext/pingback.cgi ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ $KCODE = 'u'
4
+
5
+ module Pingback
6
+ Conf = {
7
+ :db => 'path-to-sqlite-datbase-that-is-writable-by-server'
8
+ :forum_api_key => 'long string from disqus, use raketasks to get'
9
+ }
10
+ end
11
+
12
+ require 'rubygems'
13
+ require 'webby-pingback-xmlrpc.cgi'
@@ -0,0 +1,57 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'webby-pingback'
4
+
5
+ namespace :pingback do
6
+ desc 'Ping all links in all new blogposts which hasn\'t been processed'
7
+ task :ping do
8
+ Webby.load_files
9
+ db = Webby::Resources.pages.find(:all, :blog_post => true, :trackback_done => false)
10
+ db.each do |page|
11
+ doc = Hpricot(File.read(Webby.site.output_dir + page.url))
12
+ urls = (doc/'/html/body//a[@href]').inject([]) do |memo, a|
13
+ if a['href'] == ("#{Webby.site.base}/") or a['href'].match(/(disqus)|(webby.rubyforge.org)/)
14
+ memo
15
+ else
16
+ memo << a['href']
17
+ end
18
+ end.uniq # /doc
19
+
20
+ pinger = Pingback::Sender.new("#{Webby.site.base}#{page.url}", urls)
21
+ pinger.start
22
+ Pingback.toggle_trackback_done(page.path)
23
+ end
24
+ end
25
+
26
+ desc 'Fetches the Disqus forum key, needs the User API key'
27
+ task :fetch_disqus_forum_key do
28
+ require 'open-uri'
29
+ require 'json'
30
+ disqus_url = 'http://disqus.com/api/'
31
+
32
+ print 'Disqus user API key: '
33
+ user_key = STDIN.gets.strip
34
+
35
+ forum_list = JSON.parse(open("#{disqus_url}get_forum_list/?user_api_key=#{user_key}").read)
36
+ forum_id = if forum_list['message'].size > 2
37
+ puts 'Available shortnames:'
38
+ forum_list['message'].each_with_index {|x, i| puts "\t#{i + 1}) #{x['shortname']}" }
39
+
40
+ print 'Fetch shortname # '
41
+ num = STDIN.gets.strip
42
+ forum_list['message'][num.to_i - 1]['id']
43
+ else
44
+ forum_list['message'][0]['id']
45
+ end
46
+
47
+ if forum_id
48
+ forum_api_key = JSON.parse(open("#{disqus_url}get_forum_api_key/?user_api_key=#{user_key}&forum_id=#{forum_id}").read)
49
+ if forum_api_key['succeeded']
50
+ puts "Forum api key: #{forum_api_key['message']}"
51
+ else
52
+ STDERR.puts 'Unknown error:'
53
+ STDERR.puts forum_api_key.inspect
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,18 @@
1
+ # -*- coding: utf-8 -*-
2
+ Gem::Specification.new do |s|
3
+ s.name = "webby-pingback"
4
+ s.version = "1.0"
5
+ s.date = Time.now.strftime('%Y-%m-%d')
6
+ s.description = "Using Webby and some custom meta-data tags enable pingbacks to blogs and pages"
7
+ s.authors = ["Björn Andersson"]
8
+ s.email = "ba@sanitarium.se"
9
+ s.homepage = "http://github.com/ba/webby-pingback"
10
+ s.summary = s.description
11
+ s.require_path = 'lib'
12
+ s.has_rdoc = false
13
+ s.files = %w[README.textile tasks/pingback.rake webby-pingback.gemspec ext/pingback.cgi] +
14
+ Dir.glob('lib/*.rb')
15
+ s.add_dependency('amalgalite', '>= 0.10.2')
16
+ s.add_dependency('json', '>= 1.1.7')
17
+ s.add_dependency('hpricot', '>= 0.8.1')
18
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ba-webby-pingback
3
+ version: !ruby/object:Gem::Version
4
+ version: "1.0"
5
+ platform: ruby
6
+ authors:
7
+ - "Bj\xC3\xB6rn Andersson"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-15 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: amalgalite
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.10.2
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: json
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.7
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: hpricot
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.8.1
44
+ version:
45
+ description: Using Webby and some custom meta-data tags enable pingbacks to blogs and pages
46
+ email: ba@sanitarium.se
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ extra_rdoc_files: []
52
+
53
+ files:
54
+ - README.textile
55
+ - tasks/pingback.rake
56
+ - webby-pingback.gemspec
57
+ - ext/pingback.cgi
58
+ has_rdoc: false
59
+ homepage: http://github.com/ba/webby-pingback
60
+ licenses:
61
+ post_install_message:
62
+ rdoc_options: []
63
+
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "0"
71
+ version:
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: "0"
77
+ version:
78
+ requirements: []
79
+
80
+ rubyforge_project:
81
+ rubygems_version: 1.3.5
82
+ signing_key:
83
+ specification_version: 2
84
+ summary: Using Webby and some custom meta-data tags enable pingbacks to blogs and pages
85
+ test_files: []
86
+