Skip to content

Instantly share code, notes, and snippets.

@ericchernuka
Created October 22, 2014 17:48
Show Gist options
  • Save ericchernuka/5c5c1352adf0812b0ae8 to your computer and use it in GitHub Desktop.
Save ericchernuka/5c5c1352adf0812b0ae8 to your computer and use it in GitHub Desktop.
Mobile App Info
class MobileAppInfo
#
# @param platform [String] Device Platform ("ios" or "android")
# @param app_name [String] Mobile App Name ("makeshift" or "makeshift_live")
# @param app_version = "" [String] App Version
#
def initialize(platform, app_name, app_version = "")
raise ArgumentError.new("Mobile App name is required. Example: 'makeshift'") unless UserDevice::APP_NAMES.include?(app_name)
raise ArgumentError.new("Mobile Platform is required. Example: 'ios'") unless UserDevice::DEVICE_TYPES.include?(platform)
@platform = platform
@app_name = app_name
@app_version = app_version
end
#
# Returns Unique ID based on the mobile device platform and app name
#
# @example ios
# "791381017"
#
# @example android
# "ca.appcolony.makeshift.android"
#
# @return [String] App Store Id
def app_store_id
@app_store_id ||= begin
if @platform == "android"
if @app_name == "makeshift"
Settings.apps.android.makeshift.package_name
else
Settings.apps.android.makeshift_live.package_name
end
else
if @app_name == "makeshift"
Settings.apps.ios.makeshift.itunes_connect_app_id
else
Settings.apps.ios.makeshift_live.itunes_connect_app_id
end
end
end
end
#
# Returns App Store URL for the platform
#
# @example ios
# "https://itunes.apple.com/app/id791381017"
#
# @example android
# "https://play.google.com/store/apps/details?id=ca.appcolony.makeshift.android&hl=en"
#
# @return [String] Apple App Store or Google Play URL
def store_url
case @platform
when "android"
"https://play.google.com/store/apps/details?id=#{app_store_id}&hl=en"
when "ios"
"https://itunes.apple.com/app/id#{app_store_id}"
end
end
#
# Checks if the app_version is supported.
#
# @return [Boolean]
def supported?
Gem::Version.new(@app_version) > Gem::Version.new(lockout_version)
end
#
# Returns the object as JSON
#
# @return [Hash]
def as_json
{
"app_name" => @app_name,
"app_store_id" => app_store_id,
"platform" => @platform,
"store_url" => store_url
}
end
private
#
# Determines the lockout version for the platform and app.
#
# @return [String] Lockout Version
def lockout_version
@lockout_version ||= begin
if @platform == "android"
if @app_name == "makeshift"
Settings.apps.android.makeshift.lockout_version
else
Settings.apps.android.makeshift_live.lockout_version
end
else
if @app_name == "makeshift"
Settings.apps.ios.makeshift.lockout_version
else
Settings.apps.ios.makeshift_live.lockout_version
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment