glib-web 0.4.15 → 0.4.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cb86f56770b733b9e6dffe8f2b2b1dce9786a5cff9609429832402f4883d505f
4
- data.tar.gz: 6331df9c323c531df8ce4c8e1ca2b812d26e9f7fe7ff17e65b77c1bb15fcf77e
3
+ metadata.gz: a63a2f6c1b4ea589344292ac196fa72d98c006e1e582dbb06dff681ff650dc0c
4
+ data.tar.gz: 74a40e9a319791847c2f4431ffa98e19cbf28786ae0118fdba14c46aafc3c765
5
5
  SHA512:
6
- metadata.gz: 6c314405ef3d50d97ef4deb4056f3f2ff53d1d046c1f9c31c90503762597d80cb013863c2b3d55cc1bd5569ea6b79b9a1da94deb5405856f544f2a540084f704
7
- data.tar.gz: a677e65a2b3338688be9f1c9b157da94edbd90a1b4b2507fe2c71f3b8fd36cac5205c30e81bf3fdb9a91d97f2809efb01f5208292950abb27388a1974888e57b
6
+ metadata.gz: f5efb0e23eae6e10dacae4da8b755e0a0bd008091f1565b0129d2fbe0b14ee420cfe218ccafd7a44c0d3d7830acb152255f284bd5e8e6d9f49e48722f0f1d72b
7
+ data.tar.gz: 7f5b7da282fb4fe63899e0f63b073fca258b418d7b5aeda085caab7a3b99cd8852e8c589e677ba9fff0d07c4156e165e6e4e5b95864376100906ae49403c03c5
@@ -1,60 +1,90 @@
1
1
  module Glib::Json::DynamicText
2
- def __json_dynamic_text_perform
3
- if (hash = json_transformation_start).is_a?(Hash)
4
- @__specs = {}
2
+ def __json_traversal_register_dynamic_text
3
+ @__specs = {}
4
+ @__specs_db = {}
5
5
 
6
- crawl hash['header']&.[]('childViews')
7
- crawl hash['body']&.[]('childViews')
8
- crawl hash['footer']&.[]('childViews')
6
+ __json_traversal_on_traverse do |view|
7
+ extract_spec(view, 'text')
8
+ end
9
9
 
10
+ __json_traversal_on_complete do |view|
10
11
  if @__specs.keys.size > 0
11
- translated_texts = retrieve_remote_texts(@__specs.keys)
12
-
13
- # translated_texts = retrieve_example_texts(@__specs.keys)
12
+ translated_texts = retrieve_texts(@__specs.keys)
13
+ # translated_texts = retrieve_local_texts(@__specs.keys).merge(retrieve_remote_texts(@__specs.keys))
14
14
  translated_texts.each do |key, value|
15
15
  @__specs[key].each do |spec|
16
16
  spec.substitute_with(value)
17
17
  end
18
+
19
+ if @__specs_db[key] && @__specs_db[key].images.attached?
20
+ @__specs[key].each do |spec|
21
+ spec.substitute_image_with(@__specs_db[key].images)
22
+ end
23
+ end
18
24
  end
19
25
  end
20
26
  end
21
27
  end
22
28
 
23
- def retrieve_example_texts(keys)
24
- examples_translations = {
25
- 'home.json_ui_garage.hello' => 'Hello {{name}}',
26
- 'home.json_ui_garage.greeting' => 'Good day!',
27
- }
28
-
29
- translated_texts = {}
30
- keys.each do |key|
31
- translated_texts[key] = examples_translations[key]
32
- end
33
- translated_texts
29
+ def retrieve_texts
30
+ # TODO: Check local memory
31
+ # TODO: Then check DTR
34
32
  end
35
33
 
36
- def retrieve_remote_texts(keys)
37
- retries = 0
38
-
39
- begin
40
- response = RestClient.get(ENV['DTR_URL'], { params: { keys: keys } })
41
- rescue Errno::ECONNREFUSED, RestClient::InternalServerError, RestClient::Exceptions::OpenTimeout, RestClient::Exceptions::ReadTimeout
42
- if (retries += 1) <= 3
43
- puts "Timeout, retrying..."
44
- retry
45
- else
46
- raise
47
- end
48
- end
49
-
50
- JSON.parse(response)
51
- end
52
-
53
- def crawl(views)
54
- Glib::Json::Crawler.new.crawl_multiple views, ->(view) do
55
- extract_spec(view, 'text')
56
- end
57
- end
34
+ # def retrieve_remote_texts(keys)
35
+ # retries = 0
36
+
37
+ # begin
38
+ # response = RestClient.get(ENV['DTR_URL'], { params: { keys: keys } })
39
+ # rescue Errno::ECONNREFUSED, RestClient::InternalServerError, RestClient::Exceptions::OpenTimeout, RestClient::Exceptions::ReadTimeout
40
+ # if (retries += 1) <= 3
41
+ # puts "Timeout, retrying..."
42
+ # retry
43
+ # else
44
+ # raise
45
+ # end
46
+ # end
47
+
48
+ # JSON.parse(response)
49
+ # end
50
+
51
+ # def retrieve_local_texts(keys)
52
+ # translated_texts = {}
53
+ # db_keys = []
54
+
55
+ # redis = Glib::DynamicText::Config.redis
56
+ # contents = redis.pipelined do
57
+ # keys.each do |key|
58
+ # args = @__specs[key].first.args
59
+ # options = {
60
+ # scope: args.fetch(:scope, 'itinerarybuilder'),
61
+ # lang: args.fetch(:lang, 'en')
62
+ # }
63
+
64
+ # scope_key = "#{options[:scope]}.#{options[:lang]}.#{key}"
65
+ # redis.get(scope_key)
66
+ # end
67
+ # end
68
+
69
+ # keys.each_with_index do |key, index|
70
+ # if content = contents[index]
71
+ # translated_texts[key] = content
72
+ # db_keys << key if content.match(/\{\{image(\d)\}\}/)
73
+ # else
74
+ # db_keys << key
75
+ # end
76
+ # end
77
+
78
+ # if db_keys.size > 0
79
+ # texts = Glib::Text.where(key: db_keys)
80
+ # texts.each do |text|
81
+ # translated_texts[text.key] = text.content
82
+ # @__specs_db[text.key] = text
83
+ # end
84
+ # end
85
+
86
+ # translated_texts
87
+ # end
58
88
 
59
89
  def extract_spec(view, prop)
60
90
  if (spec = view[prop])
@@ -69,57 +99,28 @@ module Glib::Json::DynamicText
69
99
  def substitute_with(text)
70
100
  view[prop] = text.gsub(/\{\{(\w+)\}\}/) { args.fetch($1, "{{#{$1}}}") }
71
101
  end
72
- end
73
- end
74
-
75
- class Glib::Json::Crawler
76
- attr_reader :forms
77
102
 
78
- def initialize
79
- @forms = []
80
- end
81
-
82
- def crawl_multiple(views, block)
83
- if views.is_a? Array
84
- views.each do |view|
85
- case view['view']
86
- when 'panels/form-v1'
87
- @forms << view
88
- crawl_single view, block
89
- @forms.pop
103
+ def substitute_image_with(images)
104
+ view[prop] = view[prop].gsub(/\{\{image(\d)\}\}/) {
105
+ if image = images[$1.to_i - 1]
106
+ image_server_url(image.blob.key)
90
107
  else
91
- crawl_single view, block
108
+ "{{image#{$1}}}"
92
109
  end
93
- end
110
+ }
94
111
  end
95
- end
96
-
97
- def crawl_vertical_content(view, block)
98
- crawl_multiple view['childViews'], block if view
99
- end
100
112
 
101
- def crawl_single(view, block)
102
- block.call view
113
+ # TODO: Reuse method from DynamicTextsHelper
114
+ def image_server_url(blob_key, w: 100, h: 100)
115
+ return unless blob_key.present?
103
116
 
104
- # Generic view children
105
- crawl_multiple view['childViews'], block
117
+ uri = URI::HTTPS.build(
118
+ host: 'imageserver-demo.herokuapp.com',
119
+ path: "/image/#{ENV['AWS_S3_BUCKET']}/#{blob_key}",
120
+ query: { w: w, h: h }.to_param
121
+ )
106
122
 
107
- # panels/split
108
- # crawl_multiple view['leftViews'], block
109
- # crawl_multiple view['rightViews'], block
110
-
111
- # Split panel
112
- crawl_vertical_content view['left'], block
113
- crawl_vertical_content view['center'], block
114
- crawl_vertical_content view['right'], block
115
-
116
- # TODO: crawl header and footer
117
- # Table/List
118
- if (sections = view['sections']).is_a? Array
119
- sections.each do |section|
120
- # Table
121
- crawl_multiple section['rows'], block
122
- end
123
+ uri.to_s
123
124
  end
124
125
  end
125
126
  end
@@ -1,4 +1,3 @@
1
- # TODO: Remove old DynamicText
2
1
  module Glib::Json::NewDynamicText
3
2
  def __json_traversal_register_dynamic_text
4
3
  @__specs = {}
@@ -62,7 +61,8 @@ module Glib::Json::NewDynamicText
62
61
  translated_texts = {}
63
62
  db_keys = []
64
63
 
65
- contents = $dt_redis.pipelined do
64
+ redis = Glib::DynamicText::Config.redis
65
+ contents = redis.pipelined do
66
66
  keys.each do |key|
67
67
  args = @__specs[key].first.args
68
68
  options = {
@@ -71,7 +71,7 @@ module Glib::Json::NewDynamicText
71
71
  }
72
72
 
73
73
  scope_key = "#{options[:scope]}.#{options[:lang]}.#{key}"
74
- $dt_redis.get(scope_key)
74
+ redis.get(scope_key)
75
75
  end
76
76
  end
77
77
 
@@ -112,24 +112,24 @@ module Glib::Json::NewDynamicText
112
112
  def substitute_image_with(images)
113
113
  view[prop] = view[prop].gsub(/\{\{image(\d)\}\}/) {
114
114
  if image = images[$1.to_i - 1]
115
- image_server_url(image.blob.key)
115
+ ApplicationController.helpers.dt_image_server_url(image.blob.key)
116
116
  else
117
117
  "{{image#{$1}}}"
118
118
  end
119
119
  }
120
120
  end
121
121
 
122
- # TODO: Reuse method from DynamicTextsHelper
123
- def image_server_url(blob_key, w: 100, h: 100)
124
- return unless blob_key.present?
122
+ # # TODO: Reuse method from DynamicTextsHelper
123
+ # def image_server_url(blob_key, w: 100, h: 100)
124
+ # return unless blob_key.present?
125
125
 
126
- uri = URI::HTTPS.build(
127
- host: 'imageserver-demo.herokuapp.com',
128
- path: "/image/#{ENV['AWS_S3_BUCKET']}/#{blob_key}",
129
- query: { w: w, h: h }.to_param
130
- )
126
+ # uri = URI::HTTPS.build(
127
+ # host: 'imageserver-demo.herokuapp.com',
128
+ # path: "/image/#{ENV['AWS_S3_BUCKET']}/#{blob_key}",
129
+ # query: { w: w, h: h }.to_param
130
+ # )
131
131
 
132
- uri.to_s
133
- end
132
+ # uri.to_s
133
+ # end
134
134
  end
135
135
  end
@@ -42,14 +42,43 @@ module Glib
42
42
  def dt_image_server_url(blob_key, w: 100, h: 100)
43
43
  return unless blob_key.present?
44
44
 
45
+ encryption_service = EncryptionService.new(ENV['AWS_S3_BUCKET'], ENV['PRIVATE_API_KEY'])
46
+ params_hash = {
47
+ bucket_name: ENV['AWS_S3_BUCKET'],
48
+ blob_key: blob_key,
49
+ w: w,
50
+ h: h,
51
+ expires: 1.hours.from_now.to_i
52
+ }
53
+ signature = encryption_service.encrypt(params_hash)
54
+
45
55
  # TODO: This should probably be set as a parameter for json_libs
46
56
  uri = URI::HTTPS.build(
47
57
  host: 'imageserver-demo.herokuapp.com',
48
58
  path: "/image/#{ENV['AWS_S3_BUCKET']}/#{blob_key}",
49
- query: { w: w, h: h }.to_param
59
+ query: params_hash.except(:bucket_name, :blob_key).merge(signature: signature).to_param
50
60
  )
51
61
 
52
62
  uri.to_s
53
63
  end
64
+
65
+ EncryptionService = Struct.new(:salt, :private_key) do
66
+ def encrypt(value)
67
+ encryptor.encrypt_and_sign(value)
68
+ end
69
+
70
+ def decrypt(value)
71
+ encryptor.decrypt_and_verify(value)
72
+ end
73
+
74
+ private
75
+ def encryptor
76
+ encryptor ||= begin
77
+ key_len = ActiveSupport::MessageEncryptor.key_len
78
+ key = ActiveSupport::KeyGenerator.new(private_key).generate_key(salt, key_len)
79
+ ActiveSupport::MessageEncryptor.new(key)
80
+ end
81
+ end
82
+ end
54
83
  end
55
84
  end
@@ -68,13 +68,16 @@ module Glib
68
68
  action :onClose
