require 'rest-client' require 'open-uri' class Remote def initialize if ENV['FLUTTER_BINARY_SERVER_BASEURL'].nil? raise StandardError, "Need 'FLUTTER_BINARY_SERVER_BASEURL' in env" end @base_url = ENV['FLUTTER_BINARY_SERVER_BASEURL'] end def exist?(name, version, tag) uri = URI.join @base_url, "/frameworks/exit/#{name}/#{version}/#{tag}" resp = RestClient.get(uri.to_s) json = JSON.parse(resp.body) json["data"] end def delete(name, version, tag) uri = URI.join @base_url, "/frameworks/#{name}/#{version}/#{tag}" resp = RestClient.delete uri.to_s json = JSON.parse(resp.body) json["status"]['code'] == 0 end def upload(name, version, tag, file) uri = URI.join @base_url, "/frameworks" resp = RestClient.post(uri.to_s, { file: File.new(file, 'rb'), name: name, version: version, tag: tag }) json = JSON.parse(resp.body) @base_url + json["data"]['download_url'] end def download_url(name, version, tag) uri = URI.join @base_url, "/frameworks/#{name}/#{version}/#{tag}" resp = RestClient.get uri.to_s json = JSON.parse(resp.body) @base_url + json["data"]['download_url'] end def download_flutter_sdk_dsym(version, hash, des_path) uri = URI.join @base_url, "/dsyms/download/flutter/#{version}/#{hash}/file.zip" Pod::UserInterface.info "Start download Flutter.framework.dSYM from #{uri.to_s}" data = RestClient::Request.execute(:method => :get, :url => uri.to_s, :timeout => 3600, :raw_response => true) file = File.new(des_path, 'w+') file.write data file.close end def upload_flutter_sdk_dsym(version, hash, file_path) uri = URI.join @base_url, "/dsyms" Pod::UserInterface.info "Start upload '#{file_path}' to #{uri.to_s}" req = RestClient::Request.new( :method => :post, :url => uri.to_s, :timeout => 3600, :payload => { :multipart => true, :file => File.new(file_path, 'rb'), :name => 'flutter', :version => version, :tag => hash } ) req.execute end end