web_translate_it 1.7.3.1 → 1.8.0.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.
@@ -17,10 +17,12 @@ module WebTranslateIt
17
17
  puts ""
18
18
  puts " Pulling files ".bright
19
19
  puts ""
20
- fetch_locales_to_pull.each do |locale|
21
- configuration.files.find_all{ |file| file.locale == locale }.each do |file|
22
- print " * #{file.file_path}: "
23
- puts file.fetch(command_options.force)
20
+ WebTranslateIt::Util.http_connection do |http|
21
+ fetch_locales_to_pull.each do |locale|
22
+ configuration.files.find_all{ |file| file.locale == locale }.each do |file|
23
+ print " * #{file.file_path}: "
24
+ puts file.fetch(http, command_options.force)
25
+ end
24
26
  end
25
27
  end
26
28
  `#{configuration.after_pull}` if configuration.after_pull
@@ -32,10 +34,12 @@ module WebTranslateIt
32
34
  puts ""
33
35
  puts " Pushing files ".bright
34
36
  puts ""
35
- fetch_locales_to_push(configuration).each do |locale|
36
- configuration.files.find_all{ |file| file.locale == locale }.each do |file|
37
- print " * #{file.file_path}... "
38
- puts file.upload(command_options[:merge], command_options.ignore_missing, command_options.label, command_options.low_priority)
37
+ WebTranslateIt::Util.http_connection do |http|
38
+ fetch_locales_to_push(configuration).each do |locale|
39
+ configuration.files.find_all{ |file| file.locale == locale }.each do |file|
40
+ print " * #{file.file_path}... "
41
+ puts file.upload(http, command_options[:merge], command_options.ignore_missing, command_options.label, command_options.low_priority)
42
+ end
39
43
  end
40
44
  end
41
45
  `#{configuration.after_push}` if configuration.after_push
@@ -48,10 +52,12 @@ module WebTranslateIt
48
52
  puts "Usage: wti add master_file1 master_file2 ..."
49
53
  exit
50
54
  end
51
- parameters.each do |param|
52
- file = TranslationFile.new(nil, param, nil, configuration.api_key)
53
- print "Creating #{file.file_path}... "
54
- puts file.create
55
+ WebTranslateIt::Util.http_connection do |http|
56
+ parameters.each do |param|
57
+ file = TranslationFile.new(nil, param, nil, configuration.api_key)
58
+ print "Creating #{file.file_path}... "
59
+ puts file.create(http)
60
+ end
55
61
  end
56
62
  puts "Master file added.".success
57
63
  end
@@ -76,6 +82,10 @@ module WebTranslateIt
76
82
  FileUtils.mkpath(path.split('/')[0..path.split('/').size-2].join('/'))
77
83
  project = YAML.load WebTranslateIt::Project.fetch_info(api_key)
78
84
  project_info = project['project']
85
+ if !File.writable?(path)
86
+ puts "Error: #{path} is not writable.".failure
87
+ exit
88
+ end
79
89
  File.open(path, 'w'){ |file| file << generate_configuration(api_key, project_info) }
80
90
  error = false
81
91
  project_info['project_files'].each do |file|
@@ -6,7 +6,14 @@ module WebTranslateIt
6
6
  begin
7
7
  WebTranslateIt::Util.http_connection do |http|
8
8
  request = Net::HTTP::Get.new("/api/projects/#{api_key}.yaml")
9
- Util.handle_response(http.request(request), true)
9
+ response = http.request(request)
10
+ if response.is_a?(Net::HTTPSuccess)
11
+ return response.body
12
+ else
13
+ puts "An error occured while fetching the project information:"
14
+ puts response.body.failure
15
+ exit
16
+ end
10
17
  end
11
18
  rescue Timeout::Error
12
19
  puts "The request timed out. The service may be overloaded. We will retry in 5 seconds."
@@ -35,25 +35,22 @@ module WebTranslateIt
35
35
  # file.fetch # returns nothing, with a status 304 Not Modified
36
36
  # file.fetch(true) # force to re-download the file, will return the content of the file with a 200 OK
37
37
  #
38
- def fetch(force = false)
38
+ def fetch(http_connection, force = false)
39
39
  print "#{self.local_checksum.to_s.checksumify}...#{self.remote_checksum.to_s.checksumify} "
40
40
  if !File.exist?(self.file_path) or force or self.remote_checksum != self.local_checksum
41
41
  begin
42
- WebTranslateIt::Util.http_connection do |http|
43
- request = Net::HTTP::Get.new(api_url)
44
- response = http.request(request)
45
- FileUtils.mkpath(self.file_path.split('/')[0..-2].join('/')) unless File.exist?(self.file_path) or self.file_path.split('/')[0..-2].join('/') == ""
46
- begin
47
- File.open(self.file_path, 'wb'){ |file| file << response.body } if response.code.to_i == 200 and response.body != ''
48
- Util.handle_response(response)
49
- rescue
50
- "/!\\ An error occured: #{$!}".failure
51
- end
42
+ response = http_connection.get(api_url)
43
+ FileUtils.mkpath(self.file_path.split('/')[0..-2].join('/')) unless File.exist?(self.file_path) or self.file_path.split('/')[0..-2].join('/') == ""
44
+ begin
45
+ File.open(self.file_path, 'wb'){ |file| file << response.body } if response.code.to_i == 200 and response.body != ''
46
+ Util.handle_response(response)
47
+ rescue
48
+ "/!\\ An error occured: #{$!}".failure
52
49
  end
53
50
  rescue Timeout::Error
54
51
  puts "Request timeout. Will retry in 5 seconds.".failure
55
52
  sleep(5)
56
- fetch(force)
53
+ fetch(http_connection, force)
57
54
  end
58
55
  else
59
56
  return "Skipped (up to date)".success
@@ -71,14 +68,12 @@ module WebTranslateIt
71
68
  #
72
69
  # Note that the request might or might not eventually be acted upon, as it might be disallowed when processing
73
70
  # actually takes place. This is due to the fact that language file imports are handled by background processing.
74
- def upload(merge=false, ignore_missing=false, label=nil, low_priority=false)
71
+ def upload(http_connection, merge=false, ignore_missing=false, label=nil, low_priority=false)
75
72
  if File.exists?(self.file_path)
76
73
  File.open(self.file_path) do |file|
77
74
  begin
78
- WebTranslateIt::Util.http_connection do |http|
79
- request = Net::HTTP::Put::Multipart.new(api_url, {"file" => UploadIO.new(file, "text/plain", file.path), "merge" => merge, "ignore_missing" => ignore_missing, "label" => label, "low_priority" => low_priority })
80
- Util.handle_response(http.request(request))
81
- end
75
+ request = Net::HTTP::Put::Multipart.new(api_url, {"file" => UploadIO.new(file, "text/plain", file.path), "merge" => merge, "ignore_missing" => ignore_missing, "label" => label, "low_priority" => low_priority })
76
+ Util.handle_response(http_connection.request(request))
82
77
  rescue Timeout::Error
83
78
  puts "Request timeout. Will retry in 5 seconds.".failure
84
79
  sleep(5)
@@ -101,14 +96,12 @@ module WebTranslateIt
101
96
  # Note that the request might or might not eventually be acted upon, as it might be disallowed when processing
102
97
  # actually takes place. This is due to the fact that language file imports are handled by background processing.
103
98
  #
104
- def create
99
+ def create(http_connection)
105
100
  if File.exists?(self.file_path)
106
101
  File.open(self.file_path) do |file|
107
102
  begin
108
- WebTranslateIt::Util.http_connection do |http|
109
- request = Net::HTTP::Post::Multipart.new(api_url_for_create, { "name" => self.file_path, "file" => UploadIO.new(file, "text/plain", file.path) })
110
- Util.handle_response(http.request(request))
111
- end
103
+ request = Net::HTTP::Post::Multipart.new(api_url_for_create, { "name" => self.file_path, "file" => UploadIO.new(file, "text/plain", file.path) })
104
+ Util.handle_response(http_connection.request(request))
112
105
  rescue Timeout::Error
113
106
  puts "Request timeout. Will retry in 5 seconds.".failure
114
107
  sleep(5)
@@ -11,7 +11,7 @@ module WebTranslateIt
11
11
  # Return a string representing the gem version
12
12
  # For example "1.4.4.1"
13
13
  def self.version
14
- hash = YAML.load_file File.join(File.dirname(__FILE__), '..', '..' '/version.yml')
14
+ hash = YAML.load_file File.expand_path('../../../version.yml', __FILE__)
15
15
  [hash[:major], hash[:minor], hash[:tiny], hash[:patch]].join('.')
16
16
  end
17
17
 
@@ -30,9 +30,10 @@ module WebTranslateIt
30
30
  proxy = ENV['http_proxy'] ? URI.parse(ENV['http_proxy']) : OpenStruct.new
31
31
  http = Net::HTTP::Proxy(proxy.host, proxy.port, proxy.user, proxy.password).new('webtranslateit.com', 443)
32
32
  http.use_ssl = true
33
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
33
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
34
+ http.ca_file = File.expand_path('cacert.pem', __FILE__)
34
35
  http.open_timeout = http.read_timeout = 30
35
- yield http
36
+ yield http.start
36
37
  end
37
38
 
38
39
  def self.calculate_percentage(processed, total)
@@ -6,7 +6,6 @@ require 'web_translate_it/translation_file'
6
6
  require 'web_translate_it/auto_fetch'
7
7
  require 'web_translate_it/command_line'
8
8
  require 'web_translate_it/project'
9
- require 'web_translate_it/tasks'
10
9
  require 'web_translate_it/server'
11
10
 
12
11
  module WebTranslateIt
data/version.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 1
3
- :minor: 7
4
- :tiny: 3
5
- :patch: 1
3
+ :minor: 8
4
+ :tiny: 0
5
+ :patch: 0
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: web_translate_it
3
3
  version: !ruby/object:Gem::Version
4
- hash: 105
5
- prerelease:
4
+ prerelease: false
6
5
  segments:
7
6
  - 1
8
- - 7
9
- - 3
10
- - 1
11
- version: 1.7.3.1
7
+ - 8
8
+ - 0
9
+ - 0
10
+ version: 1.8.0.0
12
11
  platform: ruby
13
12
  authors:
14
13
  - "\xC3\x89douard Bri\xC3\xA8re"
@@ -16,7 +15,7 @@ autorequire:
16
15
  bindir: bin
17
16
  cert_chain: []
18
17
 
19
- date: 2011-05-06 00:00:00 +02:00
18
+ date: 2011-05-31 00:00:00 +02:00
20
19
  default_executable: wti
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
@@ -27,7 +26,6 @@ dependencies:
27
26
  requirements:
28
27
  - - ~>
29
28
  - !ruby/object:Gem::Version
30
- hash: 19
31
29
  segments:
32
30
  - 1
33
31
  - 1
@@ -43,7 +41,6 @@ dependencies:
43
41
  requirements:
44
42
  - - ~>
45
43
  - !ruby/object:Gem::Version
46
- hash: 83
47
44
  segments:
48
45
  - 1
49
46
  - 16
@@ -59,7 +56,6 @@ dependencies:
59
56
  requirements:
60
57
  - - ~>
61
58
  - !ruby/object:Gem::Version
62
- hash: 19
63
59
  segments:
64
60
  - 1
65
61
  - 2
@@ -75,7 +71,6 @@ dependencies:
75
71
  requirements:
76
72
  - - ~>
77
73
  - !ruby/object:Gem::Version
78
- hash: 17
79
74
  segments:
80
75
  - 1
81
76
  - 1
@@ -91,7 +86,6 @@ dependencies:
91
86
  requirements:
92
87
  - - ">="
93
88
  - !ruby/object:Gem::Version
94
- hash: 13
95
89
  segments:
96
90
  - 1
97
91
  - 2
@@ -99,7 +93,7 @@ dependencies:
99
93
  version: 1.2.9
100
94
  type: :development
101
95
  version_requirements: *id005
102
- description: An ruby executable, a sinatra app and a handful of rake tasks to sync your translations between your app and webtranslateit.com.
96
+ description: An ruby executable and a handful of tools to sync your translations between your app and webtranslateit.com.
103
97
  email: edouard@atelierconvivialite.com
104
98
  executables:
105
99
  - wti
@@ -117,12 +111,12 @@ files:
117
111
  - examples/locale.rb
118
112
  - examples/translation.yml
119
113
  - lib/web_translate_it/auto_fetch.rb
114
+ - lib/web_translate_it/cacert.pem
120
115
  - lib/web_translate_it/command_line.rb
121
116
  - lib/web_translate_it/configuration.rb
122
117
  - lib/web_translate_it/project.rb
123
118
  - lib/web_translate_it/public/screen.css
124
119
  - lib/web_translate_it/server.rb
125
- - lib/web_translate_it/tasks.rb
126
120
  - lib/web_translate_it/translation_file.rb
127
121
  - lib/web_translate_it/util.rb
128
122
  - lib/web_translate_it/views/index.erb
@@ -158,7 +152,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
158
152
  requirements:
159
153
  - - ">="
160
154
  - !ruby/object:Gem::Version
161
- hash: 3
162
155
  segments:
163
156
  - 0
164
157
  version: "0"
@@ -167,14 +160,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
160
  requirements:
168
161
  - - ">="
169
162
  - !ruby/object:Gem::Version
170
- hash: 3
171
163
  segments:
172
164
  - 0
173
165
  version: "0"
174
166
  requirements: []
175
167
 
176
168
  rubyforge_project:
177
- rubygems_version: 1.5.2
169
+ rubygems_version: 1.3.7
178
170
  signing_key:
179
171
  specification_version: 3
180
172
  summary: Sync your translations between your app and Web Translate It
@@ -1,40 +0,0 @@
1
- # encoding: utf-8
2
- require 'rake'
3
- require 'web_translate_it'
4
- namespace :trans do
5
- desc "Fetch translation files from Web Translate It"
6
- task :fetch, :locale do |task, args|
7
- WebTranslateIt::Util.welcome_message
8
- puts "Fetching file for locale #{args.locale}..."
9
- configuration = WebTranslateIt::Configuration.new
10
- configuration.files.find_all{ |file| file.locale == args.locale }.each do |file|
11
- puts file.file_path + ": " + file.fetch
12
- end
13
- end
14
-
15
- namespace :fetch do
16
- desc "Fetch all the translation files from Web Translate It"
17
- task :all do
18
- WebTranslateIt::Util.welcome_message
19
- configuration = WebTranslateIt::Configuration.new
20
- locales = configuration.target_locales
21
- configuration.ignore_locales.each{ |locale_to_ignore| locales.delete(locale_to_ignore) }
22
- puts "Fetching all files for all locales..."
23
- locales.each do |locale|
24
- configuration.files.find_all{ |file| file.locale == locale }.each do |file|
25
- puts file.file_path + " " + file.fetch
26
- end
27
- end
28
- end
29
- end
30
-
31
- desc "Upload the translation files for a locale to Web Translate It"
32
- task :upload, :locale do |task, args|
33
- WebTranslateIt::Util.welcome_message
34
- puts "Uploading file for locale #{args.locale}..."
35
- configuration = WebTranslateIt::Configuration.new
36
- configuration.files.find_all{ |file| file.locale == args.locale }.each do |file|
37
- puts file.file_path + " " + file.upload
38
- end
39
- end
40
- end