web_translate_it 1.7.0 → 1.7.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -105,6 +105,13 @@ By default, it starts an application on localhost on the port 4000. You will fin
105
105
 
106
106
  Should you need to use another host or port, you can use the -h and -p options. For example: `wti server -p 1234`.
107
107
 
108
+ You may want to run some commands before or after synching translations. To do so, add in the `translation.yml` file the following:
109
+
110
+ before_pull: "echo 'some unix command'"
111
+ after_pull: "touch public/restart.txt"
112
+
113
+ `before_pull` and `after_pull` will respectively be executed before and after pulling your language files.
114
+
108
115
  ## Rake tasks
109
116
 
110
117
  This gem includes some rake tasks and a rack middleware you could use to integrate Web Translate It with Ruby on Rails. The rake tasks are significantly slower than the executable, since it has to load the whole rails stack.
data/history.md CHANGED
@@ -1,4 +1,13 @@
1
- ## Edge
1
+ ## Version 1.7.0.2 / 2010-05-31
2
+
3
+ * Fix bug with file permissions.
4
+
5
+ ## Version 1.7.0.1 / 2010-05-31
6
+
7
+ * Handle server timeouts more gracefully, and retry request. Set timeout down to 20 secs.
8
+ * New: display warning if file is not writable.
9
+
10
+ ## Version 1.7.0 /2010-05-12
2
11
 
3
12
  * New: `wti server` launch a sinatra app allowing to sync files from a web interface.
4
13
  Pinched from Tom Lea’s awesome rack-webtranslate-it, but made less specific.
@@ -2,16 +2,29 @@ module WebTranslateIt
2
2
  class Project
3
3
 
4
4
  def self.fetch_info(api_key)
5
- WebTranslateIt::Util.http_connection do |http|
6
- request = Net::HTTP::Get.new("/api/projects/#{api_key}.yaml")
7
- Util.handle_response(http.request(request), true)
5
+ puts "Gathering project's information…"
6
+ begin
7
+ WebTranslateIt::Util.http_connection do |http|
8
+ request = Net::HTTP::Get.new("/api/projects/#{api_key}.yaml")
9
+ Util.handle_response(http.request(request), true)
10
+ end
11
+ rescue Timeout::Error
12
+ puts "The request timed out. The service may be overloaded. We will retry in 5 seconds."
13
+ sleep(5)
14
+ self.fetch_info(api_key)
8
15
  end
9
16
  end
10
17
 
11
18
  def self.fetch_stats(api_key)
12
- WebTranslateIt::Util.http_connection do |http|
13
- request = Net::HTTP::Get.new("/api/projects/#{api_key}/stats.yaml")
14
- Util.handle_response(http.request(request), true)
19
+ begin
20
+ WebTranslateIt::Util.http_connection do |http|
21
+ request = Net::HTTP::Get.new("/api/projects/#{api_key}/stats.yaml")
22
+ Util.handle_response(http.request(request), true)
23
+ end
24
+ rescue Timeout::Error
25
+ puts "The request timed out. The service may be overloaded. We will retry in 5 seconds."
26
+ sleep(5)
27
+ self.fetch_stats(api_key)
15
28
  end
16
29
  end
17
30
  end
@@ -9,6 +9,7 @@ module WebTranslateIt
9
9
  require 'net/https'
10
10
  require 'net/http/post/multipart'
11
11
  require 'time'
12
+ require 'ftools'
12
13
 
13
14
  attr_accessor :id, :file_path, :locale, :api_key
14
15
 
@@ -32,13 +33,23 @@ module WebTranslateIt
32
33
  # file.fetch(true) # force to re-download the file, will return the content of the file with a 200 OK
33
34
  #
34
35
  def fetch(force = false)
