web_translate_it 1.9.1 → 1.9.2

Sign up to get free protection for your applications and to get access to all the features.
data/bin/wti CHANGED
@@ -6,7 +6,7 @@ require 'web_translate_it'
6
6
  show_commands = <<-EOS
7
7
  A CLI for syncing files with WebTranslateIt.com
8
8
 
9
- Usage: wti <command> [options]+
9
+ Usage: wti <command> [options]+ <filename>
10
10
 
11
11
  The most commonly used wti commands are:
12
12
 
@@ -92,7 +92,6 @@ EOS
92
92
  opt :config, "Path to a translation.yml file", :short => "-c", :default => ".wti"
93
93
  end
94
94
  when "status"
95
- when "st"
96
95
  Trollop::options do
97
96
  banner "Fetch and display project statistics"
98
97
  opt :config, "Path to a translation.yml file", :short => "-c", :default => ".wti"
data/history.md CHANGED
@@ -1,3 +1,20 @@
1
+ ## Version 1.9.2 / 2011-12-21
2
+
3
+ * Gem now includes library to connect to [String](http://docs.webtranslateit.com/api/string/) and [Translation](http://docs.webtranslateit.com/api/translation/) APIs, see #74 and #78. (@bray).
4
+ * Add `<filename>` placeholder.
5
+ * Bug fix: don’t crash when running `wti init` on an empty project.
6
+ * Bug fix: File API was returning `102 Continue` error status when fetching a file begin currently imported. It was making subsequent requests fail. The File API now returns `503 Service Unavailable`. Client was updated to handle this status.
7
+ * Fix `wti status` command.
8
+ * Improvement: truncate `wti pull` performance statistics (`Pulled 10 files in 0.7 seconds at 13.4 files/sec`).
9
+ * Fix: Configuration file lookup improvements. Configuration files can now be located in another directory, and `wti` commands don’t have to be executed in the root directory. It is now possible to execute:
10
+
11
+ ```
12
+ wti pull
13
+ wti pull -c /Users/edouard/code/test/.wti
14
+ wti pull -c ../.wti
15
+ wti pull -c ~/code/.wti
16
+ ```
17
+
1
18
  ## Version 1.9.1 / 2011-12-08
2
19
 
3
20
  * Add `wti rm` and `wti rmlocale` to CLI help.
@@ -41,7 +41,7 @@ module WebTranslateIt
41
41
  end
42
42
  threads.each { |thread| thread.join }
43
43
  time = Time.now - time
44
- puts "Pulled #{files.count} files in #{time} seconds at #{files.count/time} files/sec."
44
+ puts "Pulled #{files.count} files in #{time.round(1)} seconds at #{(files.count/time).round(1)} files/sec."
45
45
  `#{configuration.after_pull}` if configuration.after_pull
46
46
  end
47
47
 
@@ -177,8 +177,6 @@ module WebTranslateIt
177
177
  end
178
178
  end
179
179
 
180
- alias :st :status
181
-
182
180
  def server
183
181
  puts "This feature is deprecated and was extracted to a separate gem,"
184
182
  puts " `web_translate_it_server`."
@@ -16,7 +16,7 @@ module WebTranslateIt
16
16
  def initialize(root_path = Rails.root, path_to_config_file = ".wti")
17
17
  self.path = root_path
18
18
  self.logger = logger
19
- configuration = YAML.load_file(File.join(self.path, path_to_config_file))
19
+ configuration = YAML.load_file(File.expand_path(path_to_config_file, self.path))
20
20
  self.api_key = configuration['api_key']
21
21
  self.before_pull = configuration['before_pull']
22
22
  self.after_pull = configuration['after_pull']
@@ -13,7 +13,7 @@ module WebTranslateIt
13
13
  return response.body
14
14
  else
15
15
  puts "An error occured while fetching the project information:"
16
- puts response.body.failure
16
+ puts StringUtil.failure(response.body)
17
17
  exit
18
18
  end
19
19
  end
@@ -0,0 +1,99 @@
1
+ # encoding: utf-8
2
+ module WebTranslateIt
3
+ class String
4
+ require 'net/https'
5
+
6
+ attr_accessor :id, :api_key
7
+
8
+ def initialize(id, api_key)
9
+ self.id = id
10
+ self.api_key = api_key
11
+ end
12
+
13
+ def self.list(http_connection, api_key, params = {}, options = {})
14
+ options.reverse_merge!(:format => 'yaml')
15
+
16
+ url = "/api/projects/#{api_key}/strings.#{options[:format]}"
17
+ url += '?' + HashUtil.to_param(params) unless params.blank?
18
+
19
+ request = Net::HTTP::Get.new(url)
20
+ request.add_field("X-Client-Name", "web_translate_it")
21
+ request.add_field("X-Client-Version", WebTranslateIt::Util.version)
22
+
23
+ begin
24
+ Util.handle_response(http_connection.request(request), true)
25
+ rescue Timeout::Error
26
+ puts "The request timed out. The service may be overloaded. We will retry in 5 seconds."
27
+ sleep(5)
28
+ retry
29
+ end
30
+ end
31
+
32
+ def show(http_connection, options = {})
33
+ options.reverse_merge!(:format => 'yaml')
34
+
35
+ request = Net::HTTP::Get.new("/api/projects/#{self.api_key}/strings/#{self.id}.#{options[:format]}")
36
+ request.add_field("X-Client-Name", "web_translate_it")
37
+ request.add_field("X-Client-Version", WebTranslateIt::Util.version)
38
+
39
+ begin
40
+ Util.handle_response(http_connection.request(request), true)
41
+ rescue Timeout::Error
42
+ puts "The request timed out. The service may be overloaded. We will retry in 5 seconds."
43
+ sleep(5)
44
+ retry
45
+ end
46
+ end
47
+
48
+ def update(http_connection, params = {}, options = {})
49
+ options.reverse_merge!(:format => 'yaml')
50
+
51
+ request = Net::HTTP::Put.new("/api/projects/#{self.api_key}/strings/#{self.id}.#{options[:format]}")
52
+ request.add_field("X-Client-Name", "web_translate_it")
53
+ request.add_field("X-Client-Version", WebTranslateIt::Util.version)
54
+ request.add_field("Content-Type", "application/json")
55
+
56
+ request.body = params.to_json
57
+
58
+ begin
59
+ Util.handle_response(http_connection.request(request), true)
60
+ rescue Timeout::Error
61
+ puts "The request timed out. The service may be overloaded. We will retry in 5 seconds."
62
+ sleep(5)
63
+ retry
64
+ end
65
+ end
66
+
67
+ def self.create(http_connection, api_key, params = {})
68
+ request = Net::HTTP::Post.new("/api/projects/#{api_key}/strings")
69
+ request.add_field("X-Client-Name", "web_translate_it")
70
+ request.add_field("X-Client-Version", WebTranslateIt::Util.version)
71
+ request.add_field("Content-Type", "application/json")
72
+
73
+ request.body = params.to_json
74
+
75
+ begin
76
+ Util.handle_response(http_connection.request(request), true)
77
+ rescue Timeout::Error
78
+ puts "The request timed out. The service may be overloaded. We will retry in 5 seconds."
79
+ sleep(5)
80
+ retry
81
+ end
82
+ end
83
+
84
+ def delete(http_connection)
85
+ request = Net::HTTP::Delete.new("/api/projects/#{self.api_key}/strings/#{self.id}")
86
+ request.add_field("X-Client-Name", "web_translate_it")
87
+ request.add_field("X-Client-Version", WebTranslateIt::Util.version)
88
+
89
+ begin
90
+ Util.handle_response(http_connection.request(request), true)
91
+ rescue Timeout::Error
92
+ puts "The request timed out. The service may be overloaded. We will retry in 5 seconds."
93
+ sleep(5)
94
+ retry
95
+ end
96
+ end
97
+
98
+ end
99
+ end
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+ module WebTranslateIt
3
+ class Translation
4
+ require 'net/https'
5
+
6
+ attr_accessor :id, :locale, :api_key
7
+
8
+ def initialize(id, locale, api_key)
9
+ self.id = id
10
+ self.locale = locale
11
+ self.api_key = api_key
12
+ end
13
+
14
+ def show(http_connection, options = {})
15
+ options.reverse_merge!(:format => 'yaml')
16
+
17
+ request = Net::HTTP::Get.new("/api/projects/#{self.api_key}/strings/#{self.id}/locales/#{self.locale}/translations.#{options[:format]}")
18
+ request.add_field("X-Client-Name", "web_translate_it")
19
+ request.add_field("X-Client-Version", WebTranslateIt::Util.version)
20
+
21
+ begin
22
+ Util.handle_response(http_connection.request(request), true)
23
+ rescue Timeout::Error
24
+ puts "The request timed out. The service may be overloaded. We will retry in 5 seconds."
25
+ sleep(5)
26
+ retry
27
+ end
28
+ end
29
+
30
+ def create(http_connection, params = {})
31
+ request = Net::HTTP::Post.new("/api/projects/#{self.api_key}/strings/#{self.id}/locales/#{self.locale}/translations")
32
+ request.add_field("X-Client-Name", "web_translate_it")
33
+ request.add_field("X-Client-Version", WebTranslateIt::Util.version)
34
+ request.add_field("Content-Type", "application/json")
35
+
36
+ request.body = params.to_json
37
+
38
+ begin
39
+ Util.handle_response(http_connection.request(request), true)
40
+ rescue Timeout::Error
41
+ puts "The request timed out. The service may be overloaded. We will retry in 5 seconds."
42
+ sleep(5)
43
+ retry
44
+ end
45
+ end
46
+
47
+ end
48
+ end
@@ -0,0 +1,7 @@
1
+ class HashUtil
2
+ def self.to_param(hash, namespace = nil) # taken from Rails
3
+ hash.collect do |key, value|
4
+ value.to_query(namespace ? "#{namespace}[#{key}]" : key)
5
+ end.sort * '&'
6
+ end
7
+ end
@@ -56,16 +56,16 @@ module WebTranslateIt
56
56
 
57
57
  def self.handle_response(response, return_response = false)
58
58
  if response.code.to_i >= 400 and response.code.to_i < 500
59
- StringUtil.failure("Error: Can't find project for this API key.")
60
- elsif response.code.to_i >= 500
59
+ StringUtil.failure("Error: Can't find project with this API key.")
60
+ elsif response.code.to_i == 500
61
61
  StringUtil.failure("Error: Server temporarily unavailable. Please try again shortly.")
62
62
  else
63
63
  return response.body if return_response
64
- return StringUtil.failure("Server currently processing file. Please retry later.") if response.code.to_i == 102
65
64
  return StringUtil.success("OK") if response.code.to_i == 200
66
65
  return StringUtil.success("Created") if response.code.to_i == 201
67
66
  return StringUtil.success("Accepted") if response.code.to_i == 202
68
67
  return StringUtil.success("Not Modified") if response.code.to_i == 304
68
+ return StringUtil.failure("Unavail") if response.code.to_i == 503
69
69
  end
70
70
  end
71
71
 
@@ -3,8 +3,11 @@
3
3
  require 'web_translate_it/util'
4
4
  require 'web_translate_it/util/array_util'
5
5
  require 'web_translate_it/util/string_util'
6
+ require 'web_translate_it/util/hash_util'
6
7
  require 'web_translate_it/configuration'
7
8
  require 'web_translate_it/translation_file'
9
+ require 'web_translate_it/string'
10
+ require 'web_translate_it/translation'
8
11
  require 'web_translate_it/auto_fetch'
9
12
  require 'web_translate_it/command_line'
10
13
  require 'web_translate_it/project'
data/version.yml CHANGED
@@ -1,5 +1,4 @@
1
- ---
2
1
  :major: 1
3
2
  :minor: 9
4
- :patch: 1
3
+ :patch: 2
5
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: web_translate_it
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.1
4
+ version: 1.9.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-08 00:00:00.000000000 Z
12
+ date: 2011-12-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multipart-post
16
- requirement: &70346835324020 !ruby/object:Gem::Requirement
16
+ requirement: &70191931766220 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.1.3
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70346835324020
24
+ version_requirements: *70191931766220
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: trollop
27
- requirement: &70346835323520 !ruby/object:Gem::Requirement
27
+ requirement: &70191931765720 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.16.2
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70346835323520
35
+ version_requirements: *70191931765720
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70346835323060 !ruby/object:Gem::Requirement
38
+ requirement: &70191931765260 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: 2.6.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70346835323060
46
+ version_requirements: *70191931765260
47
47
  description:
48
48
  email: edouard@atelierconvivialite.com
49
49
  executables:
@@ -63,8 +63,11 @@ files:
63
63
  - lib/web_translate_it/command_line.rb
64
64
  - lib/web_translate_it/configuration.rb
65
65
  - lib/web_translate_it/project.rb
66
+ - lib/web_translate_it/string.rb
67
+ - lib/web_translate_it/translation.rb
66
68
  - lib/web_translate_it/translation_file.rb
67
69
  - lib/web_translate_it/util/array_util.rb
70
+ - lib/web_translate_it/util/hash_util.rb
68
71
  - lib/web_translate_it/util/string_util.rb
69
72
  - lib/web_translate_it/util.rb
70
73
  - lib/web_translate_it.rb