web_translate_it 2.7.5 → 2.8.0.pre.1

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: 9d28dda70be5e71eeb61a269cceedb3f1406640b4e5526bed6f33d239d1b8527
4
- data.tar.gz: 670de23342b5adbbe052373c918a5b757438d42051c51bd9e7b2dc97c23e78bf
3
+ metadata.gz: 69b5c5aa701b8b255767bbc4fdff3cf1d502ee6c258a610269cc28f718380a28
4
+ data.tar.gz: c8e430b7c96f7a98cbd13a42826467c12e1a4ca523635c6b23f76666258ae6b5
5
5
  SHA512:
6
- metadata.gz: 4a7cc04fe367c0b4541b48f1dc08ecda4deedc9891dd4f92f1622060aac4f46cbe6cd0867791f319893e69f2ad50c604684a70c1071168f6b28fbe7d99631315
7
- data.tar.gz: 22800578ddbe6ccadd5231ede8fc6bdb9a743692eb17235eff3174c3c1d241a5cc1bcf7bf95096572ced08ac71308ed333625b08a700b657457380489b7f82ea
6
+ metadata.gz: 7ecdb51c0f2667cbbe0d83f185d3411196e6ade89e3d74cb283aa4cca6cf1c4c3946f90574b5e8498c51f29c72ce760d95751ff9c172d280678c4034e0702669
7
+ data.tar.gz: 52991c0930ec439e7bb9952f92821048878ad26ecae3274a1d9838515fa4c92adcf64129a6a48a716cf91d7a50afd890f3c977772e3c20925b5113e3cded6c60
@@ -13,7 +13,7 @@ class WebtranslateitGenerator < Rails::Generator::Base
13
13
  end
14
14
  record do |m|
15
15
  if options[:api_key]
16
- project_details = YAML.load WebTranslateIt::Project.fetch_info(options[:api_key])
16
+ project_details = YAML.safe_load WebTranslateIt::Project.fetch_info(options[:api_key])
17
17
  m.template '.wti', '.wti',
18
18
  assigns: {api_key: options[:api_key], project: project_details['project']}
19
19
  m.append_to 'Rakefile', "require 'web_translate_it' rescue LoadError"
