pingr 0.0.3 → 0.2.3

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.
@@ -0,0 +1,110 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>
7
+ Top Level Namespace
8
+
9
+ &mdash; Pingr
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="css/style.css" type="text/css" />
14
+
15
+ <link rel="stylesheet" href="css/common.css" type="text/css" />
16
+
17
+ <script type="text/javascript">
18
+ pathId = "";
19
+ relpath = '';
20
+ </script>
21
+
22
+
23
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
24
+
25
+ <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
26
+
27
+
28
+ </head>
29
+ <body>
30
+ <div class="nav_wrap">
31
+ <iframe id="nav" src="class_list.html?1"></iframe>
32
+ <div id="resizer"></div>
33
+ </div>
34
+
35
+ <div id="main" tabindex="-1">
36
+ <div id="header">
37
+ <div id="menu">
38
+
39
+ <a href="_index.html">Index</a> &raquo;
40
+
41
+
42
+ <span class="title">Top Level Namespace</span>
43
+
44
+ </div>
45
+
46
+ <div id="search">
47
+
48
+ <a class="full_list_link" id="class_list_link"
49
+ href="class_list.html">
50
+
51
+ <svg width="24" height="24">
52
+ <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
53
+ <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
54
+ <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
55
+ </svg>
56
+ </a>
57
+
58
+ </div>
59
+ <div class="clear"></div>
60
+ </div>
61
+
62
+ <div id="content"><h1>Top Level Namespace
63
+
64
+
65
+
66
+ </h1>
67
+ <div class="box_info">
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+ </div>
80
+
81
+ <h2>Defined Under Namespace</h2>
82
+ <p class="children">
83
+
84
+
85
+ <strong class="modules">Modules:</strong> <span class='object_link'><a href="Pingr.html" title="Pingr (module)">Pingr</a></span>
86
+
87
+
88
+
89
+
90
+ </p>
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+ </div>
101
+
102
+ <div id="footer">
103
+ Generated on Thu Aug 13 16:28:50 2020 by
104
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
105
+ 0.9.24 (ruby-2.6.6).
106
+ </div>
107
+
108
+ </div>
109
+ </body>
110
+ </html>
data/lib/pingr/request.rb CHANGED
@@ -1,73 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Pingr
2
-
3
4
  # Public: The object created to ping a search engine with a sitemap
4
5
  class Request
5
-
6
- require 'logger'
7
- require 'net/http'
8
- require 'uri'
9
-
10
- # Public: Gets/Sets the String url of the sitemap we're submitting
11
- attr_accessor :sitemap_url
12
-
13
- # Public: Gets/Sets the String or Symbol name of the search engine we're pinging
14
- attr_accessor :search_engine
6
+ require 'pingr/search_engines/bing'
7
+ require 'pingr/search_engines/google'
15
8
 
16
9
  # Public: Initialize a new ping request
17
- #
18
- # search_engine - A String or Symbol name of the search engine we're pinging
10
+ #
19
11
  # sitemap_url - A String url of the sitemap we're submitting
20
- #
12
+ #
21
13
  # Returns a Pingr::Request object
22
- def initialize(search_engine, sitemap_url)
23
- self.search_engine = search_engine.to_sym
24
- self.sitemap_url = sitemap_url
25
- end
26
-
27
- # Public: The path to ping to submit sitemaps for this search_engine
28
- #
29
- # Returns a String with the correct path to submit sitemaps
30
- #
31
- # Raises: A PingrError if the search_engine attribute's value is not supported
32
- def ping_path
33
- case search_engine
34
- # http://www.google.com/webmasters/tools/ping?sitemap=
35
- when :google then "webmasters/tools/ping?sitemap=#{URI.escape(sitemap_url)}"
36
- # http://www.bing.com/ping?sitemap=
37
- when :bing then "ping?sitemap=#{URI.escape(sitemap_url)}"
38
- else
39
- raise PingrError, "Don't know how to ping search engine: #{search_engine}"
40
- end
41
- end
42
-
43
- # Public: Perform the ping request (if in :live mode)
44
- # Logs the success/failure of the ping in logger.
45
- #
46
- # Returns true if ping was a success
47
- # Returns false if ping was not successful
48
- def ping
49
- return true unless Pingr.mode == :live
50
- uri = URI.parse("http://#{search_engine}.com/#{ping_path}")
51
- http = Net::HTTP.new(uri.host, uri.port)
52
- request = Net::HTTP::Get.new(uri.request_uri)
53
- response = http.request(request)
54
- if response.code.to_s =~ /200|301/
55
- logger.info "Pinged #{search_engine} Successfully - #{Time.now}"
56
- return true
57
- else
58
- logger.warn "Error pinging #{search_engine}! (response code: #{response.code})- #{Time.now}"
59
- return false
60
- end
61
- end
62
-
63
- private
64
-
65
- # Private: A helper method to access Pingr::logger
66
- #
67
- # Returns A Logger instance
68
- def logger
69
- Pingr.logger
14
+ def initialize(sitemap_url)
15
+ Pingr::SearchEngines::Bing.new(sitemap_url).ping
16
+ Pingr::SearchEngines::Google.new(sitemap_url).ping
70
17
  end
71
-
72
18
  end
73
- end
19
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pingr
4
+ module SearchEngines
5
+ # Public: The object created to ping a search engine with a sitemap
6
+ class Base
7
+ require 'net/http'
8
+ require 'uri'
9
+
10
+ # Public: Gets/Sets the String url of the sitemap we're submitting
11
+ attr_reader :sitemap_url
12
+
13
+ # Public: Initialize a new ping request
14
+ #
15
+ # sitemap_url - A String url of the sitemap we're submitting
16
+ #
17
+ # Returns a Pingr::Request object
18
+ def initialize(sitemap_url)
19
+ @sitemap_url = sitemap_url
20
+ end
21
+
22
+ # Public: Perform the ping request (if in :live mode)
23
+ # Logs the success/failure of the ping in logger.
24
+ #
25
+ # Returns true if ping was a success
26
+ # Returns false if ping was not successful
27
+ def ping
28
+ return true unless Pingr.mode == :live
29
+
30
+ ssl = ping_url.scheme == 'https'
31
+ Net::HTTP.start(ping_url.host, ping_url.port, use_ssl: ssl) do |http|
32
+ request = Net::HTTP::Get.new(ping_url)
33
+ response = http.request(request)
34
+ if response.code.to_s =~ /200|301/
35
+ logger.info "Pinged #{search_engine} Successfully - #{Time.now}"
36
+ return true
37
+ else
38
+ logger.warn "Error pinging #{search_engine}! (response code: #{response.code})- #{Time.now}"
39
+ return false
40
+ end
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ def ping_url
47
+ raise NotImplementedError, "Define ping_url in #{self.class}"
48
+ end
49
+
50
+ def search_engine
51
+ raise NotImplementedError, "Define search_engine in #{self.class}"
52
+ end
53
+
54
+ # Private: A helper method to access Pingr::logger
55
+ #
56
+ # Returns A Logger instance
57
+ def logger
58
+ Pingr.logger
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pingr
4
+ module SearchEngines
5
+ require 'pingr/search_engines/base'
6
+
7
+ class Bing < Base
8
+ private
9
+
10
+ def search_engine
11
+ :bing
12
+ end
13
+
14
+ # Private: The path to ping to submit sitemaps for this search_engine
15
+ #
16
+ # Returns URI
17
+ def ping_url
18
+ URI("https://www.bing.com/ping?sitemap=#{URI.escape(sitemap_url)}")
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pingr
4
+ module SearchEngines
5
+ require 'pingr/search_engines/base'
6
+ class Google < Base
7
+ private
8
+
9
+ def search_engine
10
+ :google
11
+ end
12
+
13
+ # Private: The path to ping to submit sitemaps for this search_engine
14
+ #
15
+ # Returns URI
16
+ def ping_url
17
+ URI("https://www.google.com/webmasters/tools/ping?sitemap=#{URI.escape(sitemap_url)}")
18
+ end
19
+ end
20
+ end
21
+ end
data/lib/pingr/version.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Pingr
2
- VERSION = "0.0.3"
4
+ VERSION = '0.2.3'
3
5
  end
data/lib/pingr.rb CHANGED
@@ -1,26 +1,31 @@
1
- require "pingr/version"
2
- require "pingr/request"
1
+ # frozen_string_literal: true
2
+
3
+ require 'pingr/version'
4
+ require 'pingr/request'
3
5
 
4
6
  module Pingr
5
-
7
+
8
+ require 'logger'
9
+
10
+
6
11
  # Exceptions raised from within Pingr are of this class
7
12
  class PingrError < StandardError; end
8
-
9
- # Currently supported search engines
10
- SUPPORTED_SEARCH_ENGINES = [:google, :bing]
11
-
13
+
12
14
  # Public: Set the mode Pingr is running in
13
- #
15
+ #
14
16
  # mode_name - A Symbol or String value for the mode. Must be one of :test or :live
15
- #
17
+ #
16
18
  # Raises PingrError if an invalid value is passed
17
19
  def self.mode=(mode_name)
18
- raise PingrError, "Unknown mode: #{mode_name}" unless mode_name.to_s =~ /test|live/
20
+ unless mode_name.to_s =~ /test|live/
21
+ raise PingrError, "Unknown mode: #{mode_name}"
22
+ end
23
+
19
24
  @mode = mode_name.to_sym
20
25
  end
21
26
 
22
27
  # Public: The mode Pingr is running in
23
- #
28
+ #
24
29
  # Returns a Symbol either :test or :live
25
30
  def self.mode
26
31
  @mode ||= begin
@@ -31,33 +36,36 @@ module Pingr
31
36
  end
32
37
  end
33
38
  end
34
-
39
+
35
40
  # Public: A custom logger to keep track of the Pings
36
- #
41
+ #
37
42
  # Returns a Logger object. By default, the log clears itself every week
38
43
  def self.logger
39
- @logger ||= Logger.new(logger_name, shift_age = 'weekly')
44
+ @logger ||= if defined?(Rails)
45
+ Rails.logger
46
+ else
47
+ Logger.new(logger_name, shift_age = 'weekly')
48
+ end
40
49
  end
41
-
50
+
42
51
  # Public: Sets the logger to be used.
43
52
  # If the developer would like to use their own custom logger, let 'em.
44
53
  def self.logger=(_logger)
45
54
  @logger = _logger
46
55
  end
47
-
56
+
48
57
  private
49
58
 
50
59
  # Private: The name of the Logger used by Pingr.
51
60
  # If we've detected a Rails app, sets up a log file in the log directory.
52
61
  # Otherwise, use STDOUT
53
- #
62
+ #
54
63
  # Returns a String with the logger name or an IO object
55
64
  def self.logger_name
56
65
  if defined?(Rails)
57
- Rails.root.join('log', "pingr.#{Rails.env}.log")
66
+ Rails.root.join('log', "#{Rails.env}.log").to_s
58
67
  else
59
68
  STDOUT
60
69
  end
61
70
  end
62
-
63
71
  end
@@ -0,0 +1,19 @@
1
+ require "dotenv/tasks"
2
+
3
+ namespace :pingr do
4
+ require "pingr"
5
+
6
+ desc "Request search engines crawl the sitemap again"
7
+ task :ping => :dotenv do |t, args|
8
+ sitemap_url = ENV.fetch('SITEMAP_URL')
9
+ if sitemap_url.nil?
10
+ warn("Please provide SITEMAP_URL")
11
+ exit(1)
12
+ else
13
+ puts("Pinging search engines...")
14
+ Pingr::Request.new(sitemap_url)
15
+ puts("Done!")
16
+ end
17
+ end
18
+
19
+ end
data/pingr.gemspec CHANGED
@@ -1,21 +1,25 @@
1
- # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'pingr/version'
5
6
 
6
7
  Gem::Specification.new do |gem|
7
- gem.name = "pingr"
8
+ gem.name = 'pingr'
8
9
  gem.version = Pingr::VERSION
9
- gem.authors = ["Bodacious"]
10
- gem.email = ["bodacious@katanacode.com"]
11
- gem.description = %q{A simple gem for pinging search engines with your XML sitemap}
12
- gem.summary = %q{Ping search engines with your XML Sitemap}
13
- gem.homepage = "https://github.com/KatanaCode/pingr"
10
+ gem.authors = ['Bodacious']
11
+ gem.email = ['gavin@gavinmorrice.com']
12
+ gem.description = 'A simple gem for pinging search engines with your XML sitemap'
13
+ gem.summary = 'Ping search engines with your XML Sitemap'
14
+ gem.homepage = 'https://github.com/Bodacious/pingr'
14
15
 
15
- gem.files = `git ls-files`.split($/)
16
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
17
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
- gem.require_paths = ["lib"]
19
-
20
- gem.add_development_dependency "rake"
19
+ gem.require_paths = ['lib']
20
+
21
+ gem.add_runtime_dependency 'dotenv'
22
+ gem.add_runtime_dependency 'rake'
23
+
24
+ gem.add_development_dependency 'rspec'
21
25
  end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Pingr do
4
+ it 'has a version number' do
5
+ expect(Pingr::VERSION).not_to be nil
6
+ end
7
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/setup'
4
+ require 'pingr'
5
+
6
+ RSpec.configure do |config|
7
+ # Enable flags like --only-failures and --next-failure
8
+ config.example_status_persistence_file_path = '.rspec_status'
9
+
10
+ # Disable RSpec exposing methods globally on `Module` and `main`
11
+ config.disable_monkey_patching!
12
+
13
+ config.expect_with :rspec do |c|
14
+ c.syntax = :expect
15
+ end
16
+ end
metadata CHANGED
@@ -1,76 +1,131 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pingr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
5
- prerelease:
4
+ version: 0.2.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - Bodacious
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-27 00:00:00.000000000 Z
11
+ date: 2021-09-29 00:00:00.000000000 Z
13
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dotenv
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
14
27
  - !ruby/object:Gem::Dependency
15
28
  name: rake
16
29
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
30
  requirements:
19
- - - ! '>='
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
20
46
  - !ruby/object:Gem::Version
21
47
  version: '0'
22
48
  type: :development
23
49
  prerelease: false
24
50
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
51
  requirements:
27
- - - ! '>='
52
+ - - ">="
28
53
  - !ruby/object:Gem::Version
29
54
  version: '0'
30
55
  description: A simple gem for pinging search engines with your XML sitemap
31
56
  email:
32
- - bodacious@katanacode.com
33
- executables: []
57
+ - gavin@gavinmorrice.com
58
+ executables:
59
+ - console
60
+ - setup
34
61
  extensions: []
35
62
  extra_rdoc_files: []
36
63
  files:
37
- - .gitignore
64
+ - ".gitignore"
65
+ - ".rspec"
66
+ - ".travis.yml"
67
+ - ".yardopts"
38
68
  - Gemfile
39
69
  - LICENSE.txt
40
70
  - README.md
41
71
  - Rakefile
72
+ - bin/console
73
+ - bin/setup
74
+ - docs/Pingr.html
75
+ - docs/Pingr/PingrError.html
76
+ - docs/Pingr/Request.html
77
+ - docs/Pingr/SearchEngines.html
78
+ - docs/Pingr/SearchEngines/Base.html
79
+ - docs/Pingr/SearchEngines/Bing.html
80
+ - docs/Pingr/SearchEngines/Google.html
81
+ - docs/_config.yml
82
+ - docs/_index.html
83
+ - docs/class_list.html
84
+ - docs/css/common.css
85
+ - docs/css/full_list.css
86
+ - docs/css/style.css
87
+ - docs/file.README.html
88
+ - docs/file_list.html
89
+ - docs/frames.html
90
+ - docs/index.html
91
+ - docs/index.md
92
+ - docs/js/app.js
93
+ - docs/js/full_list.js
94
+ - docs/js/jquery.js
95
+ - docs/method_list.html
96
+ - docs/top-level-namespace.html
42
97
  - lib/pingr.rb
43
98
  - lib/pingr/request.rb
99
+ - lib/pingr/search_engines/base.rb
100
+ - lib/pingr/search_engines/bing.rb
101
+ - lib/pingr/search_engines/google.rb
44
102
  - lib/pingr/version.rb
103
+ - lib/tasks/pingr.rake
45
104
  - pingr.gemspec
46
- homepage: https://github.com/KatanaCode/pingr
105
+ - spec/pingr_spec.rb
106
+ - spec/spec_helper.rb
107
+ homepage: https://github.com/Bodacious/pingr
47
108
  licenses: []
48
- post_install_message:
109
+ metadata: {}
110
+ post_install_message:
49
111
  rdoc_options: []
50
112
  require_paths:
51
113
  - lib
52
114
  required_ruby_version: !ruby/object:Gem::Requirement
53
- none: false
54
115
  requirements:
55
- - - ! '>='
116
+ - - ">="
56
117
  - !ruby/object:Gem::Version
57
118
  version: '0'
58
- segments:
59
- - 0
60
- hash: 4232574977062910475
61
119
  required_rubygems_version: !ruby/object:Gem::Requirement
62
- none: false
63
120
  requirements:
64
- - - ! '>='
121
+ - - ">="
65
122
  - !ruby/object:Gem::Version
66
123
  version: '0'
67
- segments:
68
- - 0
69
- hash: 4232574977062910475
70
124
  requirements: []
71
- rubyforge_project:
72
- rubygems_version: 1.8.24
73
- signing_key:
74
- specification_version: 3
125
+ rubygems_version: 3.2.15
126
+ signing_key:
127
+ specification_version: 4
75
128
  summary: Ping search engines with your XML Sitemap
76
- test_files: []
129
+ test_files:
130
+ - spec/pingr_spec.rb
131
+ - spec/spec_helper.rb