pingr 0.0.3 → 0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5aafdc1569dd1d154d3aea5788cf65838b1308a21eb9761ccb9d2087745bc3de
4
+ data.tar.gz: b3576e36e8d3065a62e788c7ddeec45ad58de1aaa55a7b34dcd487079b87f116
5
+ SHA512:
6
+ metadata.gz: cea8d57221a83b3f187392835e14e6561d183dd60d18dab4a232ac90cb41c0eebba6faa90a1fc1a61cdcc8a547af5b848b625042166ac1c5a5f45384f3137b15
7
+ data.tar.gz: 34d51c7cb94c67244720bebe174f75e0b36ca210c7ef8a9f0ad987f915dc626276949cd7044720ff30488a5ab62482e9fd375968b7871d5f8e8b8aaaefc833dd
data/.gitignore CHANGED
@@ -15,3 +15,5 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ log
19
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.3
7
+ before_install: gem install bundler -v 1.17.3
data/Gemfile CHANGED
@@ -1,4 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
3
7
  # Specify your gem's dependencies in pingr.gemspec
4
8
  gemspec
data/LICENSE.txt CHANGED
@@ -1,22 +1,21 @@
1
- Copyright (c) 2013 Bodacious
1
+ The MIT License (MIT)
2
2
 
3
- MIT License
3
+ Copyright (c) 2020 Bodacious
4
4
 
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
12
11
 
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
15
14
 
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -77,3 +77,8 @@ Pingr.mode = :live if Rails.env =~ /staging|production/
77
77
  3. Commit your changes (`git commit -am 'Add some feature'`)
78
78
  4. Push to the branch (`git push origin my-new-feature`)
79
79
  5. Create new Pull Request
80
+
81
+
82
+ ## About Katana Code
83
+
84
+ Katana Code are [iPhone app and Ruby on Rails Developers in Edinburgh, Scotland](http://katanacode.com/ "Katana Code").
data/Rakefile CHANGED
@@ -1 +1,8 @@
1
- require "bundler/gem_tasks"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'pingr'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/pingr.rb CHANGED
@@ -1,26 +1,27 @@
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
-
6
7
  # Exceptions raised from within Pingr are of this class
7
8
  class PingrError < StandardError; end
8
-
9
- # Currently supported search engines
10
- SUPPORTED_SEARCH_ENGINES = [:google, :bing]
11
-
9
+
12
10
  # Public: Set the mode Pingr is running in
13
- #
11
+ #
14
12
  # mode_name - A Symbol or String value for the mode. Must be one of :test or :live
15
- #
13
+ #
16
14
  # Raises PingrError if an invalid value is passed
17
15
  def self.mode=(mode_name)
18
- raise PingrError, "Unknown mode: #{mode_name}" unless mode_name.to_s =~ /test|live/
16
+ unless mode_name.to_s =~ /test|live/
17
+ raise PingrError, "Unknown mode: #{mode_name}"
18
+ end
19
+
19
20
  @mode = mode_name.to_sym
20
21
  end
21
22
 
22
23
  # Public: The mode Pingr is running in
23
- #
24
+ #
24
25
  # Returns a Symbol either :test or :live
25
26
  def self.mode
26
27
  @mode ||= begin
@@ -31,33 +32,32 @@ module Pingr
31
32
  end
32
33
  end
33
34
  end
34
-
35
+
35
36
  # Public: A custom logger to keep track of the Pings
36
- #
37
+ #
37
38
  # Returns a Logger object. By default, the log clears itself every week
38
39
  def self.logger
39
40
  @logger ||= Logger.new(logger_name, shift_age = 'weekly')
40
41
  end
41
-
42
+
42
43
  # Public: Sets the logger to be used.
43
44
  # If the developer would like to use their own custom logger, let 'em.
44
45
  def self.logger=(_logger)
45
46
  @logger = _logger
46
47
  end
47
-
48
+
48
49
  private
49
50
 
50
51
  # Private: The name of the Logger used by Pingr.
51
52
  # If we've detected a Rails app, sets up a log file in the log directory.
52
53
  # Otherwise, use STDOUT
53
- #
54
+ #
54
55
  # Returns a String with the logger name or an IO object
55
56
  def self.logger_name
56
57
  if defined?(Rails)
57
- Rails.root.join('log', "pingr.#{Rails.env}.log")
58
+ Rails.root.join('log', "#{Rails.env}.log").to_s
58
59
  else
59
60
  STDOUT
60
61
  end
61
62
  end
62
-
63
63
  end
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.1.0'
3
5
  end
data/pingr.gemspec CHANGED
@@ -1,21 +1,23 @@
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 = ['bodacious@katanacode.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/KatanaCode/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_development_dependency 'rake'
22
+ gem.add_development_dependency 'rspec'
21
23
  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,92 @@
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.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Bodacious
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-27 00:00:00.000000000 Z
11
+ date: 2020-01-17 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
28
39
  - !ruby/object:Gem::Version
29
40
  version: '0'
30
41
  description: A simple gem for pinging search engines with your XML sitemap
31
42
  email:
32
43
  - bodacious@katanacode.com
33
- executables: []
44
+ executables:
45
+ - console
46
+ - setup
34
47
  extensions: []
35
48
  extra_rdoc_files: []
36
49
  files:
37
- - .gitignore
50
+ - ".gitignore"
51
+ - ".rspec"
52
+ - ".travis.yml"
38
53
  - Gemfile
39
54
  - LICENSE.txt
40
55
  - README.md
41
56
  - Rakefile
57
+ - bin/console
58
+ - bin/setup
42
59
  - lib/pingr.rb
43
60
  - lib/pingr/request.rb
61
+ - lib/pingr/search_engines/base.rb
62
+ - lib/pingr/search_engines/bing.rb
63
+ - lib/pingr/search_engines/google.rb
44
64
  - lib/pingr/version.rb
45
65
  - pingr.gemspec
66
+ - spec/pingr_spec.rb
67
+ - spec/spec_helper.rb
46
68
  homepage: https://github.com/KatanaCode/pingr
47
69
  licenses: []
70
+ metadata: {}
48
71
  post_install_message:
49
72
  rdoc_options: []
50
73
  require_paths:
51
74
  - lib
52
75
  required_ruby_version: !ruby/object:Gem::Requirement
53
- none: false
54
76
  requirements:
55
- - - ! '>='
77
+ - - ">="
56
78
  - !ruby/object:Gem::Version
57
79
  version: '0'
58
- segments:
59
- - 0
60
- hash: 4232574977062910475
61
80
  required_rubygems_version: !ruby/object:Gem::Requirement
62
- none: false
63
81
  requirements:
64
- - - ! '>='
82
+ - - ">="
65
83
  - !ruby/object:Gem::Version
66
84
  version: '0'
67
- segments:
68
- - 0
69
- hash: 4232574977062910475
70
85
  requirements: []
71
- rubyforge_project:
72
- rubygems_version: 1.8.24
86
+ rubygems_version: 3.0.3
73
87
  signing_key:
74
- specification_version: 3
88
+ specification_version: 4
75
89
  summary: Ping search engines with your XML Sitemap
76
- test_files: []
90
+ test_files:
91
+ - spec/pingr_spec.rb
92
+ - spec/spec_helper.rb