Class: Uploader

Inherits:
Object
  • Object
show all
Defined in:
lib/upload/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.



17
18
19
20
21
22
23
# File 'lib/upload/uploader.rb', line 17

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

#frameworkObject

Returns the value of attribute framework.



15
16
17
# File 'lib/upload/uploader.rb', line 15

def framework
  @framework
end

#statesObject (readonly)

Returns the value of attribute states.



14
15
16
# File 'lib/upload/uploader.rb', line 14

def states
  @states
end

Instance Method Details

#read_statesObject



42
43
44
45
46
47
# File 'lib/upload/uploader.rb', line 42

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

#session_dir=(dir) ⇒ Object



25
26
27
28
# File 'lib/upload/uploader.rb', line 25

def session_dir= dir
	@session_dir = dir
	@state_reader.session_dir = dir
end

#uploadObject



30
31
32
33
# File 'lib/upload/uploader.rb', line 30

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

#upload_kataObject



49
50
51
52
53
54
55
56
57
58
# File 'lib/upload/uploader.rb', line 49

def upload_kata
adjuster = EncodingAdjuster.new
kata_data = {:framework => @framework}
states_data = states.each_with_index do |state,index|
	kata_data["states[#{index}]"] = {:code => state.file_contents.collect{|content| adjuster.adjust(content)}, 
      :result => adjuster.adjust(state.result), :green => state.green?, 
		:created_at => state.time}
end
  RestClient.post "#{@hostname}#{@@kata_path}", kata_data
end

#upload_kata_and_statesObject



35
36
37
38
39
40
# File 'lib/upload/uploader.rb', line 35

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

#upload_zipped_kata(zip_file_name) ⇒ Object



69
70
71
# File 'lib/upload/uploader.rb', line 69

def upload_zipped_kata zip_file_name
 RestClient::Resource.new("#{@hostname}#{@@zipped_kata_path}").post(:transfer => { :path => "kata.zip" }, :upload => File.new(zip_file_name, 'rb'))
end

#upload_zipped_sessionObject



60
61
62
63
# File 'lib/upload/uploader.rb', line 60

def upload_zipped_session
  private_url = upload_zipped_kata zip_kata
   "Complete kata information at #{private_url}"
end

#zip_kataObject



65
66
67
# File 'lib/upload/uploader.rb', line 65

def zip_kata
 SessionZipper.new.compress @session_dir
end