Skip to content

Instantly share code, notes, and snippets.

@taleschaves
Created July 10, 2014 14:07
Show Gist options
  • Save taleschaves/e654d45ec1b822277815 to your computer and use it in GitHub Desktop.
Save taleschaves/e654d45ec1b822277815 to your computer and use it in GitHub Desktop.
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