Commit 0033e97b authored by jz143's avatar jz143

"Get latest version of my app" API for app owners to implement semi-auto app updates

parent d24a2344
## Setup ## Setup
* Install `iPhone Distribution: Duke University` certificate and private key to `System` keychain on signing server. * Install `iPhone Distribution: Duke University` certificate and private key to `System` keychain on signing server.
- Get Info > Access Control > Allow all applications to access this item - Get Info > Access Control > Allow all applications to access this item
* Install [Jiehan's fork of floatsign.sh](https://github.com/jiehanzheng/floatsign) and make it part of the PATH
* Install ImageMagick * Install ImageMagick
* Install Redis * Install Redis
......
class AppsController < ApplicationController class AppsController < ApplicationController
before_action :set_app, only: [:show, :edit, :update, :destroy] before_action :set_app, only: [:show, :edit, :update, :destroy, :latest_version]
# GET /apps # GET /apps
# GET /apps.json # GET /apps.json
...@@ -11,10 +11,13 @@ class AppsController < ApplicationController ...@@ -11,10 +11,13 @@ class AppsController < ApplicationController
# GET /apps/1.json # GET /apps/1.json
def show def show
authorize @app authorize @app
set_latest_versions
end
# find latest versions for each platform # public API
@latest_ios = @app.app_files.where(platform: 'iOS', code_signing_status: AppFile.code_signing_statuses[:signed]).order(created_at: :desc).first # do not check authorization!
@latest_android = @app.app_files.where(:platform => 'Android').order(created_at: :desc).first def latest_version
set_latest_versions
end end
# GET /apps/new # GET /apps/new
...@@ -79,6 +82,12 @@ class AppsController < ApplicationController ...@@ -79,6 +82,12 @@ class AppsController < ApplicationController
@app = App.find(params[:id]) @app = App.find(params[:id])
end end
# sets @latest_ios and @latest_android to latest app_file's for each platform
def set_latest_versions
@latest_ios = @app.app_files.where(platform: 'iOS', code_signing_status: AppFile.code_signing_statuses[:signed]).order(created_at: :desc).first
@latest_android = @app.app_files.where(:platform => 'Android').order(created_at: :desc).first
end
# Never trust parameters from the scary internet, only allow the white list through. # Never trust parameters from the scary internet, only allow the white list through.
def app_params def app_params
params.require(:app).permit(:name, :description, :icon, :bundle_identifier_suffix) params.require(:app).permit(:name, :description, :icon, :bundle_identifier_suffix)
......
...@@ -33,4 +33,30 @@ class AppFile < ActiveRecord::Base ...@@ -33,4 +33,30 @@ class AppFile < ActiveRecord::Base
platform == "iOS" platform == "iOS"
end end
def is_android_app?
platform == "Android"
end
def itms_services_url
unless is_ios_app?
raise "Only iOS apps have itms-services URLs"
end
url_options = Rails.application.config.action_mailer.default_url_options
url_options[:format] = :plist
url_options[:protocol] = :https
'itms-services://?action=download-manifest&url=' + Rails.application.routes.url_helpers.app_app_file_download_url(app, self, url_options)
end
def apk_url
unless is_android_app?
raise "Only Android apps have apk_url"
end
url_options = Rails.application.config.action_mailer.default_url_options
url_options[:format] = :apk
url_options[:protocol] = :https
Rails.application.routes.url_helpers.app_app_file_download_url(app, self, url_options)
end
end end
unless @latest_ios.nil?
json.ios do
json.(@latest_ios, :version, :itms_services_url)
end
end
unless @latest_android.nil?
json.android do
json.(@latest_android, :version, :archive_url)
end
end
...@@ -14,10 +14,10 @@ ...@@ -14,10 +14,10 @@
<p><%= simple_format @app.description %></p> <p><%= simple_format @app.description %></p>
<% if @latest_ios %> <% if @latest_ios %>
<p data-no-turbolink> <p data-no-turbolink>
<a class="btn btn-primary btn-sm btn-download" href="itms-services://?action=download-manifest&url=<%= app_app_file_download_url(@app, @latest_ios, protocol: 'https', format: :plist) %>"> <%= link_to @latest_ios.itms_services_url, class: 'btn btn-primary btn-sm btn-download' do %>
<span class='download-icon'><%= image_tag 'download-icon.png', :size => '17x17' %></span> <span class='download-icon'><%= image_tag 'download-icon.png', :size => '17x17' %></span>
<span>Install on iPhone</span> <span>Install on iPhone</span>
</a> <% end %>
<p><strong>If this is your first download to iOS 9 or later:</strong> After you download one of our apps on iOS, go to Settings app, tap General > Profile. &nbsp;Under Enterprise App, tap Duke University, and then tap Trust Duke University.</p> <p><strong>If this is your first download to iOS 9 or later:</strong> After you download one of our apps on iOS, go to Settings app, tap General > Profile. &nbsp;Under Enterprise App, tap Duke University, and then tap Trust Duke University.</p>
</p> </p>
<% end %> <% end %>
......
Rails.application.routes.draw do Rails.application.routes.draw do
# devise_for :users
resources :apps do resources :apps do
member do
get 'latest_version'
end
resources :app_files do resources :app_files do
get 'build_log' get 'build_log'
get 'download' get 'download'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment