Sha256: a9bf112c49c966c8264f1a7fe032d1add8afc6dd458c5faef9202b66d192d241

Contents?: true

Size: 1.08 KB

Versions: 7

Compression:

Stored size: 1.08 KB

Contents

require 'public_suffix'

module RestPack
  module Web
    class Context
      attr_accessor :domain, :application, :channel, :user
      
      def initialize(env)    
        restpack = env[:restpack]

        if restpack
          @domain = restpack[:domain]
          @application = restpack[:application]
          @channel = restpack[:channel]
          @user = restpack[:user]
        end
      end

      def is_authenticated?
        @user.present?
      end

      def home_domain #TODO: GJ: can be overridden in config
        "www.#{root_domain}"
      end

      def auth_domain #TODO: GJ: can be overridden in config
        "auth.#{root_domain}"
      end

      def logout_url(next_url = nil)
        next_url ||= "http://#{home_domain}/"
        "http://#{auth_domain}/auth/logout?next=#{next_url}"
      end

      def login_url(provider=:twitter, next_url = nil)
        next_url ||= "http://#{home_domain}/"
        "http://#{auth_domain}/auth/#{provider}?next=#{next_url}"
      end

      def root_domain
        PublicSuffix.parse(@domain.host).domain
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
restpack-web-0.1.35 lib/restpack-web/context.rb
restpack-web-0.1.34 lib/restpack-web/context.rb
restpack-web-0.1.33 lib/restpack-web/context.rb
restpack-web-0.1.32 lib/restpack-web/context.rb
restpack-web-0.1.31 lib/restpack-web/context.rb
restpack-web-0.1.30 lib/restpack-web/context.rb
restpack-web-0.1.29 lib/restpack-web/context.rb