Sha256: 2ec01672e9ac41671b86d67ddf551fdcf61136066c0953a7182fe81fbdb3363b

Contents?: true

Size: 862 Bytes

Versions: 3

Compression:

Stored size: 862 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
      JWT.decode request.headers['Authorization'].split[1],
        ForestLiana.jwt_signing_key
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
forest_liana-1.0.11 app/controllers/forest_liana/application_controller.rb
forest_liana-1.0.10 app/controllers/forest_liana/application_controller.rb
forest_liana-1.0.8 app/controllers/forest_liana/application_controller.rb