Skip to content

Instantly share code, notes, and snippets.

@horimislime
Created December 1, 2016 00:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save horimislime/cb1f70afc50da9d3e5b98e9f8bbb12a3 to your computer and use it in GitHub Desktop.
Save horimislime/cb1f70afc50da9d3e5b98e9f8bbb12a3 to your computer and use it in GitHub Desktop.
# coding: utf-8
require 'faraday'
require 'faraday_middleware'
require 'json'
require 'open-uri'
require 'plist'
module Fastlane
module Actions
class DownloadHockeyIpaAction < Action
HOST_NAME = 'https://rink.hockeyapp.net'
def self.run(params)
api_token = params[:api_token] || ENV["FL_HOCKEY_API_TOKEN"]
build_number = params[:build_number]
public_identifier = params[:public_identifier]
ipa_path = params[:ipa_path]
conn = Faraday.new(:url => HOST_NAME) do |faraday|
faraday.request :multipart
faraday.request :url_encoded
faraday.response :logger
faraday.adapter Faraday.default_adapter
faraday.headers['X-HockeyAppToken'] = api_token
end
versions = conn.get do |req|
req.url("/api/2/apps/#{public_identifier}/app_versions/")
end
versions_json = JSON.parse(versions.body)
versions_json['app_versions'].each do |version|
if version['version'] == build_number
@version_id = version['id'].to_s
break
end
end
response = conn.get do |req|
req.url "/api/2/apps/#{public_identifier}/app_versions/#{@version_id}"
end
if response.status == 200
result = Plist::parse_xml(response.body)
download_url = result['items'][0]['assets'][0]['url']
File.open(ipa_path, "wb") do |saved_file|
open(download_url, "rb") do |read_file|
saved_file.write(read_file.read)
end
end
UI.success "Successfully downloaded ipa."
else
UI.error "Something went wrong with API request. Status code is #{response.status}"
end
end
def self.description
"Download ipa from HockeyApp"
end
def self.authors
["horimislime"]
end
def self.available_options
[
FastlaneCore::ConfigItem.new(key: :api_token,
env_name: "HOCKEY_API_TOKEN",
description: "API Token for Hockey Access",
optional: false,
type: String,
verify_block: proc do |value|
UI.user_error!("No API token for Hockey given, pass using `api_token: 'token'`") if value.to_s.length == 0
end),
FastlaneCore::ConfigItem.new(key: :public_identifier,
env_name: "PUBLIC_IDENTIFIER_TO_DOWNLOAD_IPA",
description: "Public identifier of the app you want to download",
optional: false,
type: String,
verify_block: proc do |value|
UI.user_error!("No public identifier for Hockey given, pass using `public_identifier: 'public_identifier'`") if value.to_s.length == 0
end),
FastlaneCore::ConfigItem.new(key: :ipa_path,
env_name: "IPA_DOWNLOAD_PATH",
description: "Path to your symbols file",
optional: false,
type: String,
default_value: File.expand_path('.')),
FastlaneCore::ConfigItem.new(key: :build_number,
env_name: "IPA_BUILD_NUMBER",
description: "The build number for the ipa you want to download",
optional: false,
type: String)
]
end
def self.is_supported?(platform)
[:ios, :tvos, :osx, :watchos].include?(platform)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment