wovnrb 3.3.1 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e5c458ea4be1b5bc1325a0c54a9672f7fd744b864975699ae48e70acde6d5265
4
- data.tar.gz: 318102aa29ae9bbb03d5cf0b1ccffa3f39ada7a8fc963daad856b058f46e46ec
3
+ metadata.gz: '06193b75ac22b47169f8d766af6fefbd2313ab08d064bb375f5f0966c7545f8a'
4
+ data.tar.gz: 58dc13795166410b91a33a8de5c13ecbf44f2cc777c6b0696475ef1d938449b5
5
5
  SHA512:
6
- metadata.gz: fd81bc766461ce8212a32afafc0a673790985213304c55765322e42591e34107a649d70e1133a597b88c6cda3ee0813cd1b4efbac1ff45d2d794f52d78c80814
7
- data.tar.gz: fd4304143e2226ab1b9a887d45e2326da8b8b452e0a60bcbb94f3b680fc4280459e47fb3b025d6660c2d338a1d3150617fc279b279e68693b0566a41050bd3de
6
+ metadata.gz: f696a3e0078b1c51eee646143b90cd9cbb20ddfa95406f652db770ba28b9c655e76d6e907736dd35919089bb27671af792f938ceb4da20de46ddddfa4d122f06
7
+ data.tar.gz: 4ef3a31120a8052f5ac5a0b8fe8e289b269cd5ec85640eb677e1792f202d1dfdf396787be38876442be8f10ca33987cb8a472e1b9fb4b611ea36b3e759a9d544
@@ -53,4 +53,4 @@ end
53
53
  # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
54
54
  gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
55
55
 
56
- gem 'wovnrb', path: './wovnrb'
56
+ gem 'wovnrb', path: './wovnrb'
@@ -5,7 +5,6 @@ rm /usr/local/bin/bundle
5
5
  rm /usr/local/bin/bundler
6
6
  gem install bundler:2.1.4
7
7
  update --bundler
8
- bundle update
9
8
  bundle install
10
9
  apt update
11
10
  apt install npm -y
@@ -5129,9 +5129,9 @@ path-key@^2.0.0, path-key@^2.0.1:
5129
5129
  integrity sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=
5130
5130
 
5131
5131
  path-parse@^1.0.6:
5132
- version "1.0.6"
5133
- resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c"
5134
- integrity sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==
5132
+ version "1.0.7"
5133
+ resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.7.tgz#fbc114b60ca42b30d9daf5858e4bd68bbedb6735"
5134
+ integrity sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==
5135
5135
 
5136
5136
  path-to-regexp@0.1.7:
5137
5137
  version "0.1.7"
@@ -24,18 +24,19 @@ module Wovnrb
24
24
 
25
25
  case response
26
26
  when Net::HTTPSuccess
27
- if response.header['Content-Encoding'] == 'gzip'
28
- response_body = Zlib::GzipReader.new(StringIO.new(response.body)).read
29
-
30
- JSON.parse(response_body)['body'] || body
31
- elsif @store.dev_mode?
32
- JSON.parse(response.body)['body'] || body
33
- else
34
- WovnLogger.error("Received invalid content (\"#{response.header['Content-Encoding']}\") from WOVNio translation API.")
27
+ begin
28
+ raw_response_body = @store.dev_mode? ? response.body : Zlib::GzipReader.new(StringIO.new(response.body)).read
29
+ rescue Zlib::GzipFile::Error
30
+ raw_response_body = response.body
31
+ end
32
+
33
+ begin
34
+ JSON.parse(raw_response_body)['body'] || body
35
+ rescue JSON::JSONError
35
36
  body
36
37
  end
37
38
  else
38
- WovnLogger.error("Received \"#{response.message}\" from WOVNio translation API.")
39
+ WovnLogger.error("HTML-swapper call failed. Received \"#{response.message}\" from WOVNio translation API.")
39
40
  body
40
41
  end
41
42
  end
@@ -1,3 +1,3 @@
1
1
  module Wovnrb
2
- VERSION = '3.3.1'.freeze
2
+ VERSION = '3.4.0'.freeze
3
3
  end
@@ -10,20 +10,24 @@ module Wovnrb
10
10
 
11
11
  def test_translate_falls_back_to_original_body_if_exception
12
12
  Net::HTTP.any_instance.expects(:request).raises
