Sha256: 784f9908e5cf2e047763a6caa86ae37a601e6431ea3115e1d35b620f7ffd9445

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

# encoding: utf-8
module WebTranslateIt
  class Project
    
    def self.fetch_info(api_key)
      begin
        WebTranslateIt::Util.http_connection do |http|
          request = Net::HTTP::Get.new("/api/projects/#{api_key}.yaml")
          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)
        self.fetch_info(api_key)
      end
    end
    
    def self.fetch_stats(api_key)
      begin
        WebTranslateIt::Util.http_connection do |http|
          request = Net::HTTP::Get.new("/api/projects/#{api_key}/stats.yaml")
          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)
        self.fetch_stats(api_key)
      end
    end
    
    def self.create_locale(api_key, locale_code)
      begin
        WebTranslateIt::Util.http_connection do |http|
          request = Net::HTTP::Post.new("/api/projects/#{api_key}/locales")
          request.set_form_data({ 'id' => locale_code }, ';')
          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)
        self.create_locale(api_key, locale_code)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
web_translate_it-1.7.3.1 lib/web_translate_it/project.rb