Class: Uploader
- Inherits:
-
Object
- Object
- Uploader
- Defined in:
- lib/upload/uploader.rb
Instance Attribute Summary collapse
-
#framework ⇒ Object
Returns the value of attribute framework.
-
#states ⇒ Object
readonly
Returns the value of attribute states.
Instance Method Summary collapse
-
#initialize(hostname, framework, session_dir, state_reader = StateReader.new(ShellWrapper.new)) ⇒ Uploader
constructor
A new instance of Uploader.
- #read_states ⇒ Object
- #session_dir=(dir) ⇒ Object
- #upload ⇒ Object
- #upload_kata ⇒ Object
- #upload_kata_and_states ⇒ Object
- #upload_zipped_kata(zip_file_name) ⇒ Object
- #upload_zipped_session ⇒ Object
- #zip_kata ⇒ Object
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
#framework ⇒ Object
Returns the value of attribute framework.
15 16 17 |
# File 'lib/upload/uploader.rb', line 15 def framework @framework end |
#states ⇒ Object (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_states ⇒ Object
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 |
#upload ⇒ Object
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_kata ⇒ Object
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_states ⇒ Object
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_session ⇒ Object
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_kata ⇒ Object
65 66 67 |
# File 'lib/upload/uploader.rb', line 65 def zip_kata SessionZipper.new.compress @session_dir end |