class MetaDataDownloader
require 'faraday_middleware' require 'typhoeus/adapters/faraday'
Constants
Public Class Methods
new( include_depth = false)
click to toggle source
# File lib/gsv_downloader/meta_data_downloader.rb, line 12 def initialize( include_depth = false) @base_url = if include_depth "#{BASE_URL}&dmz=1&pmz=1" else BASE_URL end # # Typhoeus::Config.memoize = false # @conn = Faraday.new(:url => "http://cbk1.google.com") do |faraday| # faraday.request :retry # faraday.response :raise_error # faraday.response :json #:content_type => /\bjson$/ # faraday.adapter :typhoeus # end @hydra = Typhoeus::Hydra.new end
Public Instance Methods
download(panoID) { |body| ... }
click to toggle source
enqueue a download
# File lib/gsv_downloader/meta_data_downloader.rb, line 35 def download(panoID) url = "#{@base_url}&panoid=#{panoID}" # p panoID # p url request = Typhoeus::Request.new(url, headers: { 'User-Agent' => "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.10) Gecko/20100915 Ubuntu/10.04 (lucid) Firefox/3.6.10", "accept-charset" => "ISO-8859-1,utf-8;q=0.7,*;q=0.3" }) request.on_complete do |response| if response.success? # Process the links in the response. yield(response.body) else raise Exception.new("error to get meta_data of #{panoID} (response code #{response.code})") end end @hydra.queue request end
download_batch(panoIDs)
click to toggle source
# File lib/gsv_downloader/meta_data_downloader.rb, line 56 def download_batch(panoIDs) @hydra = Typhoeus::Hydra.new panoIDs.each do |panoID| download(panoID) end start() end
start()
click to toggle source
# File lib/gsv_downloader/meta_data_downloader.rb, line 30 def start() @hydra.run end