data/history.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## Version 2.8.0 / 2023-03-13
2
+
3
+ * Replace YAML API calls with JSON API calls. (#242)
4
+
5
+ ## Version 2.7.6 / 2023-01-02
6
+
7
+ * Add ruby 3.2 to CI matrix.
8
+ * Dependencies upgrade and code refactoring.
9
+
1
10
  ## Version 2.7.5 / 2022-11-17
2
11
 
3
12
  * wti now works with `multipart_post = 2.0.0` AND `multipart_post >= 2.2.0`.
@@ -57,7 +57,7 @@ module WebTranslateIt
57
57
  # Now actually pulling files
58
58
  time = Time.now
59
59
  threads = []
60
- n_threads = (files.size.to_f / 3).ceil >= 10 ? 10 : (files.size.to_f / 3).ceil
60
+ n_threads = [(files.size.to_f / 3).ceil, 10].min
61
61
  ArrayUtil.chunk(files, n_threads).each do |file_array|
62
62
  next if file_array.empty?
63
63
 
@@ -148,7 +148,7 @@ module WebTranslateIt
148
148
  end
149
149
  end
150
150
 
151
- def add # rubocop:todo Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
151
+ def add # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
152
152
  complete_success = true
153
153
  $stdout.sync = true
154
154
  if parameters == []
@@ -157,7 +157,7 @@ module WebTranslateIt
157
157
  exit
158
158
  end
159
159
  WebTranslateIt::Connection.new(configuration.api_key) do |http|
160
- added = configuration.files.find_all { |file| file.locale == configuration.source_locale }.collect { |file| File.expand_path(file.file_path) }.to_set
160
+ added = configuration.files.find_all { |file| file.locale == configuration.source_locale }.to_set { |file| File.expand_path(file.file_path) }
161
161
  to_add = parameters.reject { |param| added.include?(File.expand_path(param)) }
162
162
  if to_add.any?
163
163
  to_add.each do |param|
@@ -295,11 +295,7 @@ module WebTranslateIt
295
295
  path = Util.ask(' Path to configuration file:', '.wti')
296
296
  end
297
297
  FileUtils.mkpath(path.split('/')[0..path.split('/').size - 2].join('/')) unless path.split('/').size == 1
298
- project = if RUBY_VERSION >= '3.1'
299
- YAML.safe_load WebTranslateIt::Project.fetch_info(api_key), permitted_classes: [Time]
300
- else
301
- YAML.load WebTranslateIt::Project.fetch_info(api_key)
302
- end
298
+ project = JSON.parse WebTranslateIt::Project.fetch_info(api_key)
303
299
  project_info = project['project']
304
300
  if File.exist?(path) && !File.writable?(path)
305
301
  puts StringUtil.failure("Error: `#{path}` file is not writable.")
@@ -360,7 +356,7 @@ module WebTranslateIt
360
356
  file_id = file.master_id || file.id
361
357
  puts "Statistics for '#{parameters.first}':"
362
358
  end
363
- stats = YAML.load(Project.fetch_stats(configuration.api_key, file_id))
359
+ stats = JSON.parse(Project.fetch_stats(configuration.api_key, file_id))
364
360
  completely_translated = true
365
361
  completely_proofread = true
366
362
  stats.each do |locale, values|
@@ -22,11 +22,7 @@ module WebTranslateIt
22
22
  self.before_push = configuration['before_push']
23
23
  self.after_push = configuration['after_push']
24
24
  self.ignore_files = configuration['ignore_files']
25
- project_info = if RUBY_VERSION >= '3.1.0'
26
- YAML.safe_load WebTranslateIt::Project.fetch_info(api_key), permitted_classes: [Time]
27
- else
28
- YAML.load WebTranslateIt::Project.fetch_info(api_key)
29
- end
25
+ project_info = JSON.parse WebTranslateIt::Project.fetch_info(api_key)
30
26
  self.ignore_locales = locales_to_ignore(configuration)
31
27
  self.needed_locales = locales_needed(configuration)
32
28
  self.files = files_from_project(project_info['project'])
@@ -42,7 +38,7 @@ module WebTranslateIt
42
38
  # Reload project data
43
39
  #
44
40
  def reload # rubocop:todo Metrics/AbcSize
45
- project_info = YAML.load WebTranslateIt::Project.fetch_info(api_key)
41
+ project_info = JSON.parse WebTranslateIt::Project.fetch_info(api_key)
46
42
  self.ignore_locales = locales_to_ignore(configuration)
47
43
  self.needed_locales = locales_needed(configuration)
48
44
  self.files = files_from_project(project_info['project'])
@@ -97,7 +93,7 @@ module WebTranslateIt
97
93
 
98
94
  # Convenience method which returns the endpoint for fetching a list of locales for a project.
99
95
  def api_url
100
- "/api/projects/#{api_key}.yaml"
96
+ "/api/projects/#{api_key}"
101
97
  end
102
98
 
103
99
  # Returns a logger. If RAILS_DEFAULT_LOGGER is defined, use it, else, define a new logger.
@@ -110,7 +106,7 @@ module WebTranslateIt
110
106
  end
111
107
 
112
108
  def configuration
113
- @configuration ||= YAML.load(parse_erb_in_configuration)
109
+ @configuration ||= YAML.safe_load(parse_erb_in_configuration)
114
110
  end
115
111
 
116
112
  private
@@ -7,7 +7,7 @@ module WebTranslateIt
7
7
  tries ||= 3
8
8
  begin
9
9
  WebTranslateIt::Connection.new(api_key) do |http|
10
- request = Net::HTTP::Get.new("/api/projects/#{api_key}.yaml")
10
+ request = Net::HTTP::Get.new("/api/projects/#{api_key}")
11
11
  WebTranslateIt::Util.add_fields(request)
12
12
  response = http.request(request)
13
13
  return response.body if response.is_a?(Net::HTTPSuccess)
@@ -31,7 +31,7 @@ module WebTranslateIt
31
31
  end
32
32
 
33
33
  def self.fetch_stats(api_key, file_id = nil) # rubocop:todo Metrics/MethodLength
34
- url = file_id.nil? ? "/api/projects/#{api_key}/stats.yaml" : "/api/projects/#{api_key}/stats.yaml?file=#{file_id}"
34
+ url = file_id.nil? ? "/api/projects/#{api_key}/stats" : "/api/projects/#{api_key}/stats?file=#{file_id}"
35
35
  success = true
36
36
  tries ||= 3
37
37
  begin
@@ -53,7 +53,7 @@ module WebTranslateIt
53
53
  success = true
54
54
  tries ||= 3
55
55
  params.stringify_keys!
56
- url = "/api/projects/#{Connection.api_key}/strings.yaml"
56
+ url = "/api/projects/#{Connection.api_key}/strings"
57
57
  url += "?#{HashUtil.to_params('filters' => params)}" unless params.empty?
58
58
 
59
59
  request = Net::HTTP::Get.new(url)
@@ -62,7 +62,7 @@ module WebTranslateIt
62
62
  strings = []
63
63
  while request
64
64
  response = Connection.http_connection.request(request)
65
- YAML.load(response.body).each do |string_response|
65
+ JSON.parse(response.body).each do |string_response|
66
66
  string = WebTranslateIt::String.new(string_response)
67
67
  string.new_record = false
68
68
  strings.push(string)
@@ -105,13 +105,13 @@ module WebTranslateIt
105
105
  def self.find(id) # rubocop:todo Metrics/MethodLength, Metrics/AbcSize
106
106
  success = true
107
107
  tries ||= 3
108
- request = Net::HTTP::Get.new("/api/projects/#{Connection.api_key}/strings/#{id}.yaml")
108
+ request = Net::HTTP::Get.new("/api/projects/#{Connection.api_key}/strings/#{id}")
109
109
  WebTranslateIt::Util.add_fields(request)
110
110
  begin
111
111
  response = Connection.http_connection.request(request)
112
112
  return nil if response.code.to_i == 404
113
113
 
114
- string = WebTranslateIt::String.new(YAML.load(response.body))
114
+ string = WebTranslateIt::String.new(JSON.parse(response.body))
115
115
  string.new_record = false
116
116
  return string
117
117
  rescue Timeout::Error
@@ -187,11 +187,11 @@ module WebTranslateIt
187
187
  return translation if translation
188
188
  return nil if new_record
189
189
 
190
- request = Net::HTTP::Get.new("/api/projects/#{Connection.api_key}/strings/#{id}/locales/#{locale}/translations.yaml")
190
+ request = Net::HTTP::Get.new("/api/projects/#{Connection.api_key}/strings/#{id}/locales/#{locale}/translations")
191
191
  WebTranslateIt::Util.add_fields(request)
192
192
  begin
193
193
  response = Util.handle_response(Connection.http_connection.request(request), true, true)
194
- hash = YAML.load(response)
194
+ hash = JSON.parse(response)
195
195
  return nil if hash.empty?
196
196
 
197
197
  translation = WebTranslateIt::Translation.new(hash)
@@ -216,7 +216,7 @@ module WebTranslateIt
216
216
  def update # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
217
217
  success = true
218
218
  tries ||= 3
219
- request = Net::HTTP::Put.new("/api/projects/#{Connection.api_key}/strings/#{id}.yaml")
219
+ request = Net::HTTP::Put.new("/api/projects/#{Connection.api_key}/strings/#{id}")
220
220
  WebTranslateIt::Util.add_fields(request)
221
221
  request.body = to_json
222
222
 
@@ -249,7 +249,7 @@ module WebTranslateIt
249
249
  WebTranslateIt::Util.add_fields(request)
250
250
  request.body = to_json(true)
251
251
  begin
252
- response = YAML.load(Util.handle_response(Connection.http_connection.request(request), true, true))
252
+ response = JSON.parse(Util.handle_response(Connection.http_connection.request(request), true, true))
253
253
  self.id = response['id']
254
254
  self.new_record = false
255
255
  return true
@@ -43,7 +43,7 @@ module WebTranslateIt
43
43
  success = true
44
44
  tries ||= 3
45
45
  params.stringify_keys!
46
- url = "/api/projects/#{Connection.api_key}/terms.yaml"
46
+ url = "/api/projects/#{Connection.api_key}/terms"
47
47
  url += "?#{HashUtil.to_params(params)}" unless params.empty?
48
48
 
49
49
  request = Net::HTTP::Get.new(url)
@@ -52,7 +52,7 @@ module WebTranslateIt
52
52
  terms = []
53
53
  while request
54
54
  response = Connection.http_connection.request(request)
55
- YAML.load(response.body).each do |term_response|
55
+ JSON.parse(response.body).each do |term_response|
56
56
  term = WebTranslateIt::Term.new(term_response)
57
57
  term.new_record = false
58
58
  terms.push(term)
@@ -95,13 +95,13 @@ module WebTranslateIt
95
95
  def self.find(term_id) # rubocop:todo Metrics/MethodLength, Metrics/AbcSize
96
96
  success = true
97
97
  tries ||= 3
98
- request = Net::HTTP::Get.new("/api/projects/#{Connection.api_key}/terms/#{term_id}.yaml")
98
+ request = Net::HTTP::Get.new("/api/projects/#{Connection.api_key}/terms/#{term_id}")
99
99
  WebTranslateIt::Util.add_fields(request)
100
100
  begin
101
101
  response = Connection.http_connection.request(request)
102
102
  return nil if response.code.to_i == 404
103
103
 
104
- term = WebTranslateIt::Term.new(YAML.load(response.body))
104
+ term = WebTranslateIt::Term.new(JSON.parse(response.body))
105
105
  term.new_record = false
106
106
  return term
107
107
  rescue Timeout::Error
@@ -177,11 +177,11 @@ module WebTranslateIt
177
177
  return translation if translation
178
178
  return nil if new_record
179
179
 
180
- request = Net::HTTP::Get.new("/api/projects/#{Connection.api_key}/terms/#{id}/locales/#{locale}/translations.yaml")
180
+ request = Net::HTTP::Get.new("/api/projects/#{Connection.api_key}/terms/#{id}/locales/#{locale}/translations")
181
181
  WebTranslateIt::Util.add_fields(request)
182
182
  begin
183
183
  response = Util.handle_response(Connection.http_connection.request(request), true, true)
184
- array = YAML.load(response)
184
+ array = JSON.parse(response)
185
185
  return nil if array.empty?
186
186
 
187
187
  translations = []
@@ -207,7 +207,7 @@ module WebTranslateIt
207
207
  def update # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
208
208
  success = true
209
209
  tries ||= 3
210
- request = Net::HTTP::Put.new("/api/projects/#{Connection.api_key}/terms/#{id}.yaml")
210
+ request = Net::HTTP::Put.new("/api/projects/#{Connection.api_key}/terms/#{id}")
211
211
  WebTranslateIt::Util.add_fields(request)
212
212
  request.body = to_json
213
213
 
@@ -238,7 +238,7 @@ module WebTranslateIt
238
238
  request.body = to_json(true)
239
239
 
240
240
  begin
241
- response = YAML.load(Util.handle_response(Connection.http_connection.request(request), true, true))
241
+ response = JSON.parse(Util.handle_response(Connection.http_connection.request(request), true, true))
242
242
  self.id = response['id']
243
243
  self.new_record = false
244
244
  return true
@@ -62,7 +62,7 @@ module WebTranslateIt
62
62
  request.body = to_json
63
63
 
64
64
  begin
65
- response = YAML.load(Util.handle_response(Connection.http_connection.request(request), true, true))
65
+ response = JSON.parse(Util.handle_response(Connection.http_connection.request(request), true, true))
66
66
  self.id = response['id']
67
67
  self.new_record = false
68
68
  return true
@@ -1,4 +1,5 @@
1
1
  require 'fileutils'
2
+ require 'json'
2
3
  require 'yaml'
3
4
  require 'erb'
4
5
  require 'net/http'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: web_translate_it
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.5
4
+ version: 2.8.0.pre.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edouard Briere
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-17 00:00:00.000000000 Z
11
+ date: 2023-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -110,11 +110,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
110
110
  version: '2.6'
111
111
  required_rubygems_version: !ruby/object:Gem::Requirement
112
112
  requirements:
113
- - - ">="
113
+ - - ">"
114
114
  - !ruby/object:Gem::Version
115
- version: '0'
115
+ version: 1.3.1
116
116
  requirements: []
117
- rubygems_version: 3.3.21
117
+ rubygems_version: 3.4.6
118
118
  signing_key:
119
119
  specification_version: 4
120
120
  summary: A CLI tool to sync locale files with WebTranslateIt.com.