phrase 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/Gemfile.lock +2 -0
  2. data/lib/phrase/tool.rb +34 -4
  3. data/phrase.gemspec +1 -1
  4. metadata +2 -2
data/Gemfile.lock CHANGED
@@ -4,6 +4,7 @@ GEM
4
4
  addressable (2.2.7)
5
5
  crack (0.3.1)
6
6
  diff-lcs (1.1.3)
7
+ json (1.6.5)
7
8
  rspec (2.8.0)
8
9
  rspec-core (~> 2.8.0)
9
10
  rspec-expectations (~> 2.8.0)
@@ -21,6 +22,7 @@ PLATFORMS
21
22
  ruby
22
23
 
23
24
  DEPENDENCIES
25
+ json
24
26
  rspec
25
27
  vcr
26
28
  webmock (~> 1.7.0)
data/lib/phrase/tool.rb CHANGED
@@ -121,14 +121,28 @@ module PhraseGem
121
121
 
122
122
  def pull(config)
123
123
  locale = args[1]
124
+
125
+ locales = []
126
+ if locale && locale.strip != ''
127
+ locales = [locale]
128
+ else
129
+ locales = fetch_locales(config)
130
+ end
131
+
132
+ locales.each do |locale|
133
+ fetch_translation_for_locale(config, locale)
134
+ end
135
+ end
136
+
137
+ def fetch_translation_for_locale(config, locale)
124
138
  print "Downloading phrase.#{locale}.yml..."
125
139
  ::FileUtils.mkdir_p("phrase/locales")
126
-
140
+
127
141
  http = http_client(config)
128
-
142
+
129
143
  request = Net::HTTP::Get.new("#{config.api_path_prefix}/translations/download?auth_token=#{config.secret}&locale=#{locale}")
130
144
  res = http.request(request)
131
-
145
+
132
146
  if res.code.to_s =~ /200/
133
147
  puts " OK"
134
148
  File.open("phrase/locales/phrase.#{locale}.yml", "w") do |file|
@@ -139,6 +153,22 @@ module PhraseGem
139
153
  print_server_error(res)
140
154
  end
141
155
  end
156
+
157
+ def fetch_locales(config)
158
+ http = http_client(config)
159
+
160
+ request = Net::HTTP::Get.new("#{config.api_path_prefix}/locales?auth_token=#{config.secret}")
161
+ res = http.request(request)
162
+
163
+ if res.code.to_s =~ /200/
164
+ puts " Fetched all locales"
165
+ return JSON.parse(res.body).map { |locale| locale['name'] }
166
+ else
167
+ puts " Failed"
168
+ print_server_error(res)
169
+ exit(47)
170
+ end
171
+ end
142
172
 
143
173
  def print_server_error(res, filename=nil)
144
174
  error_message = server_error_message(res.body)
@@ -149,7 +179,7 @@ module PhraseGem
149
179
  begin
150
180
  JSON.parse(body)["error"]
151
181
  rescue JSON::ParserError
152
- "Unkown error"
182
+ "Unknown error"
153
183
  end
154
184
  end
155
185
 
data/phrase.gemspec CHANGED
@@ -4,7 +4,7 @@ $:.unshift lib unless $:.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "phrase"
7
- s.version = "0.0.3"
7
+ s.version = "0.0.4"
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Dynport GmbH"]
10
10
  s.email = ["info@phraseapp.com"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phrase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-16 00:00:00.000000000Z
12
+ date: 2012-03-22 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: The best way to manage i18n.
15
15
  email: