restpack_web 0.2.19 → 0.2.20

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZDRiZTVkYzFmOGVlZTljYWVhYmE2NmIxYzI1ZTY0ZTJmYzFlOGY5Yg==
4
+ N2Y1Y2U5NjY1MjFmZWY0NjUyZTk0NmJjNzMwNGQ3Y2I3ODQzNWY3Nw==
5
5
  data.tar.gz: !binary |-
6
- Y2RiYmIxZjE1M2UzNjkzNTFhODQ0ZTUyZDlhYjliYTgxMDJiYzRkOQ==
6
+ MjQxZGU0NDE0MDQ2YTU1MWZiZDk1ZDBhMzA5MmE0NjE2NGRhNGU1YQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YjJmNTkzYmM0YTZkZGM3M2JiMzk3ZmZlZmUxYmY5MzFjZmQzZWY0YzA1ZDJm
10
- NTA3ZjI5NjQzZDRjYWVhYWJkZjI1YmRkY2UyNzVjMThmZDFmNTVlNmJhMWQ1
11
- ZWQyMGRiNzkzZTg3YTIyMDJmNTljNWY4ZmYyZWJiY2ExMTdjNzE=
9
+ OTcyNmQwM2Y1NjQwZTI4MDBjZDM2MmQ4ODJjNTQ3MWZiMmQ1NDQ3MTkxMTNk
10
+ MTVjNzQ4M2ZiMDE4N2YyMGE3MjMyM2NkZjEzMzFmMDlkMTdlNWM1MTg1NDlj
11
+ NDljMzJjOTE3MWVhNTY2MTY2ZjgzZDQwOTUzZGY3ZWQxMDZjNmY=
12
12
  data.tar.gz: !binary |-
13
- ZGQ1MGYwNjAxNjlhZDQ0NjBjNTg3ZDk5YzRkYzZjMjM2YmRhOWJmYzgyOWY1
14
- OGJlYzBlY2EwZDU5ZmEzMWM1ZWVmZmVhZjJjZDY1NzJkNzYyZDM2ODQzNGEy
15
- MDUyMDRkMTFmNmE4ZTdhZjIxODlmOGZhZDgyMDkyZDdlOGMzMWQ=
13
+ NjNmMzhiOTM1NjA1NzlhYjE3YWE4MjkyOWVkN2ZiOGJkNjQyODYwMzZmY2Zl
14
+ ZmNmMjlkYjEzMzIxNWQ2YTAzODEzYTIwMDU4MGUyNTYwNzVmNzFjMTg5NmQ2
15
+ ZmJkMzRjOWRlNTk3YjA5NDJhNDI4NzBhNDliZmE4OWU3NDc5MzU=
@@ -4,7 +4,6 @@ module RestPack
4
4
  module Web
5
5
  class App
6
6
  def initialize(app, options = {})
7
- p "RestPack::Web::App.initialize"
8
7
  @app = app
9
8
 
10
9
  options[:core_domain] ||= ENV['RESTPACK_CORE_SERVICE']
@@ -18,29 +17,17 @@ module RestPack
18
17
  def call(env)
19
18
  env[:restpack] ||= {}
20
19
 
21
- begin #TODO: GJ: cache should handle errors gracefully
22
- request = Rack::Request.new(env)
20
+ request = Rack::Request.new(env)
23
21
 
24
- channel = @core_cache.get_channel(request.host)
25
- domain = channel.get_domain_by_host(request.host)
22
+ domain = @core_cache.get_domain(request.host)
26
23
 
27
- env[:restpack][:request] = request
28
- env[:restpack][:host] = request.host
29
- env[:restpack][:channel] = channel
30
- env[:restpack][:application] = domain.application
31
- env[:restpack][:domain] = domain
32
- env[:restpack][:configurations] = @core_cache.configurations
33
- env[:restpack][:services] = @core_cache.get_configuration_value('services', [])
24
+ env[:restpack][:host] = request.host
25
+ env[:restpack][:channel] = domain.channel
26
+ env[:restpack][:application] = domain.application
27
+ env[:restpack][:domain] = domain
28
+ env[:restpack][:configurations] = @core_cache.configurations
34
29
 
35
- add_user env
36
-
37
- rescue Exception => e
38
- p "---"
39
- p e.message
40
- p "===="
41
- p e.backtrace.inspect
42
- p "---"
43
- end
30
+ add_user env
44
31
 
45
32
  @app.call(env)
46
33
  end
@@ -53,11 +40,11 @@ module RestPack
53
40
  user_id = env['rack.session'][:user_id]
54
41
 
55
42
  if user_id
