Class: GpisScraper
- Inherits:
-
Object
- Object
- GpisScraper
- Defined in:
- lib/gpis/gpis_scraper.rb
Constant Summary collapse
- GOOGLE_PLAY_URL =
"https://play.google.com/store/apps/details"
Class Method Summary collapse
- .get_data_and_follow_redirections(initial_url) ⇒ Object
- .scrape_info(package_name, languages) ⇒ Object
Class Method Details
.get_data_and_follow_redirections(initial_url) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/gpis/gpis_scraper.rb', line 16 def self.get_data_and_follow_redirections(initial_url) url = initial_url begin stream = open(url, 'User-Agent' => 'ruby', :redirect => false) rescue OpenURI::HTTPRedirect url = $!.uri retry rescue OpenURI::HTTPError => e status_code = e.io.status[0] if status_code == "503" raise GpisServiceNotAvailable.new("Gpis: Service Not Available : #{e.} :#{e.backtrace.join("\n")}") else raise GpisPageNotFoundError.new("Gpis: Page Not Found Error : #{e.} :#{e.backtrace.join("\n")}") end end # ensure encoding Iconv.conv('UTF-8', stream.charset, stream.read) end |
.scrape_info(package_name, languages) ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/gpis/gpis_scraper.rb', line 6 def self.scrape_info(package_name, languages) documents = Hash.new languages.each do |language| initial_url = "#{GOOGLE_PLAY_URL}?id=#{package_name}&hl=#{language}" stream = get_data_and_follow_redirections(initial_url) documents[language] = Nokogiri::HTML(stream) end GpisAppInfo.new(package_name, documents) end |