Module: FetchApp
- Defined in:
- lib/fetch_app.rb,
lib/fetch_app/version.rb
Constant Summary collapse
- ANDROID_BASE_URL =
'http://www.wandoujia.com/apps/'
- IOS_BASE_URL =
'http://itunes.apple.com/lookup?country=cn&'
- VERSION =
"0.0.1"
Class Method Summary collapse
- .fetch_android(bundle_id) ⇒ Object
- .fetch_app(type, bundle_id) ⇒ Object
- .fetch_ios(bundle_id = "") ⇒ Object
Class Method Details
.fetch_android(bundle_id) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/fetch_app.rb', line 69 def fetch_android bundle_id return raise 'bundle_id is error' if !bundle_id || bundle_id.empty? url = ANDROID_BASE_URL+"#{bundle_id}?json" data = RestClient.get(url) return raise 'app info null' if !data begin info = JSON.parse(data.body) puts 'info[:packageName]',info["packageName"] if info && info["packageName"] info_detail = { name: info["app"]["title"], app_id: info["packageName"], version: info["app"]["latestApk"]["versionName"], desc: info["app"]["description"].gsub("<br />","\n"), link: info["app"]["latestApk"]["downloadUrl"]["referUrl"], icon: info["app"]["icons"]["px256"] || info["app"]["icons"]["px100"], screens: info["app"]["screenshots"]["normal"], gener: info["app"]["categories"][0]["name"] } return info_detail else return raise 'app info null' end rescue Exception => e raise e end end |
.fetch_app(type, bundle_id) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/fetch_app.rb', line 9 def fetch_app type,bundle_id type ||= 'ios' type = type.downcase if type != 'ios' && type != 'android' return nil end self.send("fetch_#{type}",bundle_id) end |
.fetch_ios(bundle_id = "") ⇒ Object
19 20 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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/fetch_app.rb', line 19 def fetch_ios bundle_id="" url = IOS_BASE_URL ; if bundle_id.is_a?(Numeric) bundle_id = bundle_id.to_s end return raise 'bundle_id is error' if !bundle_id || bundle_id.empty? if /^[0-9]*$/.match(bundle_id) url += 'id=' else url += 'bundleId=' end url += bundle_id data = RestClient.get(url) raise 'app info nil' if !data body = data.body begin info = JSON.parse(body) if info["resultCount"] == 1 info = info['results'][0] if info["kind"] == 'software' info_detail = { name: info["trackName"], app_id: info["bundleId"], desc: info["description"], link: info["trackViewUrl"], icon: info["artworkUrl512"], screens: info["screenshotUrls"], version: info["version"], track_id: info["trackId"], gener: info["genres"][0] } return info_detail else raise 'app info nil' end else raise 'app info nil' end rescue Exception => e raise e end end |