Sha256: 4b93d82b51da6940aefd24f864c88c51826b31a4610f26d2e78a6ac8fba5ff3d

Contents?: true

Size: 1.64 KB

Versions: 10

Compression:

Stored size: 1.64 KB

Contents

# encoding: utf-8
module Mutx
  module Routes
    module Api
      module Input
        class Routes < App
          define do
            on post do

              on ":id" do |id|
                $result = basic_auth(env) do |user, pass|
                 user == "inputs" && pass == "InputsAdmin"
                end
                if $result.eql? true
                  Mutx::Support::Log.debug "REFERENCE IS => #{id}"
                  data = req.params.dup
                  data.store("reference", "#{id}")
                  Mutx::Support::Log.debug "DATA TO INPUT IS => #{data}"
                  response = Mutx::API::Input.validate_and_create data
                  Mutx::Support::Log.debug "RESPONSE => #{response}"
                  (res.status = 201
                  res.write "status 201") if response.to_s.include? "success=>true"
                  (res.status = 404
                  res.write "status 404") if response.to_s.include? "success=>false"
                  Mutx::Support::Log.debug "STATUS CODE => #{res.status}"
                else
                 on default do
                   res.status = 401
                   res.headers["WWW-Authenticate"] = 'Basic realm="MyApp"'
                   res.write "status 401"
                   res.write "Access Denied, Mutx don't let you POST without authorization"
                 end
                end
              end
            end

            on get do
              on ":id" do |id|
                output = Mutx::API::Input.get_data(id, query_string.raw)        
                res.write output.to_json
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
mutx-0.2.9 lib/mutx/routes/api_routes/input_routes.rb
mutx-0.2.8 lib/mutx/routes/api_routes/input_routes.rb
mutx-0.2.7 lib/mutx/routes/api_routes/input_routes.rb
mutx-0.2.6 lib/mutx/routes/api_routes/input_routes.rb
mutx-0.2.5 lib/mutx/routes/api_routes/input_routes.rb
mutx-0.2.4 lib/mutx/routes/api_routes/input_routes.rb
mutx-0.2.3 lib/mutx/routes/api_routes/input_routes.rb
mutx-0.2.2 lib/mutx/routes/api_routes/input_routes.rb
mutx-0.2.1 lib/mutx/routes/api_routes/input_routes.rb
mutx-0.2.0 lib/mutx/routes/api_routes/input_routes.rb