Class: ScraperAppStore::App

Inherits:
Base
  • Object
show all
Defined in:
lib/scraper_app_store/app.rb

Constant Summary collapse

DEFAULT_URL =
"https://itunes.apple.com/lookup"

Instance Method Summary collapse

Methods inherited from Base

#exist?

Constructor Details

#initialize(options = {}) ⇒ App

params id or app_id



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/scraper_app_store/app.rb', line 4

def initialize( options = {} ) #params id or app_id
	raise "require Id (TrackId) or AppId (bundleId) " unless options[:id] || options[:app_id]
	id_field = options[:id] ? "id" : "bundleId"
	id_value = options[:id] || options[:app_id]
   country = options[:country] || ''
			
	@agent = Mechanize.new

	unless exist?("#{DEFAULT_URL}?#{id_field}=#{id_value}&country=#{country}")
		@page = nil
	else 
		@page = @agent.get("#{DEFAULT_URL}?#{id_field}=#{id_value}&country=#{country}")
	end

	@info = @page.body
end

Instance Method Details

#infoObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/scraper_app_store/app.rb', line 21

def info
	hash_info = JSON.parse(@info)["results"][0]
	
	@app_info = {
		id: hash_info['trackId'],
		app_id: hash_info['bundleId'],
		name: hash_info["trackName"] ,
		logo: hash_info['artworkUrl512'] || hash_info['artworkUrl100'] || hash_info['artworkUrl60'],
		screen_shots: hash_info['screenshotUrls'],
		developer: hash_info['artistName'],
		address: "",
		email: hash_info['sellerUrl'], 
		title: hash_info["trackName"],
		genre_text: hash_info['genres'],
		genre_id: hash_info['genresIds'],
		version: hash_info['version'],
		description: hash_info['description'],
		android_version_text: "",
		android_version: hash_info['minimumOsVersion'],
		contentRating: hash_info['contentAdvisoryRating'],
		size: hash_info['fileSizeBytes'],
		video: "",
		score: hash_info['averageUserRating'],
	}	

end