web_translate_it 1.5.0 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/history.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## Version 1.5.1 /2010-03-09
2
+
3
+ * Add `wti stats`, to fetch the project stats from the stats API endpoint.
4
+
1
5
  ## Version 1.5.0 /2010-02-19
2
6
 
3
7
  Warning, some deprecations in this version.
@@ -6,6 +6,7 @@ module WebTranslateIt
6
6
  pull Pull target language file(s) from Web Translate It.
7
7
  push Push master language file(s) to Web Translate It.
8
8
  autoconf Configure your project to sync with Web Translate It.
9
+ stats Fetch and display your project statistics.
9
10
 
10
11
  OPTIONAL PARAMETERS:
11
12
  --------------------
@@ -29,6 +30,8 @@ OPTION
29
30
  push
30
31
  when 'autoconf'
31
32
  autoconf
33
+ when 'stats'
34
+ stats
32
35
  when '-v', '--version'
33
36
  show_version
34
37
  when '-h', '--help'
@@ -82,6 +85,16 @@ OPTION
82
85
  puts "Check `wti --help` for more information."
83
86
  end
84
87
 
88
+ def self.stats
89
+ configuration = fetch_configuration
90
+ stats = YAML.load(Project.fetch_stats(configuration.api_key))
91
+ stats.each do |locale, values|
92
+ percent_translated = Util.calculate_percentage(values['count_strings_to_proofread'] + values['count_strings_done'] + values['count_strings_to_verify'], values['count_strings'])
93
+ percent_completed = Util.calculate_percentage(values['count_strings_done'], values['count_strings'])
94
+ puts "#{locale}: #{percent_translated}% translated, #{percent_completed}% completed #{values['stale'] ? "Stale" : ""}"
95
+ end
96
+ end
97
+
85
98
  def self.show_options
86
99
  puts ""
87
100
  puts "Web Translate It Help:"
@@ -15,7 +15,24 @@ module WebTranslateIt
15
15
  else
16
16
  return response.body
17
17
  end
18
- end
18
+ end
19
+ end
20
+
21
+ def self.fetch_stats(api_key)
22
+ WebTranslateIt::Util.http_connection do |http|
23
+ request = Net::HTTP::Get.new("/api/projects/#{api_key}/stats.yaml")
24
+ response = http.request(request)
25
+ if response.code.to_i >= 400 and response.code.to_i < 500
26
+ puts "We had a problem connecting to Web Translate It with this API key."
27
+ puts "Make sure it is correct."
28
+ exit
29
+ elsif response.code.to_i >= 500
30
+ puts "Web Translate It is temporarily unavailable. Please try again shortly."
31
+ exit
32
+ else
33
+ return response.body
34
+ end
35
+ end
19
36
  end
20
37
  end
21
38
  end
@@ -26,5 +26,10 @@ module WebTranslateIt
26
26
  http.read_timeout = 40
27
27
  yield http
28
28
  end
29
+
30
+ def self.calculate_percentage(processed, total)
31
+ return 0 if total == 0
32
+ ((processed*10)/total).to_f.ceil*10
33
+ end
29
34
  end
30
35
  end
data/version.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 1
3
3
  :minor: 5
4
- :patch: 0
4
+ :patch: 1
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.5.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - "\xC3\x89douard Bri\xC3\xA8re"
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-19 00:00:00 +01:00
12
+ date: 2010-03-09 00:00:00 +01:00
13
13
  default_executable: wti
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency