bcms_sitemap 0.9.1 → 0.9.8

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.markdown CHANGED
@@ -1,6 +1,4 @@
1
- **WARNING: This module has not yet been tested in a live production environment**
2
-
3
- Available as a gem at [Gemcutter.org](http://gemcutter.org)
1
+ Available as a gem at [RubyGems.org](http://rubygems.org)
4
2
 
5
3
  # BCMS\_sitemap BrowserCMS sitemap submission module
6
4
 
@@ -77,14 +75,16 @@ and automatically create these upon saving the record for the individual search
77
75
 
78
76
  For more information see the individual sites:
79
77
 
80
- [Ask](http://about.ask.com/en/docs/about/webmasters.shtml),
81
78
  [Google](http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=156184),
82
79
  [Yahoo](http://help.yahoo.com/l/us/yahoo/smallbusiness/store/promote/sitemap/sitemap-16.html) and
83
80
  [yahoo submissions](https://siteexplorer.search.yahoo.com/submit), [Live/Bing](http://www.bing.com/webmaster)
84
81
 
85
- [Moreover](http://moreover.com) does not require authentication. (Not really a search engine, but provides news many to companies)
82
+ [Ask](http://about.ask.com/en/docs/about/webmasters.shtml) and
83
+ [Moreover](http://moreover.com) does not require authentication. (Moreover is not really a search engine, but provides news many to companies)
86
84
 
87
85
  [See also](http://www.hariesdesign.com/tips-and-trick/6-seo/46-submit-a-sitemap-to-top-5-search-engine) http://www.hariesdesign.com/tips-and-trick/6-seo/46-submit-a-sitemap-to-top-5-search-engine
86
+
87
+ Yahoo must be manually submitted the first time.
88
88
 
89
89
  ### Setting up your submission job
90
90
  You can use either cron or backgroundrb to submit your sitemap. My preference is cron.
@@ -97,11 +97,12 @@ Add the following:
97
97
  #!/usr/bin/env ruby
98
98
  require 'fileutils'
99
99
 
100
+ LUSER="...the user running the app..."
100
101
  APP_ROOT="/...yoursite..."
101
102
  RAILS_ENV="production"
102
103
  RAKE_OPTS='-q -s'
103
104
  Dir.chdir "#{APP_ROOT}/current"
104
- `RAILS_ENV=#{RAILS_ENV} rake #{RAKE_OPTS} sitemap:submit`
105
+ `su #{LUSER} -c "RAILS_ENV=#{RAILS_ENV} rake #{RAKE_OPTS} sitemap:submit"`
105
106
 
106
107
  Make it executable:
107
108
 
@@ -164,4 +165,8 @@ If you deploy using capistrano, you may want to add the sitemap:verify_signatori
164
165
  # Considerations for the future
165
166
 
166
167
  Currently the module is placing a template for rendering the search engines in the administration interface, due to inflexible module
167
- facilities in BrowserCMS. (Should be on the backlog for the browser cms team). Meanwhile, that view has to be stored locally.
168
+ facilities in BrowserCMS. (Should be on the backlog for the browser cms team). Meanwhile, that view has to be stored locally.
169
+
170
+ # Issues
171
+
172
+ I have had some issues with submitting updates to yahoo. This is currently under investigation.
@@ -35,7 +35,7 @@ class SearchEngine < ActiveRecord::Base
35
35
  end
36
36
 
37
37
  def signatory_file_name
38
- verification_file && !verification_file.empty? && File.join(signatory_folder, verification_file )
38
+ verification_file && !verification_file.blank? && File.join(signatory_folder, verification_file )
39
39
  end
40
40
 
41
41
  def has_signatory_file?
@@ -54,7 +54,7 @@ protected
54
54
  end
55
55
 
56
56
  def create_signatory_file
57
- if verification_file
57
+ unless verification_file.blank?
58
58
  File.atomic_write(signatory_file_name) do |file|
59
59
  file.write(verification_content || '')
60
60
  end
@@ -15,7 +15,7 @@ class CreateSearchEngines < ActiveRecord::Migration
15
15
  SearchEngine.create :name => 'Yahoo', :url => 'http://search.yahooapis.com/SiteExplorerService/V1/ping?sitemap='
16
16
  SearchEngine.create :name => 'Ask', :url => 'http://submissions.ask.com/ping?sitemap='
17
17
  SearchEngine.create :name => 'Live/Bing', :url => 'http://www.bing.com/webmaster/ping.aspx?siteMap='
18
- SearchEngine.create :name => 'Moreover', :url => 'http://api.moreover.com/ping?u='
18
+ SearchEngine.create :name => 'Moreover', :url => 'http://rpc.weblogs.com/pingSiteForm?url='
19
19
  end
20
20
 
21
21
  def self.down
@@ -1,14 +1,14 @@
1
1
  require 'cgi'
2
+ require 'net/https'
2
3
  class Cms::SitemapSubmitter
3
4
  include ActionController::UrlWriter
4
- include ActionController::Caching::Pages
5
5
 
6
6
  class << self
7
7
 
8
8
  # Checks to see if there has been any updates since last time.
9
9
  # If so, clears the cache for the relevant model and submits the url to the search engine's that have not yet been notified
10
10
  def run
11
- submit_time = SearchEngine.enabled.minimum(:submitted_at)
11
+ submit_time = SearchEngine.enabled.minimum(:submitted_at) || Time.now.years_ago(10)
12
12
 
13
13
  # collect timestamp for all models. We don't want to expire more pages than necessary
14
14
  timestamps = {}
@@ -18,12 +18,12 @@ class Cms::SitemapSubmitter
18
18
  end
19
19
  last_update = timestamps.values.compact.max
20
20
  # try this {}.values.compact.max
21
- if last_update && (submit_time.nil? || submit_time < last_update)
21
+ if last_update && (submit_time.nil? || (submit_time < last_update))
22
22
  # This is a lazy cleaning of cache
23
- expire_page :controller => 'sitemaps', :action => 'index', :format => 'xml'
23
+ expire_sitemap :controller => 'sitemaps', :action => 'index', :format => 'xml'
24
24
 
25
25
  @models.each do |model|
26
- expire_page :controller => 'sitemaps', :model => model, :format => 'xml' if !timestamps[model] || submit_time < timestamps[model]
26
+ expire_sitemap :controller => 'sitemaps', :action => model, :format => 'xml' if !timestamps[model] || submit_time < timestamps[model]
27
27
  end
28
28
  SearchEngine.enabled.all.each do |search_engine|
29
29
  if search_engine.submitted_at.nil? || search_engine.submitted_at < last_update
@@ -32,6 +32,19 @@ class Cms::SitemapSubmitter
32
32
  end
33
33
  end
34
34
  end
35
+
36
+ def expire_sitemap(options = {})
37
+ return unless perform_caching
38
+ ApplicationController::expire_page sitemap_path(options)
39
+ end
40
+
41
+ def sitemap_path(options = {})
42
+ if options[:action] == 'index'
43
+ "/#{options[:controller]}.#{options[:format]}"
44
+ else
45
+ "/#{options[:controller]}/#{options[:action]}.#{options[:format]}"
46
+ end
47
+ end
35
48
 
36
49
  # Submit a single search engine. Called from run through the search engine
37
50
  def submit(search_engine)
@@ -81,19 +94,25 @@ class Cms::SitemapSubmitter
81
94
 
82
95
  def initialize(search_engine) #:nodoc:
83
96
  @search_engine = search_engine
84
- @connection = ActiveResource::Connection.new(search_engine.url)
85
97
  end
86
98
 
87
99
  def submit #:nodoc:
88
- response = 200
89
- begin
90
- @connection.get(document_url)
100
+ #puts "Submitting #{document_url}"
101
+ resp = get document_url
102
+ #puts "Response was #{resp.code} #{resp.message}"
103
+ #puts "Body #{resp.body}"
104
+ if resp.is_a? Net::HTTPOK
91
105
  logger.info "Sitemap was successfully submitted to #{search_engine.name} (#{document_url})"
92
- rescue => e
93
- logger.error "Sitemap submition failed for #{search_engine.name} (#{document_url})\nResponse was #{e.response}"
94
- response = e.response
106
+ else
107
+ logger.error "Sitemap submition failed for #{search_engine.name} (#{document_url})\nResponse was #{resp.code} #{resp.message}"
95
108
  end
96
- response
109
+ resp.code
110
+ end
111
+
112
+ def get(document_url)
113
+ url = URI.parse(document_url)
114
+ http = Net::HTTP.new(url.host, url.port)
115
+ resp = http.send_request('GET', url.request_uri)
97
116
  end
98
117
 
99
118
  def document_url #:nodoc:
@@ -23,12 +23,12 @@ class Cms::SitemapSubmitterTest < ActiveSupport::TestCase
23
23
  @submitter = Cms::SitemapSubmitter.new(@search_engine)
24
24
  end
25
25
  should 'return response code on success' do
26
- @submitter.instance_variable_get(:@connection).stubs(:get).returns('')
26
+ @submitter.stubs(:get).returns(Net::HTTPSuccess.new('1.1', 200, 'OK'))
27
27
  resp = @submitter.submit
28
28
  assert_equal 200, resp
29
29
  end
30
30
  should 'return response code on failure' do
31
- @submitter.instance_variable_get(:@connection).expects(:get).raises(ActiveResource::ResourceNotFound, 404)
31
+ @submitter.stubs(:get).returns(Net::HTTPNotFound.new('1.1', 404, 'NotFound'))
32
32
  resp = @submitter.submit
33
33
  assert_equal 404, resp
34
34
  end
@@ -37,6 +37,23 @@ class Cms::SitemapSubmitterTest < ActiveSupport::TestCase
37
37
  end
38
38
  end
39
39
 
40
+ context 'expiring cache for sitemap' do
41
+ should 'execute' do
42
+ ApplicationController.perform_caching = true
43
+ assert_nil Cms::SitemapSubmitter.expire_sitemap( :controller => 'sitemaps', :action => 'test', :format => 'xml')
44
+ ApplicationController.perform_caching = false
45
+ end
46
+ end
47
+
48
+ context 'calculating path' do
49
+ should 'exclude index from path' do
50
+ assert_equal '/sitemaps.xml', Cms::SitemapSubmitter.sitemap_path(:controller => 'sitemaps', :action => 'index', :format => 'xml')
51
+ end
52
+ should 'include odel in path' do
53
+ assert_equal '/sitemaps/test.xml', Cms::SitemapSubmitter.sitemap_path(:controller => 'sitemaps', :action => 'test', :format => 'xml')
54
+ end
55
+ end
56
+
40
57
  context 'run' do
41
58
  setup do
42
59
  @search_engine = create_search_engine
@@ -7,7 +7,7 @@ class SitemapsHelperTest < ActionView::TestCase
7
7
  context 'xml_url' do
8
8
  setup do
9
9
  page_routes(:new_article).reload_routes
10
- @news = create_news_article :name => 'good-news', :created_at => Date.parse('2010-03-03')
10
+ @news = create_news_article :name => 'good-news' #, :created_at => Date.parse('2010-03-03')
11
11
  flunk "Expected news article not to respond to path" if @news.respond_to?(:path)
12
12
  @page = create_page :path => '/home'
13
13
  flunk "Expected page to respond to path" unless @page.respond_to?(:path)
@@ -16,7 +16,8 @@ class SitemapsHelperTest < ActionView::TestCase
16
16
  assert_equal "http://test.host/home", xml_url(@page)
17
17
  end
18
18
  should 'handle objects which does not have path' do
19
- assert_equal "http://test.host/news/articles/2010/03/02/good-news", xml_url(@news)
19
+ date_path = Date.yesterday.strftime("%Y/%m/%d")
20
+ assert_equal "http://test.host/news/articles/#{date_path}/good-news", xml_url(@news)
20
21
  end
21
22
  end
22
23
  end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bcms_sitemap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ hash: 43
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 9
9
+ - 8
10
+ version: 0.9.8
5
11
  platform: ruby
6
12
  authors:
7
13
  - Knut Stenmark
@@ -9,20 +15,26 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-03-03 00:00:00 +01:00
18
+ date: 2010-07-30 00:00:00 +02:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  name: browsercms
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
20
26
  requirements:
21
27
  - - ">="
22
28
  - !ruby/object:Gem::Version
29
+ hash: 11
30
+ segments:
31
+ - 3
32
+ - 0
33
+ - 6
23
34
  version: 3.0.6
24
- version:
25
- description: Warning. Not tested in production environment yet. Sitemap submitter module for BrowserCMS, which enables submission of sitemap to different search engines
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ description: Sitemap submitter module for BrowserCMS, which enables submission of sitemap to different search engines
26
38
  email: knut.stenmark@gmail.com
27
39
  executables: []
28
40
 
@@ -55,6 +67,13 @@ files:
55
67
  - rails/init.rb
56
68
  - LICENSE.txt
57
69
  - README.markdown
70
+ - test/functional/sitemaps_controller_test.rb
71
+ - test/integration/sitemap_submitter_test.rb
72
+ - test/performance/browsing_test.rb
73
+ - test/test_factory.rb
74
+ - test/test_helper.rb
75
+ - test/unit/helpers/sitemaps_helper_test.rb
76
+ - test/unit/search_engine_test.rb
58
77
  has_rdoc: true
59
78
  homepage: http://github.com/stonefield/bcms_sitemap
60
79
  licenses: []
@@ -65,21 +84,27 @@ rdoc_options:
65
84
  require_paths:
66
85
  - lib
67
86
  required_ruby_version: !ruby/object:Gem::Requirement
87
+ none: false
68
88
  requirements:
69
89
  - - ">="
70
90
  - !ruby/object:Gem::Version
91
+ hash: 3
92
+ segments:
93
+ - 0
71
94
  version: "0"
72
- version:
73
95
  required_rubygems_version: !ruby/object:Gem::Requirement
96
+ none: false
74
97
  requirements:
75
98
  - - ">="
76
99
  - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
77
103
  version: "0"
78
- version:
79
104
  requirements: []
80
105
 
81
106
  rubyforge_project:
82
- rubygems_version: 1.3.5
107
+ rubygems_version: 1.3.7
83
108
  signing_key:
84
109
  specification_version: 3
85
110
  summary: Sitemap submitter module for BrowserCMS