Class: CF::Run

Inherits:
Object
  • Object
show all
Includes:
Client
Defined in:
lib/cf/run.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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
# File 'lib/cf/run.rb', line 29

def initialize(line, title, input)
  if line.class == CF::Line || Hashie::Mash
    @line = line
    @line_title = @line.title
  else
    @line_title = line
  end
  @title = title
  if File.exist?(input.to_s)
    @file = input
    @param_data = File.new(input, 'rb')
    @param_for_input = :file
    resp = self.class.post("/lines/#{CF.}/#{@line_title.downcase}/runs.json", {:data => {:run => {:title => @title}}, @param_for_input => @param_data})
    if resp.code != 200
      self.errors = resp.error.message
    end
  else
    @input = input
    @param_data = input
    @param_for_input = :inputs
    options = 
    {
      :body => 
      {
        :api_key => CF.api_key,
        :data =>{:run => { :title => @title }, :inputs => @param_data}
      }
    }
    run =  HTTParty.post("#{CF.api_url}#{CF.api_version}/lines/#{CF.}/#{@line_title.downcase}/runs.json",options)
    if run.code != 200
      self.errors = run.parsed_response['error']['message']
    end
  end
end

Instance Attribute Details

#errorsObject

Contains Error Message if any



19
20
21
# File 'lib/cf/run.rb', line 19

def errors
  @errors
end

#fileObject

File attribute to upload for Production Run



10
11
12
# File 'lib/cf/run.rb', line 10

def file
  @file
end

#inputObject

Input to be passed for Production Run



13
14
15
# File 'lib/cf/run.rb', line 13

def input
  @input
end

#lineObject

Line attribute with which run is associated



16
17
18
# File 'lib/cf/run.rb', line 16

def line
  @line
end

#titleObject

Title of the “run” object



7
8
9
# File 'lib/cf/run.rb', line 7

def title
  @title
end

Class Method Details

.all(line_title = nil) ⇒ Object



155
156
157
158
159
160
161
# File 'lib/cf/run.rb', line 155

def self.all(line_title=nil)
  if line_title.blank?
    get("/runs/#{CF.}.json")
  else
    get("/lines/#{CF.}/#{line_title}/list_runs.json")
  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)


72
73
74
# File 'lib/cf/run.rb', line 72

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")


98
99
100
101
# File 'lib/cf/run.rb', line 98

def self.final_output(title)
  resp = get("/runs/#{CF.}/#{title.downcase}/output.json")
  return resp['output']
end

.find(title) ⇒ Object

Searches Run for the given “run_title”

Usage Example:

CF::Run.find("run_title")


127
128
129
130
131
132
133
134
135
# File 'lib/cf/run.rb', line 127

def self.find(title)
  resp = get("/runs/#{CF.}/#{title.downcase}.json")
  if resp.code != 200
    resp.error = resp.error.message
    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



107
108
109
110
111
112
# File 'lib/cf/run.rb', line 107

def self.output(options={})
  station_no = options[:station]
  title = options[:title]
  resp = get("/runs/#{CF.}/#{title.downcase}/output/#{station_no}.json")
  return resp['output']
end

.progress(run_title) ⇒ Object



137
138
139
# File 'lib/cf/run.rb', line 137

def self.progress(run_title)
  get("/runs/#{CF.}/#{run_title}/progress.json")
end

.progress_details(run_title) ⇒ Object



145
146
147
148
# File 'lib/cf/run.rb', line 145

def self.progress_details(run_title)
  resp = get("/runs/#{CF.}/#{run_title}/details.json")
  return resp['progress_details']
end

.resume(run_title) ⇒ Object



163
164
165
# File 'lib/cf/run.rb', line 163

def self.resume(run_title)
  post("/runs/#{CF.}/#{run_title}/resume.json")
end

Instance Method Details

#final_outputObject

Returns Final Output of production Run

Usage Example:

run_object.final_output


79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/cf/run.rb', line 79

def final_output
  resp = self.class.get("/runs/#{CF.}/#{self.title.downcase}/output.json")
  @final_output =[]
  resp['output'].each do |r|
    result = FinalOutput.new()
    r.to_hash.each_pair do |k,v|
      result.send("#{k}=",v) if result.respond_to?(k)
    end
    if result.final_output == nil
      result.final_output = resp.output
    end
    @final_output << result
  end
  return @final_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



118
119
120
121
122
# File 'lib/cf/run.rb', line 118

def output(options={})
  station_no = options[:station]
  resp = self.class.get("/runs/#{CF.}/#{self.title.downcase}/output/#{station_no}.json")
  return resp['output'].first.to_hash
end

#progressObject



141
142
143
# File 'lib/cf/run.rb', line 141

def progress
  self.class.get("/runs/#{CF.}/#{self.title}/progress.json")
end

#progress_detailsObject



150
151
152
153
# File 'lib/cf/run.rb', line 150

def progress_details
  resp = self.class.get("/runs/#{CF.}/#{self.title}/details.json")
  return resp['progress_details']
end