13
- assert_translation('test.html', 'test_translated.html', false, nil)
13
+ assert_translation('test.html', 'test_translated.html', false, response: nil)
14
14
  end
15
15
 
16
16
  def test_translate_falls_back_to_original_body_if_api_error
17
- assert_translation('test.html', 'test_translated.html', false, status_code: 500)
17
+ assert_translation('test.html', 'test_translated.html', false, response: { encoding: 'text/json', status_code: 500 })
18
18
  end
19
19
 
20
- def test_translate_falls_back_to_original_body_if_api_response_is_not_compressed
21
- assert_translation('test.html', 'test_translated.html', false, encoding: 'unknown')
20
+ def test_translate_continues_if_api_response_is_not_compressed
21
+ assert_translation('test.html', 'test_translated.html', true, response: { encoding: 'unknown', status: 200 }, compress_data: false)
22
+ end
23
+
24
+ def test_translate_continues_if_api_response_is_compressed
25
+ assert_translation('test.html', 'test_translated.html', true, response: { encoding: 'unknown', status: 200 })
22
26
  end
23
27
 
24
28
  def test_translate_accepts_uncompressed_response_from_api_in_dev_mode
25
29
  Wovnrb::Store.instance.update_settings('wovn_dev_mode' => true)
26
- assert_translation('test.html', 'test_translated.html', true, encoding: 'text/json')
30
+ assert_translation('test.html', 'test_translated.html', true, response: { encoding: 'text/json', status: 200 }, compress_data: false)
27
31
  end
28
32
 
29
33
  def test_translate_without_api_compression_sends_json
@@ -60,10 +64,10 @@ module Wovnrb
60
64
 
61
65
  private
62
66
 
63
- def assert_translation(original_html_fixture, translated_html_fixture, success_expected, response = { encoding: 'gzip', status_code: 200 })
67
+ def assert_translation(original_html_fixture, translated_html_fixture, success_expected, response: { encoding: 'gzip', status_code: 200 }, compress_data: true)
64
68
  original_html = File.read("test/fixtures/html/#{original_html_fixture}")
65
69
  translated_html = File.read("test/fixtures/html/#{translated_html_fixture}")
66
- actual_translated_html = translate(original_html, translated_html, response)
70
+ actual_translated_html = translate(original_html, translated_html, response, compress_data: compress_data)
67
71
 
68
72
  if success_expected
69
73
  assert_equal(actual_translated_html, translated_html)
@@ -72,9 +76,9 @@ module Wovnrb
72
76
  end
73
77
  end
74
78
 
75
- def translate(original_html, translated_html, response)
76
- api_translator, store, headers = create_sut
77
- translation_request_stub = stub_translation_api_request(store, headers, original_html, translated_html, response)
79
+ def translate(original_html, translated_html, response, compress_data: true)
80
+ api_translator, store, _headers = create_sut
81
+ translation_request_stub = stub_translation_api_request(store, original_html, translated_html, response, compress_data: compress_data)
78
82
 
79
83
  actual_translated_html = api_translator.translate(original_html)
80
84
  assert_requested(translation_request_stub, times: 1) if translation_request_stub
@@ -101,7 +105,7 @@ module Wovnrb
101
105
  [api_translator, store, headers]
102
106
  end
103
107
 
104
- def stub_translation_api_request(store, headers, original_html, translated_html, response)
108
+ def stub_translation_api_request(store, original_html, translated_html, response, compress_data: true)
105
109
  if response
106
110
  cache_key = generate_cache_key(store, original_html)
107
111
  api_host = if store.dev_mode?
@@ -119,10 +123,10 @@ module Wovnrb
119
123
  'User-Agent' => 'Ruby'
120
124
  }
121
125
  stub_response_json = "{\"body\":\"#{translated_html.gsub("\n", '\n')}\"}"
122
- stub_response = if store.dev_mode?
123
- stub_response_json
124
- else
126
+ stub_response = if compress_data
125
127
  compress(stub_response_json)
128
+ else
129
+ stub_response_json
126
130
  end
127
131
  response_headers = { 'Content-Encoding' => response[:encoding] || 'gzip' }
128
132
  stub_request(:post, api_url)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wovnrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.1
4
+ version: 3.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wovn Technologies, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-22 00:00:00.000000000 Z
11
+ date: 2021-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport