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) ⇒ 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 39 40 |
# File 'lib/ruby_appthwack/appthwack_api.rb', line 35 def download_file(src, dst) File.open(dst, 'w') { |f| f.write(Typhoeus.get(src).body) } return dst end |
.download_results(proj_id, run_id) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/ruby_appthwack/appthwack_api.rb', line 91 def download_results(proj_id, run_id) 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'], "#{proj_id}_#{run_id}.zip" ) if resp.code == 303 end |
.get_device_pool(proj_id, name) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ruby_appthwack/appthwack_api.rb', line 22 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
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/ruby_appthwack/appthwack_api.rb', line 10 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
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/ruby_appthwack/appthwack_api.rb', line 61 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
87 88 89 |
# File 'lib/ruby_appthwack/appthwack_api.rb', line 87 def test_running?(proj_id, run_id) return test_status?( proj_id, run_id ) != 'completed' end |
.test_status?(proj_id, run_id) ⇒ Boolean
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/ruby_appthwack/appthwack_api.rb', line 76 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
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ruby_appthwack/appthwack_api.rb', line 42 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 |