Class: BrowserStack::LocalBinary
- Inherits:
-
Object
- Object
- BrowserStack::LocalBinary
- Defined in:
- lib/browserstack/localbinary.rb
Instance Method Summary collapse
- #binary_path ⇒ Object
- #download(dest_parent_dir) ⇒ Object
-
#initialize ⇒ LocalBinary
constructor
A new instance of LocalBinary.
- #verify_binary(binary_path) ⇒ Object
Constructor Details
#initialize ⇒ LocalBinary
Returns a new instance of LocalBinary.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/browserstack/localbinary.rb', line 11 def initialize host_os = RbConfig::CONFIG['host_os'] @http_path = case host_os when /mswin|msys|mingw|cygwin|bccwin|wince|emc/ @windows = true "https://www.browserstack.com/local-testing/downloads/binaries/BrowserStackLocal.exe" when /darwin|mac os/ "https://www.browserstack.com/local-testing/downloads/binaries/BrowserStackLocal-darwin-x64" when /linux-musl/ "https://www.browserstack.com/local-testing/downloads/binaries/BrowserStackLocal-alpine" when /linux/ if 1.size == 8 "https://www.browserstack.com/local-testing/downloads/binaries/BrowserStackLocal-linux-x64" else "https://www.browserstack.com/local-testing/downloads/binaries/BrowserStackLocal-linux-ia32" end end @ordered_paths = [ File.join(File.('~'), '.browserstack'), Dir.pwd, Dir.tmpdir ] end |
Instance Method Details
#binary_path ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/browserstack/localbinary.rb', line 62 def binary_path dest_parent_dir = get_available_dirs binary_path = File.join(dest_parent_dir, "BrowserStackLocal#{".exe" if @windows}") if File.exist? binary_path binary_path else binary_path = download(dest_parent_dir) end valid_binary = verify_binary(binary_path) if valid_binary binary_path else binary_path = download(dest_parent_dir) valid_binary = verify_binary(binary_path) if valid_binary binary_path else raise BrowserStack::LocalException.new('BrowserStack Local binary is corrupt') end end end |
#download(dest_parent_dir) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/browserstack/localbinary.rb', line 36 def download(dest_parent_dir) unless File.exist? dest_parent_dir Dir.mkdir dest_parent_dir end uri = URI.parse(@http_path) binary_path = File.join(dest_parent_dir, "BrowserStackLocal#{".exe" if @windows}") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE res = http.get(uri.path) file = open(binary_path, 'wb') file.write(res.body) file.close FileUtils.chmod 0755, binary_path binary_path end |
#verify_binary(binary_path) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/browserstack/localbinary.rb', line 55 def verify_binary(binary_path) binary_response = IO.popen(binary_path + " --version").readline binary_response =~ /BrowserStack Local version \d+\.\d+/ rescue Exception => e false end |