web_translate_it 1.6.6 → 1.6.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  [Homepage](https://webtranslateit.com) |
4
4
  [RDocs](http://yardoc.org/docs/AtelierConvivialite-webtranslateit) |
5
- [Metrics](http://getcaliper.com/caliper/project?repo=git%3A%2F%2Fgithub.com%2FAtelierConvivialite%2Fwebtranslateit.git) |
6
5
  [Example app](http://github.com/AtelierConvivialite/rails_example_app) |
7
6
  [Report a bug](http://github.com/AtelierConvivialite/webtranslateit/issues) |
8
7
  [Support](http://help.webtranslateit.com)
data/history.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## Version 1.6.7 /2010-05-05
2
+
3
+ * New: `wti add file_path` to create a new master language file on Web Translate It.
4
+ This is only for master language files. Target language files are created server-side,
5
+ and can be updated using `wti push --all`.
6
+
1
7
  ## Version 1.6.6 /2010-04-26
2
8
 
3
9
  * New: `--merge` option to force WTI to perform a merge of this file with its database.
@@ -6,6 +6,7 @@ module WebTranslateIt
6
6
  OPTIONS = <<-OPTION
7
7
  pull Pull target language file(s) from Web Translate It.
8
8
  push Push master language file(s) to Web Translate It.
9
+ add Create a new master language file to Web Translate It.
9
10
  autoconf Configure your project to sync with Web Translate It.
10
11
  stats Fetch and display your project statistics.
11
12
 
@@ -32,6 +33,8 @@ OPTION
32
33
  pull
33
34
  when 'push'
34
35
  push
36
+ when 'add'
37
+ add
35
38
  when 'autoconf'
36
39
  autoconf
37
40
  when 'stats'
@@ -61,8 +64,8 @@ OPTION
61
64
  STDOUT.sync = true
62
65
  configuration = fetch_configuration
63
66
  fetch_locales_to_push(configuration).each do |locale|
64
- merge = !(ARGV.index('--merge')).nil?
65
- ignore_missing = !(ARGV.index('--ignore_missing')).nil?
67
+ merge = !(ARGV.index('--merge')).nil?
68
+ ignore_missing = !(ARGV.index('--ignore_missing')).nil?
66
69
  configuration.files.find_all{ |file| file.locale == locale }.each do |file|
67
70
  print "Pushing #{file.file_path}… "
68
71
  puts file.upload(merge, ignore_missing)
@@ -70,6 +73,15 @@ OPTION
70
73
  end
71
74
  end
72
75
 
76
+ def self.add
77
+ STDOUT.sync = true
78
+ configuration = fetch_configuration
79
+ file_path = fetch_file_to_add(configuration)
80
+ file = TranslationFile.new(nil, file_path, nil, configuration.api_key)
81
+ print "Creating #{file.file_path}… "
82
+ puts file.create
83
+ end
84
+
73
85
  def self.autoconf
74
86
  puts "We will attempt to configure your project automagically"
75
87
  api_key = Util.ask("Please enter your project API Key")
@@ -147,6 +159,12 @@ OPTION
147
159
  return locales.uniq
148
160
  end
149
161
 
162
+ def self.fetch_file_to_add(configuration)
163
+ index = ARGV.index('add')
164
+ file_path = ARGV[index+1].strip
165
+ return file_path
166
+ end
167
+
150
168
  def self.fetch_locales_to_push(configuration)
151
169
  if (index = ARGV.index('-l') || ARGV.index('--locale')).nil?
152
170
  locales = [configuration.source_locale]
@@ -43,7 +43,6 @@ module WebTranslateIt
43
43
  end
44
44
 
45
45
  # Update a language file to Web Translate It by performing a PUT Request.
46
- # Note that it is currently not possible to POST a new language file at the moment.
47
46
  #
48
47
  # Example of implementation:
49
48
  #
@@ -52,10 +51,8 @@ module WebTranslateIt
52
51
  # file = configuration.files.first
53
52
  # file.upload # should respond the HTTP code 202 Accepted
54
53
  #
55
- # The meaning of the HTTP 202 code is: the request has been accepted for processing, but the processing has not
56
- # been completed. The request might or might not eventually be acted upon, as it might be disallowed when processing
57
- # actually takes place.
58
- # This is due to the fact that language file imports are handled by background processing.
54
+ # Note that the request might or might not eventually be acted upon, as it might be disallowed when processing
55
+ # actually takes place. This is due to the fact that language file imports are handled by background processing.
59
56
  def upload(merge=false, ignore_missing=false)
60
57
  if File.exists?(self.file_path)
61
58
  File.open(self.file_path) do |file|
@@ -68,6 +65,30 @@ module WebTranslateIt
68
65
  puts "\nFile #{self.file_path} doesn't exist!"
69
66
  end
70
67
  end
68
+
69
+ # Create a language file to Web Translate It by performing a POST Request.
70
+ #
71
+ # Example of implementation:
72
+ #
73
+ # configuration = WebTranslateIt::Configuration.new
74
+ # file = TranslationFile.new(nil, file_path, nil, configuration.api_key)
75
+ # file.create # should respond the HTTP code 201 Created
76
+ #
77
+ # Note that the request might or might not eventually be acted upon, as it might be disallowed when processing
78
+ # actually takes place. This is due to the fact that language file imports are handled by background processing.
79
+ #
80
+ def create
81
+ if File.exists?(self.file_path)
82
+ 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))
86
+ end
87
+ end
88
+ else
89
+ puts "\nFile #{self.file_path} doesn't exist!"
90
+ end
91
+ end
71
92
 
72
93
  protected
73
94
 
@@ -80,5 +101,9 @@ module WebTranslateIt
80
101
  def api_url
81
102
  "/api/projects/#{self.api_key}/files/#{self.id}/locales/#{self.locale}"
82
103
  end
104
+
105
+ def api_url_for_create
106
+ "/api/projects/#{self.api_key}/files"
107
+ end
83
108
  end
84
109
  end
@@ -43,6 +43,8 @@ module WebTranslateIt
43
43
  else
44
44
  return response.body if return_response
45
45
  return "200 OK" if response.code.to_i == 200
46
+ return "201 Created" if response.code.to_i == 201
47
+ return "202 Accepted" if response.code.to_i == 202
46
48
  return "304 Not Modified" if response.code.to_i == 304
47
49
  end
48
50
  end
data/version.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 1
3
3
  :minor: 6
4
- :patch: 6
4
+ :patch: 7
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 6
8
- - 6
9
- version: 1.6.6
8
+ - 7
9
+ version: 1.6.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - "\xC3\x89douard Bri\xC3\xA8re"
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-26 00:00:00 +02:00
17
+ date: 2010-05-05 00:00:00 +02:00
18
18
  default_executable: wti
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency