pingr 0.0.3 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f4489ba3b7b8c39ee1e18bbd9e80d366d13020aa790b8bf6b0f332cac8376018
4
+ data.tar.gz: 60ef57d71a99b5ca892c45cf419eb8af039f4a1a94eed3bd50b30f57b00344f4
5
+ SHA512:
6
+ metadata.gz: 9cb214d121f3f557641963bccf2ae67cfbb9fbf190c7f1f2e57a4dc6735d381fa3aa27fed29decba46c6b3b3708254489d38d1dcaf28e581106adddd5b2dcba6
7
+ data.tar.gz: 2c452f2ccf7e495de33d63f1ec38140c156ebe32f28cb4b914fb5038fc6336adeb38fb146e8ca5f22a215b4019c526b34c23de8272a0e55f4cdf7a721493aa4f
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
@@ -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
@@ -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,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ import "./lib/tasks/pingr.rake"
7
+
8
+ RSpec::Core::RakeTask.new(:spec)
9
+
10
+ task default: :spec
11
+
12
+ Bundler::GemHelper.install_tasks
@@ -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__)
@@ -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
@@ -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
@@ -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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Pingr
2
- VERSION = "0.0.3"
4
+ VERSION = '0.2.2'
3
5
  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
@@ -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 = ['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
+ gem.require_paths = ['lib']
20
+
21
+ gem.add_runtime_dependency 'dotenv'
22
+ gem.add_runtime_dependency 'rake'
19
23
 
20
- gem.add_development_dependency "rake"
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,107 @@
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.2
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-06-18 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
57
  - bodacious@katanacode.com
33
- executables: []
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"
38
67
  - Gemfile
39
68
  - LICENSE.txt
40
69
  - README.md
41
70
  - Rakefile
71
+ - bin/console
72
+ - bin/setup
42
73
  - lib/pingr.rb
43
74
  - lib/pingr/request.rb
75
+ - lib/pingr/search_engines/base.rb
76
+ - lib/pingr/search_engines/bing.rb
77
+ - lib/pingr/search_engines/google.rb
44
78
  - lib/pingr/version.rb
79
+ - lib/tasks/pingr.rake
45
80
  - pingr.gemspec
81
+ - spec/pingr_spec.rb
82
+ - spec/spec_helper.rb
46
83
  homepage: https://github.com/KatanaCode/pingr
47
84
  licenses: []
85
+ metadata: {}
48
86
  post_install_message:
49
87
  rdoc_options: []
50
88
  require_paths:
51
89
  - lib
52
90
  required_ruby_version: !ruby/object:Gem::Requirement
53
- none: false
54
91
  requirements:
55
- - - ! '>='
92
+ - - ">="
56
93
  - !ruby/object:Gem::Version
57
94
  version: '0'
58
- segments:
59
- - 0
60
- hash: 4232574977062910475
61
95
  required_rubygems_version: !ruby/object:Gem::Requirement
62
- none: false
63
96
  requirements:
64
- - - ! '>='
97
+ - - ">="
65
98
  - !ruby/object:Gem::Version
66
99
  version: '0'
67
- segments:
68
- - 0
69
- hash: 4232574977062910475
70
100
  requirements: []
71
- rubyforge_project:
72
- rubygems_version: 1.8.24
101
+ rubygems_version: 3.1.3
73
102
  signing_key:
74
- specification_version: 3
103
+ specification_version: 4
75
104
  summary: Ping search engines with your XML Sitemap
76
- test_files: []
105
+ test_files:
106
+ - spec/pingr_spec.rb
107
+ - spec/spec_helper.rb