Class: Rack::Webtranslateit::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/webtranslateit/configuration.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rack/webtranslateit/configuration.rb', line 6

def initialize
  unless file = self.class.config_location
    root = defined?(RAILS_ROOT) && RAILS_ROOT
    root ||= defined?(RACK_ROOT) && RACK_ROOT
    root ||= File.expand_path(".")
    file = File.join(root, 'config', 'translation.yml')
  end

  configuration       = YAML.load_file(file)
  self.api_key        = configuration['api_key']
  self.password       = configuration['password']
  self.master_locale  = configuration['master_locale'].to_s
  self.files          = []
  configuration['files'].each do |file_id, file_path|
    self.files.push(Rack::Webtranslateit::TranslationFile.new(file_id, file_path, api_key, master_locale))
  end
end

Class Attribute Details

.config_locationObject

Returns the value of attribute config_location.



44
45
46
# File 'lib/rack/webtranslateit/configuration.rb', line 44

def config_location
  @config_location
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



4
5
6
# File 'lib/rack/webtranslateit/configuration.rb', line 4

def api_key
  @api_key
end

#filesObject

Returns the value of attribute files.



4
5
6
# File 'lib/rack/webtranslateit/configuration.rb', line 4

def files
  @files
end

#master_localeObject

Returns the value of attribute master_locale.



4
5
6
# File 'lib/rack/webtranslateit/configuration.rb', line 4

def master_locale
  @master_locale
end

#passwordObject

Returns the value of attribute password.



4
5
6
# File 'lib/rack/webtranslateit/configuration.rb', line 4

def password
  @password
end

Class Method Details

.method_missing(name, *args) ⇒ Object



39
40
41
42
# File 'lib/rack/webtranslateit/configuration.rb', line 39

def method_missing(name, *args)
  @configuration ||= new
  @configuration.send(name, *args)
end

Instance Method Details

#localesObject



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rack/webtranslateit/configuration.rb', line 24

def locales
  http              = Net::HTTP.new('webtranslateit.com', 443)
  http.use_ssl      = true
  http.verify_mode  = OpenSSL::SSL::VERIFY_NONE
  http.read_timeout = 10
  request           = Net::HTTP::Get.new("/api/projects/#{api_key}/locales")
  response          = http.request(request)
  if response.code.to_i == 200
    response.body.split
  else
    []
  end
end