Class: WebTranslateIt::Project
- Inherits:
-
Object
- Object
- WebTranslateIt::Project
- Defined in:
- lib/web_translate_it/project.rb
Class Method Summary collapse
- .create_locale(locale_code) ⇒ Object
- .delete_locale(locale_code) ⇒ Object
- .fetch_info(api_key) ⇒ Object
- .fetch_stats(api_key) ⇒ Object
Class Method Details
.create_locale(locale_code) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/web_translate_it/project.rb', line 44 def self.create_locale(locale_code) begin request = Net::HTTP::Post.new("/api/projects/#{Connection.api_key}/locales") request.add_field("X-Client-Name", "web_translate_it") request.add_field("X-Client-Version", WebTranslateIt::Util.version) request.set_form_data({ 'id' => locale_code }, ';') Util.handle_response(Connection.http_connection.request(request), true) rescue Timeout::Error puts "The request timed out. The service may be overloaded. We will retry in 5 seconds." sleep(5) retry end end |
.delete_locale(locale_code) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/web_translate_it/project.rb', line 58 def self.delete_locale(locale_code) begin request = Net::HTTP::Delete.new("/api/projects/#{Connection.api_key}/locales/#{locale_code}") request.add_field("X-Client-Name", "web_translate_it") request.add_field("X-Client-Version", WebTranslateIt::Util.version) Util.handle_response(Connection.http_connection.request(request), true) rescue Timeout::Error puts "The request timed out. The service may be overloaded. We will retry in 5 seconds." sleep(5) retry end end |
.fetch_info(api_key) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/web_translate_it/project.rb', line 5 def self.fetch_info(api_key) begin WebTranslateIt::Connection.new(api_key) do |http| request = Net::HTTP::Get.new("/api/projects/#{api_key}.yaml") request.add_field("X-Client-Name", "web_translate_it") request.add_field("X-Client-Version", WebTranslateIt::Util.version) response = http.request(request) if response.is_a?(Net::HTTPSuccess) return response.body else puts "An error occured while fetching the project information:" puts StringUtil.failure(response.body) exit end end rescue Timeout::Error puts "The request timed out. The service may be overloaded. We will retry in 5 seconds." sleep(5) retry rescue puts $!.inspect end end |
.fetch_stats(api_key) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/web_translate_it/project.rb', line 29 def self.fetch_stats(api_key) begin WebTranslateIt::Connection.new(api_key) do |http| request = Net::HTTP::Get.new("/api/projects/#{api_key}/stats.yaml") request.add_field("X-Client-Name", "web_translate_it") request.add_field("X-Client-Version", WebTranslateIt::Util.version) return Util.handle_response(http.request(request), true) end rescue Timeout::Error puts "The request timed out. The service may be overloaded. We will retry in 5 seconds." sleep(5) retry end end |