Class: Uploader

Inherits:
Object
  • Object
show all
Defined in:
app/uploader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hostname, framework, session_dir, state_reader = StateReader.new(ShellWrapper.new)) ⇒ Uploader

Returns a new instance of Uploader.



12
13
14
15
16
17
18
# File 'app/uploader.rb', line 12

def initialize hostname, framework, session_dir, state_reader = StateReader.new(ShellWrapper.new)
 @states = []
@hostname = hostname
 @framework = framework
  @state_reader = state_reader
  @state_reader.session_dir = session_dir
end

Instance Attribute Details

#statesObject (readonly)

Returns the value of attribute states.



10
11
12
# File 'app/uploader.rb', line 10

def states
  @states
end

Instance Method Details

#read_statesObject



33
34
35
36
37
38
# File 'app/uploader.rb', line 33

def read_states
  @state_reader.reset
  while @state_reader.has_next_state
    @states << @state_reader.read_next_state
  end
end

#uploadObject



20
21
22
23
# File 'app/uploader.rb', line 20

def upload
  return upload_kata_and_states if @state_reader.enough_states?
  return "You need at least two states"
end

#upload_kataObject



40
41
42
43
44
45
46
# File 'app/uploader.rb', line 40

def upload_kata
kata_data = {:framework => @framework}
states_data = states.each_with_index do |state,index|
  kata_data["states[#{index}]"] = {:code => state.code, :result => state.result, :created_at => state.time}
end
  RestClient.post "#{@hostname}#{@@kata_path}", kata_data
end

#upload_kata_and_statesObject



25
26
27
28
29
30
31
# File 'app/uploader.rb', line 25

def upload_kata_and_states
read_states
  kata = upload_kata
finish_url = "#{@hostname}#{@@description_path}/#{XMLElementExtractor.extract('kata/uuid', kata)}"
summary_url = XMLElementExtractor.extract('kata/short-url', kata)
  "Complete kata information at #{finish_url}"
end