restpack-web 0.1.28 → 0.1.29

Sign up to get free protection for your applications and to get access to all the features.
@@ -58,7 +58,7 @@ module RestPack
58
58
  env[:restpack][:user_id] = user_id
59
59
  end
60
60
 
61
- def add_application_domains(env)
61
+ def add_application_domains(env) #TODO: gj move to controller mixin
62
62
  application = env[:restpack][:application]
63
63
 
64
64
  domains = {}
@@ -0,0 +1,47 @@
1
+ require 'public_suffix'
2
+
3
+ module RestPack
4
+ module Web
5
+ class Context
6
+ attr_accessor :domain, :application, :channel, :user
7
+
8
+ def initialize(env)
9
+ restpack = env[:restpack]
10
+
11
+ if restpack
12
+ @domain = restpack[:domain]
13
+ @application = restpack[:application]
14
+ @channel = restpack[:channel]
15
+ @user = restpack[:user]
16
+ end
17
+ end
18
+
19
+ def is_authenticated?
20
+ @user.present?
21
+ end
22
+
23
+ def home_domain #TODO: GJ: can be overridden in config
24
+ "www.#{root_domain}"
25
+ end
26
+
27
+ def auth_domain #TODO: GJ: can be overridden in config
28
+ "auth.#{root_domain}"
29
+ end
30
+
31
+ def logout_url(next_url = nil)
32
+ next_url ||= "http://#{home_domain}/"
33
+ "http://#{auth_domain}/auth/logout?next=#{next_url}"
34
+ end
35
+
36
+ def login_url(provider=:twitter, next_url = nil)
37
+ next_url ||= "http://#{home_domain}/"
38
+ "http://#{auth_domain}/auth/#{provider}?next=#{next_url}"
39
+ end
40
+
41
+ def root_domain
42
+ PublicSuffix.parse(@domain.host).domain
43
+ end
44
+ end
45
+ end
46
+ end
47
+
@@ -6,11 +6,7 @@ module RestPack
6
6
  end
7
7
 
8
8
  def include_restpack
9
- @restpack = request.env[:restpack]
10
- @domain = @restpack[:domain]
11
- @application = @restpack[:application]
12
- @channel = @restpack[:channel]
13
- @user = @restpack[:user]
9
+ @restpack = RestPackContext.new(request.env)
14
10
  end
15
11
  end
16
12
  end
@@ -1,5 +1,5 @@
1
1
  module RestPack
2
2
  module Web
3
- VERSION = "0.1.28"
3
+ VERSION = "0.1.29"
4
4
  end
5
5
  end
data/lib/restpack-web.rb CHANGED
@@ -1,3 +1,5 @@
1
1
  require 'restpack-web/version'
2
+ require 'restpack-web/context'
2
3
  require 'restpack-web/app'
4
+
3
5
  require 'restpack-web/rails/controller'
data/restpack-web.gemspec CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |gem|
19
19
 
20
20
  gem.add_dependency 'rack-auto-session-domain'
21
21
  gem.add_dependency 'restpack-core-client'
22
+ gem.add_dependency 'public_suffix'
22
23
  gem.add_development_dependency 'rack'
23
24
  gem.add_development_dependency 'rspec', '~> 2.12'
24
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restpack-web
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.28
4
+ version: 0.1.29
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -43,6 +43,22 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: public_suffix
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
46
62
  - !ruby/object:Gem::Dependency
47
63
  name: rack
48
64
  requirement: !ruby/object:Gem::Requirement
@@ -88,6 +104,7 @@ files:
88
104
  - Rakefile
89
105
  - lib/restpack-web.rb
90
106
  - lib/restpack-web/app.rb
107
+ - lib/restpack-web/context.rb
91
108
  - lib/restpack-web/rails/controller.rb
92
109
  - lib/restpack-web/version.rb
93
110
  - restpack-web.gemspec