Class: TestSwarm::Project
- Inherits:
-
Object
- Object
- TestSwarm::Project
- Defined in:
- lib/testswarm/project.rb
Defined Under Namespace
Classes: SubmissionFailed
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(client, name, options = {}) ⇒ Project
constructor
A new instance of Project.
- #payload(job, params = {}) ⇒ Object
- #submit_job(name, job, options = {}) ⇒ Object
Constructor Details
#initialize(client, name, options = {}) ⇒ Project
8 9 10 11 12 |
# File 'lib/testswarm/project.rb', line 8 def initialize(client, name, = {}) @client = client @name = name = end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/testswarm/project.rb', line 6 def name @name end |
Instance Method Details
#payload(job, params = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/testswarm/project.rb', line 14 def payload(job, params = {}) cgi = { 'action' => 'addjob', 'authUsername' => @name, 'authToken' => [:auth], 'jobName' => params[:name], 'runMax' => params[:max] || DEFAULT_MAX } query = '' cgi.keys.sort.each do |key| query += '&' unless query.empty? query += "#{key}=#{escape cgi[key]}" end browsers = [params[:browsers] || DEFAULT_BROWSERS].flatten browsers.each do |browser| query += "&browserSets[]=#{escape browser}" end job.each_suite do |name, url| query += "&runNames[]=#{escape name}&runUrls[]=#{escape url}" end query end |
#submit_job(name, job, options = {}) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/testswarm/project.rb', line 40 def submit_job(name, job, = {}) job.inject_script(@client.url + INJECT_SCRIPT) http = Net::HTTP.start(@client.uri.host, @client.uri.port) data = payload(job, job_params(name, )) job.log "POST #{@client.url} #{data}" response = http.post('/api.php', data) job.log "Response: #{response.body}" job_data = JSON.parse(response.body)['addjob'] rescue nil unless job_data job.log 'Job submission failed' job.log response.body return nil end job.log "Job ID: #{job_data['id']}" job.log "Runs: #{job_data['runTotal']}, user agents: #{job_data['uaTotal']}" job_data['id'].to_s rescue => e job.log 'Job submission failed' job.log e. job.log e.backtrace end |