56
- user_id = env['rack.session'][:user_id]
57
- channel_domains = env[:restpack][:channel].configurations.find{ |conf| conf.key == 'domains' }.value
58
- auth_domain = channel_domains[:auth]
59
- json = RestClient.get("#{auth_domain}/api/v1/users/#{user_id}.json")
60
- env[:restpack][:user] = Yajl::Parser.parse(json)['user']
43
+ context = RestPack::Web::Context.new(env)
44
+
45
+ user_service_domain = context.get_service_domain('restpack-user-service')
46
+ json = RestClient.get("http://:#{ENV['RESTPACK_ACCESS_KEY']}@#{user_service_domain}/api/v1/users/#{user_id}.json")
47
+ env[:restpack][:user] = Yajl::Parser.parse(json, :symbolize_keys => true)[:user]
61
48
  end
62
49
 
63
50
  env[:restpack][:user_id] = user_id
@@ -3,18 +3,16 @@ require 'public_suffix'
3
3
  module RestPack
4
4
  module Web
5
5
  class Context
6
- attr_accessor :domain, :application, :channel, :configurations, :services, :user, :user_id, :request
7
-
8
- def initialize(env)
6
+ attr_accessor :domain, :application, :channel, :configurations, :user, :user_id
7
+
8
+ def initialize(env)
9
9
  restpack = env[:restpack]
10
10
 
11
11
  if restpack
12
- @request = restpack[:request]
13
12
  @domain = restpack[:domain]
14
13
  @application = restpack[:application]
15
14
  @channel = restpack[:channel]
16
15
  @configurations = restpack[:configurations]
17
- @services = restpack[:services]
18
16
  @user = restpack[:user]
19
17
  @user_id = @user[:id] if @user
20
18
  end
@@ -24,8 +22,20 @@ module RestPack
24
22
  !@user.nil?
25
23
  end
26
24
 
25
+ def get_configuration(key)
26
+ @configurations.find { |c| c.key == key }
27
+ end
28
+
29
+ def services
30
+ get_configuration('services').value
31
+ end
32
+
27
33
  def get_service(name)
28
- @services.find { |s| s[:name] == name.to_s }
34
+ services.find { |s| s[:name] == name }
35
+ end
36
+
37
+ def get_service_domain(name)
38
+ get_service(name)[:domain]
29
39
  end
30
40
 
31
41
  def home_domain
@@ -54,14 +64,14 @@ module RestPack
54
64
  user_debug_info = ""
55
65
  if is_authenticated?
56
66
  image_debug_info = ""
57
- image_debug_info = " * **image** : #{@user['image']} ![Image](#{@user['image']}" unless @user['image'].nil?
67
+ image_debug_info = " * **image** : #{@user[:image]} ![Image](#{@user[:image]}" unless @user[:image].nil?
58
68
 
59
69
  user_debug_info = %{
60
- * **id** : #{@user['id']}
61
- * **name** : #{@user['name']}
62
- * **nickname** : #{@user['nickname']}
63
- * **location** : #{@user['location']}
64
- * **description** : #{@user['description']}
70
+ * **id** : #{@user[:id]}
71
+ * **name** : #{@user[:name]}
72
+ * **nickname** : #{@user[:nickname]}
73
+ * **location** : #{@user[:location]}
74
+ * **description** : #{@user[:description]}
65
75
  #{image_debug_info})
66
76
  }
67
77
  end
@@ -94,6 +104,7 @@ module RestPack
94
104
  #### Configuration:
95
105
 
96
106
  * **keys**: #{@configurations.map { |c| c.key }.join(', ')}
107
+ * **services**: #{services.map { |s| s[:name] + ': ' + s[:domain] }.join(', ')}
97
108
 
98
109
  #### Authentication:
99
110
 
@@ -104,4 +115,4 @@ module RestPack
104
115
  end
105
116
  end
106
117
  end
107
- end
118
+ end
@@ -1,5 +1,5 @@
1
1
  module RestPack
2
2
  module Web
3
- VERSION = "0.2.19"
3
+ VERSION = "0.2.20"
4
4
  end
5
5
  end
data/restpack_web.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ["lib"]
19
19
 
20
20
  gem.add_dependency 'rack-auto-session-domain', '~> 0.1.1'
21
- gem.add_dependency 'restpack_core_client', '~> 0.2.4'
21
+ gem.add_dependency 'restpack_core_client', '~> 0.2.6'
22
22
  gem.add_dependency 'public_suffix', '~> 1.3.0'
23
23
  gem.add_dependency 'yajl-ruby', '~> 1.1.0'
24
24
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restpack_web
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.19
4
+ version: 0.2.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Joyce
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-30 00:00:00.000000000 Z
11
+ date: 2013-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack-auto-session-domain
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: 0.2.4
33
+ version: 0.2.6
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: 0.2.4
40
+ version: 0.2.6
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: public_suffix
43
43
  requirement: !ruby/object:Gem::Requirement