Class: WebTranslateIt::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/web_translate_it/project.rb

Class Method Summary collapse

Class Method Details

.fetch_info(api_key) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/web_translate_it/project.rb', line 4

def self.fetch_info(api_key)
  WebTranslateIt::Util.http_connection do |http|
    request  = Net::HTTP::Get.new("/api/projects/#{api_key}.yaml")
    response = http.request(request)
    if response.code.to_i >= 400 and response.code.to_i < 500
      puts "We had a problem connecting to Web Translate It with this API key."
      puts "Make sure it is correct."
      exit
    elsif response.code.to_i >= 500
      puts "Web Translate It is temporarily unavailable. Please try again shortly."
      exit
    else
      return response.body
    end
  end
end

.fetch_stats(api_key) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/web_translate_it/project.rb', line 21

def self.fetch_stats(api_key)
  WebTranslateIt::Util.http_connection do |http|
    request  = Net::HTTP::Get.new("/api/projects/#{api_key}/stats.yaml")
    response = http.request(request)
    if response.code.to_i >= 400 and response.code.to_i < 500
      puts "We had a problem connecting to Web Translate It with this API key."
      puts "Make sure it is correct."
      exit
    elsif response.code.to_i >= 500
      puts "Web Translate It is temporarily unavailable. Please try again shortly."
      exit
    else
      return response.body
    end
  end
end