Created
July 10, 2014 14:07
-
-
Save taleschaves/e654d45ec1b822277815 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HockeyAppClient | |
ANDROID_HPTPM_V1 = '/download/HPTPM_v1-0.apk' | |
ANDROID_APP_VERSION = '1.4.11' | |
attr_reader :platform | |
def initialize(platform = 'Android', fallback_url = ANDROID_HPTPM_V1) | |
@platform = platform | |
@fallback_url = fallback_url | |
@connection = HockeyApp.build_client(token: KeyManagement.HockeyAppAPIToken) | |
end | |
def app_url(version=nil) | |
handle_errors do | |
app = version ? find_app_by_version(version) : latest_version | |
app.direct_download_url | |
end | |
end | |
def handle_errors(&block) | |
begin | |
yield | |
rescue => e | |
@fallback_url | |
end | |
end | |
def latest_app_version(version = :full) | |
app = latest_version | |
version == :short ? app.shortversion : app.version | |
end | |
def find_app_by_version(version) | |
app.versions.each do |app| | |
return app if app.shortversion == version | |
end | |
end | |
privateclass HockeyAppClient | |
ANDROID_HPTPM_V1 = '/download/HPTPM_v1-0.apk' | |
ANDROID_APP_VERSION = '1.4.11' | |
attr_reader :platform | |
def initialize(platform = 'Android', fallback_url = ANDROID_HPTPM_V1) | |
@platform = platform | |
@fallback_url = fallback_url | |
@connection = HockeyApp.build_client(token: KeyManagement.HockeyAppAPIToken) | |
end | |
def app_url(version=nil) | |
handle_errors do | |
app = version ? find_app_by_version(version) : latest_version | |
app.direct_download_url | |
end | |
end | |
def handle_errors(&block) | |
begin | |
yield | |
rescue => e | |
@fallback_url | |
end | |
end | |
def latest_app_version(version = :full) | |
app = latest_version | |
version == :short ? app.shortversion : app.version | |
end | |
def find_app_by_version(version) | |
app.versions.each do |app| | |
return app if app.shortversion == version | |
end | |
end | |
private | |
def latest_version | |
app.last_version | |
end | |
def app | |
all_apps.select {|app| app.title = "HP Touchpoint Manager" && app.platform == @platform }.first | |
end | |
def all_apps | |
@all_apps ||= @connection.get_apps | |
end | |
end | |
def latest_version | |
app.last_version | |
end | |
def app | |
all_apps.select {|app| app.title = "HP Touchpoint Manager" && app.platform == @platform }.first | |
end | |
def all_apps | |
@all_apps ||= @connection.get_apps | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment