- migrated software.o.o to rails 2
[opensuse:software-o-o.git] / app / controllers / main_controller.rb
1 require 'net/http'
2
3 class MainController < ApplicationController
4   verify :only => :ymp, :params => [:project, :repository, :arch, :binary],
5     :redirect_to => :index
6
7   def index
8   end
9
10   def developer
11   end
12
13   def old_dist
14     dist = params[:dist]
15     begin
16       render :template => "main/old_#{dist}.rhtml"
17     rescue Object
18       @message = "No old page found for dist #{10.2}"
19       render :template => "error", :status => 404
20     end
21   end
22
23   def ymp_with_arch_and_version
24     path = "/published/#{params[:project]}/#{params[:repository]}/#{params[:arch]}/#{params[:binary]}?view=ymp"
25     res = get_from_api(path)
26     render :text => res.body, :content_type => res.content_type
27   end
28
29   def ymp_without_arch_and_version
30     path = "/published/#{params[:project]}/#{params[:repository]}/#{params[:package]}?view=ymp"
31     res = get_from_api(path)
32     render :text => res.body, :content_type => res.content_type
33   end
34
35   private
36   def get_from_api(path)
37     req = Net::HTTP::Get.new(path)
38     req['x-username'] = "obs_read_only"
39
40     host, port = API_HOST.split(/:/)
41     port ||= 80
42     res = Net::HTTP.new(host, port).start do |http|
43       http.request(req)
44     end
45   end
46 end