Sha256: e8bad2ac67139ea549a04cb4b13290bf82c0dd9f5047e7cf3065c864e71c99d9

Contents?: true

Size: 971 Bytes

Versions: 26

Compression:

Stored size: 971 Bytes

Contents

require 'jwt'

module ForestLiana
  class ApplicationController < ActionController::Base
    before_filter :authenticate_user_from_jwt

    def serialize_model(model, options = {})
      options[:is_collection] = false
      JSONAPI::Serializer.serialize(model, options)
    end

    def serialize_models(models, options = {})
      options[:is_collection] = true
      json = JSONAPI::Serializer.serialize(models, options)

      if options[:count]
        json[:meta] = {} unless json[:meta]
        json[:meta][:count] = options[:count]
      end

      if !options[:has_more].nil?
        json[:meta] = {} unless json[:meta]
        json[:meta][:has_more] = options[:has_more]
      end

      json
    end

    def authenticate_user_from_jwt
      if request.headers['Authorization']
        JWT.decode request.headers['Authorization'].split[1],
          ForestLiana.jwt_signing_key
      else
        render nothing: true, status: 401
      end
    end

  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
forest_liana-1.1.28 app/controllers/forest_liana/application_controller.rb
forest_liana-1.1.27 app/controllers/forest_liana/application_controller.rb
forest_liana-1.1.26 app/controllers/forest_liana/application_controller.rb
forest_liana-1.1.25 app/controllers/forest_liana/application_controller.rb
forest_liana-1.1.23 app/controllers/forest_liana/application_controller.rb
forest_liana-1.1.22 app/controllers/forest_liana/application_controller.rb
forest_liana-1.1.20 app/controllers/forest_liana/application_controller.rb
forest_liana-1.1.19 app/controllers/forest_liana/application_controller.rb
forest_liana-1.1.18 app/controllers/forest_liana/application_controller.rb
forest_liana-1.1.17 app/controllers/forest_liana/application_controller.rb
forest_liana-1.1.16 app/controllers/forest_liana/application_controller.rb
forest_liana-1.1.15 app/controllers/forest_liana/application_controller.rb
forest_liana-1.1.14 app/controllers/forest_liana/application_controller.rb
forest_liana-1.1.13 app/controllers/forest_liana/application_controller.rb
forest_liana-1.1.12 app/controllers/forest_liana/application_controller.rb
forest_liana-1.1.11 app/controllers/forest_liana/application_controller.rb
forest_liana-1.1.10 app/controllers/forest_liana/application_controller.rb
forest_liana-1.1.8 app/controllers/forest_liana/application_controller.rb
forest_liana-1.1.7 app/controllers/forest_liana/application_controller.rb
forest_liana-1.1.6 app/controllers/forest_liana/application_controller.rb