69
69
  end
70
70
 
71
- # TODO: Deprecate
72
- # Consider renaming to ShowSnackbar
73
- class Snackbar < Action
71
+ class Oauth < Action
72
+ hash :provider
73
+ action :onSuccess
74
+ string :providerParamName
75
+ string :callbackUrlParamName
76
+ end
77
+
78
+ class Alert < Action
74
79
  string :message
75
- string :verticalPosition
76
- string :horizontalPosition
77
- singleton_array :styleClass, :styleClasses
80
+ action :onClose
78
81
  end
79
82
 
80
83
  class Notification < Action
@@ -60,10 +60,14 @@ module Glib
60
60
 
61
61
  after_save :update_to_redis
62
62
 
63
+ def self.redis
64
+ Glib::DynamicText::Config.redis
65
+ end
66
+
63
67
  def self.get_content(key, default_value, options:)
64
68
  scope_key = "#{options[:scope]}.#{options[:lang]}.#{key}"
65
69
 
66
- content = $dt_redis.get(scope_key)
70
+ content = redis.get(scope_key)
67
71
  text = find_by(scope: options[:scope], lang: options[:lang], key: key)
68
72
 
69
73
  if !(content && text)
@@ -82,7 +86,7 @@ module Glib
82
86
 
83
87
  private
84
88
  def self.update_content(scope_key, content)
85
- $dt_redis.set(scope_key, content)
89
+ redis.set(scope_key, content)
86
90
  end
87
91
 
88
92
  def update_to_redis
@@ -12,15 +12,15 @@ json_ui_page json do |page|
12
12
  section.rows builder: ->(template) do
13
13
  template.thumbnail title: 'dialogs/alert', onClick: ->(action) do
14
14
  action.dialogs_alert message: 'This is an alert dialog', onClose: ->(action) do
15
- action.dialogs_snackbar message: 'Closed'
15
+ action.snackbars_alert message: 'Closed'
16
16
  end
17
17
  end
18
18
 
19
19
  # template.thumbnail title: 'dialogs/confirm (Experimental)', onClick: ->(action) do
20
20
  # action.dialogs_confirm message: 'This is a confirm dialog', onCancel: ->(action) do
21
- # action.dialogs_snackbar message: 'Canceled'
21
+ # action.snackbars_alert message: 'Canceled'
22
22
  # end, onConfirm: ->(action) do
23
- # action.dialogs_snackbar message: 'Confirmed'
23
+ # action.snackbars_alert message: 'Confirmed'
24
24
  # end
25
25
  # end
26
26
 
@@ -40,8 +40,18 @@ json_ui_page json do |page|
40
40
  action.dialogs_open url: json_ui_garage_url(path: 'forms/basic', mode: 'dialog')
41
41
  end
42
42
 
43
- template.thumbnail title: 'dialogs/snackbar (Legacy)', onClick: ->(action) do
44
- action.dialogs_snackbar message: 'This is a default snackbar'
43
+ template.thumbnail title: 'dialogs/oauth', onClick: ->(action) do
44
+ provider = {
45
+ name: "facebook",
46
+ webRequestUrl: "https://www.facebook.com/v3.1/dialog/oauth?auth_type=rerequest&client_id=CLIENT_ID&redirect_uri=http%3A%2F%2Fwww.lvh.me%3A3000%2Foauth_callback%2Ffacebook&response_type=code&scope=email",
47
+ requestUrl: "https://www.facebook.com/v3.1/dialog/oauth",
48
+ clientId: "CLIENT_ID",
49
+ redirectUrl: "http://www.lvh.me:3000/oauth_callback/facebook.json"
50
+ }
51
+
52
+ action.dialogs_oauth provider: provider, providerParamName: "session[oauth_provider]", callbackUrlParamName: "session[[oauth_callback_url]", onSuccess: ->(action) do
53
+ action.http_post url: 'TODO: post params to server'
54
+ end
45
55
  end
46
56
 
47
57
  end
@@ -7,7 +7,8 @@ module Glib
7
7
  def self.redis
8
8
  if @@redis.nil?
9
9
  redis_url = ENV.fetch('DT_REDIS_URL', 'redis://localhost:6379')
10
- @@redis = Redis.new(url: redis_url)
10
+ # Allow application to specify their own $dt_redis
11
+ @@redis = $dt_redis || Redis.new(url: redis_url)
11
12
  end
12
13
  @@redis
13
14
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glib-web
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.15
4
+ version: 0.4.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''