Class: Pinger

Inherits:
Object
  • Object
show all
Defined in:
app/services/pinger.rb

Class Method Summary collapse

Class Method Details

.ping(url, title) ⇒ Object


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/services/pinger.rb', line 2

def self.ping(url, title)
  uri = URI('http://ping.blogs.yandex.ru/RPC2')
  https = Net::HTTP.new(uri.host, uri.port)

  xml = <<~XML
    <?xml version="1.0" encoding="UTF-8"?>
    <methodCall>
      <methodName>weblogUpdates.ping</methodName>
      <params>
        <param>
          <value>#{title}</value>
        </param>
        <param>
          <value>#{url}</value>
        </param>
      </params>
    </methodCall>
  XML

  response = https.post(uri.path, xml)
rescue Net::OpenTimeout => ex
  Rails.logger.error "Faild to ping #{ex}"
end