Sha256: 7718c8262fc189cc781436afae1f157137c6eed8c3e968a19ce3681504e6295e

Contents?: true

Size: 930 Bytes

Versions: 16

Compression:

Stored size: 930 Bytes

Contents

require 'devise_token_auth'

module Xing
  module Controllers
    class Base < ActionController::Base
      include DeviseTokenAuth::Concerns::SetUserByToken

      respond_to :json

      protect_from_forgery
      before_filter :check_format

      def check_format
        if request.subdomains.include? Xing.backend_subdomain
          if request.headers["Accept"] =~ /json/
            params[:format] = :json
          else
            render :nothing => true, :status => 406
          end
        end
      end

      def json_body
        @json_body ||= request.body.read
      end

      def parse_json
        @parsed_json ||= JSON.parse(json_body)
      end

      def failed_to_process(error_document)
        render :status => 422, :json => error_document
      end

      def successful_create(new_resource_path)
        render :status => 201, :json => {}, :location => new_resource_path
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
xing-backend-1.0.0.pre.beta lib/xing/controllers/base.rb
xing-backend-0.0.25 lib/xing/controllers/base.rb
xing-backend-0.0.23 lib/xing/controllers/base.rb
xing-backend-0.0.22 lib/xing/controllers/base.rb
xing-backend-0.0.21 lib/xing/controllers/base.rb
xing-backend-0.0.20 lib/xing/controllers/base.rb
xing-backend-0.0.19 lib/xing/controllers/base.rb
xing-backend-0.0.18 lib/xing/controllers/base.rb
xing-backend-0.0.17 lib/xing/controllers/base.rb
xing-backend-0.0.16 lib/xing/controllers/base.rb
xing-backend-0.0.15 lib/xing/controllers/base.rb
xing-backend-0.0.14 lib/xing/controllers/base.rb
xing-backend-0.0.13 lib/xing/controllers/base.rb
xing-backend-0.0.12 lib/xing/controllers/base.rb
xing-backend-0.0.11 lib/xing/controllers/base.rb
xing-backend-0.0.10 lib/xing/controllers/base.rb