examples/wikipedia-dns.rb in rubydns-1.0.3 vs examples/wikipedia-dns.rb in rubydns-2.0.0.pre.rc1

- old
+ new

@@ -20,43 +20,31 @@ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. require 'rubydns' -require 'rubydns/extensions/string' require 'process/daemon' require 'process/daemon/privileges' require 'cgi' require 'nokogiri' require 'json' require 'digest/md5' +require 'http' + # You might need to change the user name "daemon". This can be a user name # or a user id. RUN_AS = 'daemon' if Process::Daemon::Privileges.current_user != 'root' $stderr.puts 'Sorry, this command needs to be run as root!' exit 1 end -require 'http' - -# Celluloid::IO fetcher to retrieve URLs. -class HttpFetcher - include Celluloid::IO - - def get(url) - # Note: For SSL support specify: - # ssl_socket_class: Celluloid::IO::SSLSocket - HTTP.get(url, socket_class: Celluloid::IO::TCPSocket) - end -end - # Encapsulates the logic for fetching information from Wikipedia. module Wikipedia def self.summary_url(title) "http://en.wikipedia.org/w/api.php?action=parse&page=#{CGI.escape title}&prop=text&section=0&format=json" end @@ -79,13 +67,10 @@ # Don't buffer output (for debug purposes) $stderr.sync = true stats = { requested: 0 } - # Use a Celluloid supervisor so the system recovers if the actor dies - fetcher = HttpFetcher.supervise - # Start the RubyDNS server RubyDNS.run_server do on(:start) do Process::Daemon::Privileges.change_user(RUN_AS) if ARGV.include?('--debug') @@ -101,10 +86,11 @@ match(/(.+)\.wikipedia/, IN::TXT) do |transaction, match_data| title = match_data[1] stats[:requested] += 1 - response = fetcher.actors.first.get(Wikipedia.summary_url(title)) + url = Wikipedia.summary_url(title) + response = HTTP.get(url) # socket_class: ... is not yet supported. summary = Wikipedia.extract_summary(response).force_encoding('ASCII-8BIT') transaction.respond!(*summary.chunked) end