35
- WebTranslateIt::Util.http_connection do |http|
36
- request = Net::HTTP::Get.new(api_url)
37
- request.add_field('If-Modified-Since', last_modification) if File.exist?(self.file_path) and !force
38
- response = http.request(request)
39
- FileUtils.mkpath(self.file_path.split('/')[0..-2].join('/')) unless File.exist?(self.file_path)
40
- File.open(self.file_path, 'w'){ |file| file << response.body } if response.code.to_i == 200 and response.body != ''
41
- Util.handle_response(response)
36
+ begin
37
+ WebTranslateIt::Util.http_connection do |http|
38
+ request = Net::HTTP::Get.new(api_url)
39
+ request.add_field('If-Modified-Since', last_modification) if File.exist?(self.file_path) and !force
40
+ response = http.request(request)
41
+ FileUtils.mkpath(self.file_path.split('/')[0..-2].join('/')) unless File.exist?(self.file_path) or self.file_path.split('/')[0..-2].join('/') == ""
42
+ begin
43
+ File.open(self.file_path, 'wb'){ |file| file << response.body } if response.code.to_i == 200 and response.body != ''
44
+ Util.handle_response(response)
45
+ rescue
46
+ "\n/!\\ An error occured: #{$!}"
47
+ end
48
+ end
49
+ rescue Timeout::Error
50
+ puts "The request timed out. The service may be overloaded. We will retry in 5 seconds."
51
+ sleep(5)
52
+ fetch(force)
42
53
  end
43
54
  end
44
55
 
@@ -56,9 +67,15 @@ module WebTranslateIt
56
67
  def upload(merge=false, ignore_missing=false)
57
68
  if File.exists?(self.file_path)
58
69
  File.open(self.file_path) do |file|
59
- WebTranslateIt::Util.http_connection do |http|
60
- request = Net::HTTP::Put::Multipart.new(api_url, {"file" => UploadIO.new(file, "text/plain", file.path), "merge" => merge, "ignore_missing" => ignore_missing})
61
- Util.handle_response(http.request(request))
70
+ begin
71
+ WebTranslateIt::Util.http_connection do |http|
72
+ request = Net::HTTP::Put::Multipart.new(api_url, {"file" => UploadIO.new(file, "text/plain", file.path), "merge" => merge, "ignore_missing" => ignore_missing})
73
+ Util.handle_response(http.request(request))
74
+ end
75
+ rescue Timeout::Error
76
+ puts "The request timed out. The service may be overloaded. We will retry in 5 seconds."
77
+ sleep(5)
78
+ upload(merge, ignore_missing)
62
79
  end
63
80
  end
64
81
  else
@@ -80,9 +97,15 @@ module WebTranslateIt
80
97
  def create
81
98
  if File.exists?(self.file_path)
82
99
  File.open(self.file_path) do |file|
83
- WebTranslateIt::Util.http_connection do |http|
84
- request = Net::HTTP::Post::Multipart.new(api_url_for_create, { "name" => self.file_path, "file" => UploadIO.new(file, "text/plain", file.path) })
85
- Util.handle_response(http.request(request))
100
+ begin
101
+ WebTranslateIt::Util.http_connection do |http|
102
+ request = Net::HTTP::Post::Multipart.new(api_url_for_create, { "name" => self.file_path, "file" => UploadIO.new(file, "text/plain", file.path) })
103
+ Util.handle_response(http.request(request))
104
+ end
105
+ rescue Timeout::Error
106
+ puts "The request timed out. The service may be overloaded. We will retry in 5 seconds."
107
+ sleep(5)
108
+ create
86
109
  end
87
110
  end
88
111
  else
@@ -3,10 +3,10 @@ module WebTranslateIt
3
3
  class Util
4
4
 
5
5
  # Return a string representing the gem version
6
- # For example "1.4.4"
6
+ # For example "1.4.4.1"
7
7
  def self.version
8
8
  hash = YAML.load_file File.join(File.dirname(__FILE__), '..', '..' '/version.yml')
9
- [hash[:major], hash[:minor], hash[:patch]].join('.')
9
+ [hash[:major], hash[:minor], hash[:tiny], hash[:patch]].join('.')
10
10
  end
11
11
 
12
12
  # Yields a HTTP connection over SSL to Web Translate It.
@@ -22,7 +22,7 @@ module WebTranslateIt
22
22
  http = Net::HTTP.new('webtranslateit.com', 443)
23
23
  http.use_ssl = true
24
24
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
25
- http.read_timeout = 40
25
+ http.read_timeout = 20
26
26
  yield http
27
27
  end
28
28
 
data/version.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  ---
2
2
  :major: 1
3
3
  :minor: 7
4
- :patch: 0
4
+ :tiny: 0
5
+ :patch: 2
metadata CHANGED
@@ -1,12 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: web_translate_it
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 99
4
5
  prerelease: false
5
6
  segments:
6
7
  - 1
7
8
  - 7
8
9
  - 0
9
- version: 1.7.0
10
+ - 2
11
+ version: 1.7.0.2
10
12
  platform: ruby
11
13
  authors:
12
14
  - "\xC3\x89douard Bri\xC3\xA8re"
@@ -14,16 +16,18 @@ autorequire:
14
16
  bindir: bin
15
17
  cert_chain: []
16
18
 
17
- date: 2010-05-12 00:00:00 +02:00
19
+ date: 2010-05-31 00:00:00 +02:00
18
20
  default_executable: wti
19
21
  dependencies:
20
22
  - !ruby/object:Gem::Dependency
21
23
  name: multipart-post
22
24
  prerelease: false
23
25
  requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
24
27
  requirements:
25
28
  - - ~>
26
29
  - !ruby/object:Gem::Version
30
+ hash: 15
27
31
  segments:
28
32
  - 1
29
33
  - 0
@@ -34,9 +38,11 @@ dependencies:
34
38
  name: sinatra
35
39
  prerelease: false
36
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
43
  - - ~>
39
44
  - !ruby/object:Gem::Version
45
+ hash: 15
40
46
  segments:
41
47
  - 1
42
48
  - 0
@@ -47,9 +53,11 @@ dependencies:
47
53
  name: rspec
48
54
  prerelease: false
49
55
  requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
50
57
  requirements:
51
58
  - - ">="
52
59
  - !ruby/object:Gem::Version
60
+ hash: 13
53
61
  segments:
54
62
  - 1
55
63
  - 2
@@ -92,6 +100,14 @@ files:
92
100
  - man/wti.1
93
101
  - man/wti.1.html
94
102
  - man/wti.1.ron
103
+ - spec/examples/config/translation.yml
104
+ - spec/examples/en.yml
105
+ - spec/spec.opts
106
+ - spec/spec_helper.rb
107
+ - spec/web_translate_it/configuration_spec.rb
108
+ - spec/web_translate_it/translation_file_spec.rb
109
+ - spec/web_translate_it/util_spec.rb
110
+ - spec/web_translate_it_spec.rb
95
111
  has_rdoc: true
96
112
  homepage: https://webtranslateit.com
97
113
  licenses: []
@@ -103,23 +119,27 @@ rdoc_options:
103
119
  require_paths:
104
120
  - lib
105
121
  required_ruby_version: !ruby/object:Gem::Requirement
122
+ none: false
106
123
  requirements:
107
124
  - - ">="
108
125
  - !ruby/object:Gem::Version
126
+ hash: 3
109
127
  segments:
110
128
  - 0
111
129
  version: "0"
112
130
  required_rubygems_version: !ruby/object:Gem::Requirement
131
+ none: false
113
132
  requirements:
114
133
  - - ">="
115
134
  - !ruby/object:Gem::Version
135
+ hash: 3
116
136
  segments:
117
137
  - 0
118
138
  version: "0"
119
139
  requirements: []
120
140
 
121
141
  rubyforge_project:
122
- rubygems_version: 1.3.6
142
+ rubygems_version: 1.3.7
123
143
  signing_key:
124
144
  specification_version: 3
125
145
  summary: Sync your translations between your app and Web Translate It