lib/play_time/apk.rb in play_time-0.1.0 vs lib/play_time/apk.rb in play_time-0.1.1

- old
+ new

@@ -1,19 +1,34 @@ require 'google/api_client' module PlayTime class Apk + class FileNotFound < StandardError; end + MIME_TYPE = 'application/vnd.android.package-archive'.freeze class << self def load - Google::APIClient::UploadIO.new(path, MIME_TYPE) + Google::APIClient::UploadIO.new(most_recent_modified_file_path, MIME_TYPE) end private - def path + def file_path PlayTime.configuration.apk_path + end + + def most_recent_modified_file_path + @most_recent_modified_file_path ||= + begin + file = Dir[file_path].map{|file_path| File.open(file_path) }.sort_by(&:mtime).last + + if file + file.path + else + raise FileNotFound, "No such file or directory: #{file_path}" + end + end end end end end