lib/burndown_chart.rb in trollolo-0.0.6 vs lib/burndown_chart.rb in trollolo-0.0.7

- old
+ new

@@ -104,10 +104,34 @@ rescue Errno::ENOENT raise TrolloloError.new( "'#{filename}' not found" ) end end + + # Writes a POST request to url + def push_to_api(url, burndown_data) + + url = url.gsub(':sprint', sprint.to_s) + .gsub(':board', board_id.to_s) + + begin + uri = URI.parse(url) + push = Net::HTTP::Post.new(uri.path, { 'Content-Type' => 'application/json' }) + push.body = burndown_data.to_hash.to_json + + Net::HTTP.start(uri.hostname, uri.port) do |http| + http.request(push) + end + rescue StandardError => e + # Instead of catching 20 different exceptions which can be + # thrown by URI and Http::, StandardError is catched. + # Fix this if there is a better solution + raise TrolloloError.new("pushing to endpoint failed: #{e.message}") + end + end + + def burndown_data_filename "burndown-data-#{sprint.to_s.rjust(2,"0")}.yaml" end def setup(burndown_dir, board_id) @@ -176,9 +200,13 @@ write_data(burndown_data_path) if options[:plot] BurndownChart.plot(self.sprint, options) + end + + if options.has_key?('push-to-api') + push_to_api(options['push-to-api'], data) end end def create_next_sprint(burndown_dir) load_last_sprint(burndown_dir)