Class: CF::Run
Instance Attribute Summary collapse
-
#errors ⇒ Object
Contains Error Message if any.
-
#file ⇒ Object
File attribute to upload for Production Run.
-
#input ⇒ Object
Input to be passed for Production Run.
-
#line ⇒ Object
Line attribute with which run is associated.
-
#title ⇒ Object
Title of the “run” object.
Class Method Summary collapse
-
.add_units(options = {}) ⇒ Object
Adds units to an existing production Run ===Usage Example: units = CF::Run.add_units(=> “title”, :file => “path_of_file”).
-
.all(options = {}) ⇒ Object
Returns all runs of a line ===Usage Example: progress = CF::Run.all({:line_title => “line_title”, :page => 1).
-
.create(line, title, file) ⇒ Object
Creates a new Run ===Usage Example:.
-
.final_output(title) ⇒ Object
Returns Final Output of production Run ===Usage Example: CF::Run.final_output(“run_title”).
-
.find(title) ⇒ Object
Searches Run for the given “run_title” ===Usage Example: CF::Run.find(“run_title”).
-
.output(options = {}) ⇒ Object
Returns Output of production Run for any specific Station and for given Run Title ===Usage Example: CF::Run.output(=> “run_title”, :station => 2) Will return output of second station.
-
.progress(run_title) ⇒ Object
Returns progress of the production run ===Usage Example: progress = CF::Run.progress(“run_title”).
-
.progress_details(run_title) ⇒ Object
Returns progress details of the production run ===Usage Example: progress = CF::Run.progress_details(“run_title”).
-
.resume(run_title) ⇒ Object
Resumes the paused production run ===Usage Example: resume_run = CF::Run.resume(“run_title”).
Instance Method Summary collapse
-
#final_output ⇒ Object
Returns Final Output of production Run ===Usage Example: run_object.final_output.
-
#initialize(line, title, input) ⇒ Run
constructor
Initializes a new Run ===Usage Example:.
-
#output(options = {}) ⇒ Object
Returns Output of Run object for any specific Station ===Usage Example: run_object.output(:station => 2) Will return output of second station.
-
#progress ⇒ Object
:nodoc:.
-
#progress_details ⇒ Object
:nodoc:.
Constructor Details
#initialize(line, title, input) ⇒ Run
Initializes a new Run
Usage Example:
run = CF::Run.new("line_title", "run name", file_path)
OR
You can pass line object instead of passing line title:
run = CF::Run.new(line_object, "run name", file_path)
29 30 31 32 33 34 35 36 37 38 39 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 68 69 70 71 72 73 74 75 |
# File 'lib/cf/run.rb', line 29 def initialize(line, title, input) if line.class == CF::Line || line.class == Hashie::Mash @line = line @line_title = line.title elsif line.class == String if line.split("/").count == 2 @account = line.split("/").first @line_title = line.split("/").last elsif line.split("/").count == 1 @line_title = line end end @title = title if File.exist?(input.to_s) @file = input @param_data = File.new(input, 'rb') @param_for_input = :file if line.class == String && line.split("/").count == 2 resp = self.class.post("/lines/#{@account}/#{@line_title.downcase}/runs.json", {:data => {:run => {:title => @title}}, @param_for_input => @param_data}) else resp = self.class.post("/lines/#{CF.account_name}/#{@line_title.downcase}/runs.json", {:data => {:run => {:title => @title}}, @param_for_input => @param_data}) end if resp.code != 200 self.errors = resp.error. end else @input = input @param_data = input @param_for_input = :inputs = { :body => { :api_key => CF.api_key, :data =>{:run => { :title => @title }, :inputs => @param_data} } } if line.class == String && line.split("/").count == 2 run = HTTParty.post("#{CF.api_url}#{CF.api_version}/lines/#{@account}/#{@line_title.downcase}/runs.json",) else run = HTTParty.post("#{CF.api_url}#{CF.api_version}/lines/#{CF.account_name}/#{@line_title.downcase}/runs.json",) end if run.code != 200 self.errors = run.parsed_response['error']['message'] end end end |
Instance Attribute Details
#errors ⇒ Object
Contains Error Message if any
19 20 21 |
# File 'lib/cf/run.rb', line 19 def errors @errors end |
#file ⇒ Object
File attribute to upload for Production Run
10 11 12 |
# File 'lib/cf/run.rb', line 10 def file @file end |
#input ⇒ Object
Input to be passed for Production Run
13 14 15 |
# File 'lib/cf/run.rb', line 13 def input @input end |
#line ⇒ Object
Line attribute with which run is associated
16 17 18 |
# File 'lib/cf/run.rb', line 16 def line @line end |
#title ⇒ Object
Title of the “run” object
7 8 9 |
# File 'lib/cf/run.rb', line 7 def title @title end |
Class Method Details
.add_units(options = {}) ⇒ Object
Adds units to an existing production Run
Usage Example:
units = CF::Run.add_units({:run_title => "title", :file => "path_of_file"})
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/cf/run.rb', line 92 def self.add_units(={}) units = [:units].presence run_title = [:run_title].presence file = [:file].presence if units request = { :body => { :api_key => CF.api_key, :data => units } } resp = HTTParty.post("#{CF.api_url}#{CF.api_version}/runs/#{CF.account_name}/#{run_title.downcase}/units.json",request) @errors = resp['error']['message'] if resp.code != 200 return resp.parsed_response elsif file if File.exist?(file.to_s) file_upload = File.new(file, 'rb') resp = post("/runs/#{CF.account_name}/#{run_title.downcase}/units.json", {:file => file_upload}) @errors = resp.error. if resp.code != 200 return resp.to_hash end end end |
.all(options = {}) ⇒ Object
Returns all runs of a line
Usage Example:
progress = CF::Run.all({:line_title => "line_title", :page => 1)
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/cf/run.rb', line 223 def self.all(={}) page = [:page].presence line_title = [:line_title].presence if line_title.nil? if page.nil? resp = get("/runs/#{CF.account_name}.json") else resp = get("/runs/#{CF.account_name}.json", :page => page) end else if page.nil? resp = get("/lines/#{CF.account_name}/#{line_title}/list_runs.json") else resp = get("/lines/#{CF.account_name}/#{line_title}/list_runs.json", :page => page) end end if resp.code != 200 send_resp = {"error" => resp.error.} return send_resp end new_resp = [] if resp.code == 200 if resp.runs if resp.runs.count > 0 resp.runs.each do |r| new_resp << r.to_hash end end end send_resp = {"runs" => new_resp, "total_pages" => resp.total_pages, "total_runs" => resp.total_runs} return send_resp end end |
.create(line, title, file) ⇒ Object
Creates a new Run
Usage Example:
run = CF::Run.new("line_title", "run name", file_path)
OR
You can pass line object instead passing line title:
run = CF::Run.new(line_object, "run name", file_path)
85 86 87 |
# File 'lib/cf/run.rb', line 85 def self.create(line, title, file) Run.new(line, title, file) end |
.final_output(title) ⇒ Object
Returns Final Output of production Run
Usage Example:
CF::Run.final_output("run_title")
135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/cf/run.rb', line 135 def self.final_output(title) resp = get("/runs/#{CF.account_name}/#{title.downcase}/output.json") @errors = resp.error. if resp.code != 200 output = [] if resp['output'].class == Array resp['output'].each do |o| output << o.to_hash end end return output end |
.find(title) ⇒ Object
Searches Run for the given “run_title”
Usage Example:
CF::Run.find("run_title")
185 186 187 188 189 190 191 192 193 194 |
# File 'lib/cf/run.rb', line 185 def self.find(title) resp = get("/runs/#{CF.account_name}/#{title.downcase}.json") if resp.code != 200 @errors = resp.error. resp.error = resp.error. resp.merge!(:errors => "#{resp.error}") resp.delete(:error) end return resp end |
.output(options = {}) ⇒ Object
Returns Output of production Run for any specific Station and for given Run Title
Usage Example:
CF::Run.output({:title => "run_title", :station => 2})
Will return output of second station
151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/cf/run.rb', line 151 def self.output(={}) station_no = [:station] title = [:title] resp = get("/runs/#{CF.account_name}/#{title.downcase}/output/#{station_no}.json") @errors = resp.error. if resp.code != 200 output = [] if resp['output'].class == Array resp['output'].each do |o| output << o.to_hash end end return output end |
.progress(run_title) ⇒ Object
Returns progress of the production run
Usage Example:
progress = CF::Run.progress("run_title")
199 200 201 |
# File 'lib/cf/run.rb', line 199 def self.progress(run_title) get("/runs/#{CF.account_name}/#{run_title}/progress.json") end |
.progress_details(run_title) ⇒ Object
Returns progress details of the production run
Usage Example:
progress = CF::Run.progress_details("run_title")
210 211 212 213 |
# File 'lib/cf/run.rb', line 210 def self.progress_details(run_title) resp = get("/runs/#{CF.account_name}/#{run_title}/details.json") return resp['progress_details'] end |
.resume(run_title) ⇒ Object
Resumes the paused production run
Usage Example:
resume_run = CF::Run.resume("run_title")
263 264 265 266 267 |
# File 'lib/cf/run.rb', line 263 def self.resume(run_title) resp = post("/runs/#{CF.account_name}/#{run_title}/resume.json") @errors = resp.error. if resp.code != 200 return resp end |
Instance Method Details
#final_output ⇒ Object
Returns Final Output of production Run
Usage Example:
run_object.final_output
120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/cf/run.rb', line 120 def final_output resp = self.class.get("/runs/#{CF.account_name}/#{self.title.downcase}/output.json") self.errors = resp.error. if resp.code != 200 output = [] if resp['output'].class == Array resp['output'].each do |o| output << o.to_hash end end return output end |
#output(options = {}) ⇒ Object
Returns Output of Run object for any specific Station
Usage Example:
run_object.output(:station => 2)
Will return output of second station
169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/cf/run.rb', line 169 def output(={}) station_no = [:station] resp = self.class.get("/runs/#{CF.account_name}/#{self.title.downcase}/output/#{station_no}.json") self.errors = resp.error. if resp.code != 200 output = [] if resp['output'].class == Array resp['output'].each do |o| output << o.to_hash end end return output end |
#progress ⇒ Object
:nodoc:
203 204 205 |
# File 'lib/cf/run.rb', line 203 def progress # :nodoc: self.class.get("/runs/#{CF.account_name}/#{self.title}/progress.json") end |
#progress_details ⇒ Object
:nodoc:
215 216 217 218 |
# File 'lib/cf/run.rb', line 215 def progress_details # :nodoc: resp = self.class.get("/runs/#{CF.account_name}/#{self.title}/details.json") return resp['progress_details'] end |