class Fastlane::Actions::SupplyAptoideAction
Public Class Methods
available_options()
click to toggle source
# File lib/fastlane/plugin/supply_aptoide/actions/supply_aptoide_action.rb, line 98 def self.available_options [ FastlaneCore::ConfigItem.new(key: :json_credential_path, env_name: "SUPPLY_APTOIDE_JSON_CREDENTIAL_PATH", short_option: "-c", description: "JSON file containing object with username and password for authentication", verify_block: proc do |value| UI.user_error! "'#{value}' doesn't seem to be a JSON file" unless FastlaneCore::Helper.json_file?(File.expand_path(value)) begin parsed_value = JSON.parse(File.read(File.expand_path(value))) UI.user_error! "JSON must be an object with \"username\" and \"password\" keys" if parsed_value["username"].empty? || parsed_value["password"].empty? rescue JSON::ParserError UI.user_error! "Could not parse Aptoide account json -- JSON::ParseError" end end), FastlaneCore::ConfigItem.new(key: :repo, env_name: "SUPPLY_APTOIDE_REPO", short_option: "-r", description: "User repository name"), FastlaneCore::ConfigItem.new(key: :only_user_repo, env_name: "SUPPLY_APTOIDE_ONLY_USER_REPO", short_option: "-x", optional: true, is_string: false, description: "If true, the application gets uploaded only to the repository given in the repo argument. If false or ommited, the application gets uploaded to the official apps repository as well"), FastlaneCore::ConfigItem.new(key: :apk, env_name: "SUPPLY_APK", description: "Path to the APK file to upload", short_option: "-b", default_value: Dir["*.apk"].last || Dir[File.join("app", "build", "outputs", "apk", "app-Release.apk")].last, verify_block: proc do |value| UI.user_error! "Could not find apk file at path '#{value}'" unless File.exist?(value) UI.user_error! "apk file is not an apk" unless value.end_with?('.apk') end) ] end
description()
click to toggle source
# File lib/fastlane/plugin/supply_aptoide/actions/supply_aptoide_action.rb, line 139 def self.description "Upload metadata, screenshots and binaries to Aptoide." end
details()
click to toggle source
# File lib/fastlane/plugin/supply_aptoide/actions/supply_aptoide_action.rb, line 147 def self.details "Drop-in replacement for supply that uploads to Aptoide instead." end
fetch_aptoid_access_token(username, password)
click to toggle source
# File lib/fastlane/plugin/supply_aptoide/actions/supply_aptoide_action.rb, line 62 def self.fetch_aptoid_access_token(username, password) params = { grant_type: "password", client_id: "Aptoide", mode: "json", username: username, password: password } response = Typhoeus.post( "http://webservices.aptoide.com/webservices/3/oauth2Authentication", headers: { 'Content-Type' => "application/json" }, body: params.to_json ) unless response.success? UI.error "Could not contact Aptoide to fetch access token" return nil end parsed_response = nil begin parsed_response = JSON.parse(response.response_body) rescue JSON::ParserError UI.error "Invalid JSON returned by Apotide access token fetch: #{response.response_body}" return nil end if parsed_response["error"] UI.error "Aptoide access token fetch error: #{parsed_response['error_description']}" return nil end return parsed_response["access_token"] end
is_supported?(platform)
click to toggle source
# File lib/fastlane/plugin/supply_aptoide/actions/supply_aptoide_action.rb, line 135 def self.is_supported?(platform) [:android].include?(platform) end
parse_json_credentials(json_credential_path)
click to toggle source
# File lib/fastlane/plugin/supply_aptoide/actions/supply_aptoide_action.rb, line 57 def self.parse_json_credentials(json_credential_path) parsed = JSON.parse(File.read(File.expand_path(json_credential_path))) return parsed["username"], parsed["password"] end
run(params)
click to toggle source
# File lib/fastlane/plugin/supply_aptoide/actions/supply_aptoide_action.rb, line 7 def self.run(params) repo = params[:repo] only_user_repo = params[:only_user_repo] apk = params[:apk] username, password = self.parse_json_credentials(params[:json_credential_path]) UI.message "Fetching access token..." access_token = self.fetch_aptoid_access_token(username, password) return unless access_token UI.message "Got access token: '#{access_token}', starting upload..." params = { access_token: access_token, repo: repo, mode: "json", apk: File.open(apk, "r") } if only_user_repo params[:only_user_repo] = true end response = Typhoeus.post( "https://webservices.aptoide.com/webservices/3/uploadAppToRepo", body: params ) unless response.success? UI.error "Could not contact Aptoide to upload apk" return end parsed_response = nil begin parsed_response = JSON.parse(response.response_body) rescue JSON::ParserError UI.error "Invalid JSON returned by Apotide apk upload" return end if parsed_response["status"] != "OK" UI.error "Aptoide apk upload errors: #{parsed_response['errors']}" return end UI.message "Successfully uploaded apk to Aptoide: #{parsed_response['url']}" end