Module: AppThwack::API
- Defined in:
- lib/ruby_appthwack/appthwack_api.rb
Class Method Summary collapse
- .download_file(src, dst) ⇒ Object
- .download_results(proj_id, run_id, output) ⇒ Object
- .get_device_pool(proj_id, name) ⇒ Object
- .get_project_id(name) ⇒ Object
- .start_test(name, proj_id, app_id, pool_id, params = {}) ⇒ Object
- .test_running?(proj_id, run_id) ⇒ Boolean
- .test_status?(proj_id, run_id) ⇒ Boolean
- .upload_file(src) ⇒ Object
Class Method Details
.download_file(src, dst) ⇒ Object
35 36 37 38 |
# File 'lib/ruby_appthwack/appthwack_api.rb', line 35 def download_file(src, dst) # We use curl to download the file to avoid running out of RAM return dst if system "curl -X GET '#{src}' -o '#{dst}' --silent" end |
.download_results(proj_id, run_id, output) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/ruby_appthwack/appthwack_api.rb', line 89 def download_results(proj_id, run_id, output) resp = Typhoeus.get( "https://appthwack.com/api/run/#{proj_id}/#{run_id}", userpwd: "#{ENV['APPTHWACK_API_KEY']}:", params: { format: "archive" } ) return ( download_file resp.headers_hash['Location'], output ) if resp.code == 303 end |
.get_device_pool(proj_id, name) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ruby_appthwack/appthwack_api.rb', line 21 def get_device_pool(proj_id, name) res = JSON.parse( Typhoeus.get( "https://appthwack.com/api/devicepool/#{proj_id}", userpwd: "#{ENV['APPTHWACK_API_KEY']}:" ).body ) return (res.select { |pool| pool['name'].eql? name }).first['id'] end |
.get_project_id(name) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/ruby_appthwack/appthwack_api.rb', line 9 def get_project_id(name) res = JSON.parse( Typhoeus.get( "https://appthwack.com/api/project/", userpwd: "#{ENV['APPTHWACK_API_KEY']}:" ).body ) return (res.select { |project| project['name'].eql? name }).first['id'] end |
.start_test(name, proj_id, app_id, pool_id, params = {}) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/ruby_appthwack/appthwack_api.rb', line 59 def start_test(name, proj_id, app_id, pool_id, params = {}) params.merge! project: proj_id, name: name, app: app_id, pool: pool_id res = JSON.parse( Typhoeus.post( "https://appthwack.com/api/run", userpwd: "#{ENV['APPTHWACK_API_KEY']}:", params: params ).body ) return { :run_id => res['run_id'], :succeeded? => res['message'].nil?, :message => res['message'] } end |
.test_running?(proj_id, run_id) ⇒ Boolean
85 86 87 |
# File 'lib/ruby_appthwack/appthwack_api.rb', line 85 def test_running?(proj_id, run_id) return test_status?( proj_id, run_id ) != 'completed' end |
.test_status?(proj_id, run_id) ⇒ Boolean
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/ruby_appthwack/appthwack_api.rb', line 74 def test_status?(proj_id, run_id) res = JSON.parse( Typhoeus.get( "https://appthwack.com/api/run/#{proj_id}/#{run_id}/status", userpwd: "#{ENV['APPTHWACK_API_KEY']}:", ).body ) return res['status'] end |
.upload_file(src) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ruby_appthwack/appthwack_api.rb', line 40 def upload_file(src) f = Dir.glob( src ).first res = JSON.parse( Typhoeus.post( "https://appthwack.com/api/file", userpwd: "#{ENV['APPTHWACK_API_KEY']}:", params: { name: File.basename(f) }, body: { file: File.open(f,"r") } ).body ) return { :file_id => res["file_id"], :succeeded? => res['message'].nil?, :message => res['message'] } end |