Class: Cloudfuji::EnvsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/cloudfuji/envs_controller.rb

Instance Method Summary collapse

Instance Method Details

#updateObject

PUT /cloudfuji/envs/:id



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/cloudfuji/envs_controller.rb', line 4

def update
  if ENV["CLOUDFUJI_APP_KEY"] != params[:key] or params[:id] == "CLOUDFUJI_KEY"
    respond_to do |format|
      format.html { render :layout => false, :text => true, :status => :forbidden }
      format.json { render :json => {:error => "Not authorized to submit data to this app" }, :status => :unprocessable_entity }
    end

  else

    var = params[:id].upcase

    ENV[var] = params[:value]
    @value = ENV[var]
    
    respond_to do |format|
      if @value != ENV[var]
        format.html{render :layout => false, :text => true, :status => :unprocessable_entity}
        format.json{render :status => :unprocessable_entity}
      else
        Cloudfuji::Data.fire(var, {var => ENV[var]})
        format.html{render :text => true}
        format.json{render :json => {var => ENV[var]}}
      end
    end
  end
end