Class: Pingr::SearchEngines::Base
- Inherits:
-
Object
- Object
- Pingr::SearchEngines::Base
- Defined in:
- lib/pingr/search_engines/base.rb
Overview
Public: The object created to ping a search engine with a sitemap
Instance Attribute Summary collapse
-
#sitemap_url ⇒ Object
readonly
Public: Gets/Sets the String url of the sitemap we’re submitting.
Instance Method Summary collapse
-
#initialize(sitemap_url) ⇒ Base
constructor
Public: Initialize a new ping request.
-
#ping ⇒ Object
Public: Perform the ping request (if in :live mode) Logs the success/failure of the ping in logger.
Constructor Details
#initialize(sitemap_url) ⇒ Base
Public: Initialize a new ping request
sitemap_url - A String url of the sitemap we’re submitting
Returns a Pingr::Request object
18 19 20 |
# File 'lib/pingr/search_engines/base.rb', line 18 def initialize(sitemap_url) @sitemap_url = sitemap_url end |
Instance Attribute Details
#sitemap_url ⇒ Object (readonly)
Public: Gets/Sets the String url of the sitemap we’re submitting
11 12 13 |
# File 'lib/pingr/search_engines/base.rb', line 11 def sitemap_url @sitemap_url end |
Instance Method Details
#ping ⇒ Object
Public: Perform the ping request (if in :live mode) Logs the success/failure of the ping in logger.
Returns true if ping was a success Returns false if ping was not successful
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/pingr/search_engines/base.rb', line 27 def ping return true unless Pingr.mode == :live ssl = ping_url.scheme == 'https' Net::HTTP.start(ping_url.host, ping_url.port, use_ssl: ssl) do |http| request = Net::HTTP::Get.new(ping_url) response = http.request(request) if response.code.to_s =~ /200|301/ logger.info "Pinged #{search_engine} Successfully - #{Time.now}" return true else logger.warn "Error pinging #{search_engine}! (response code: #{response.code})- #{Time.now}" return false end end end |