class Aigu::Rails::Accent::LocaleDownloader

Public Class Methods

connection() click to toggle source
# File lib/aigu-rails/accent/locale_downloader.rb, line 15
def self.connection
  @connection ||= Faraday.new(url: Aigu::Rails.configuration.api_url)
end
new(locale:) click to toggle source
# File lib/aigu-rails/accent/locale_downloader.rb, line 5
def initialize(locale:)
  @locale = locale
end

Public Instance Methods

download!() click to toggle source
# File lib/aigu-rails/accent/locale_downloader.rb, line 9
def download!
  File.open(input_filename, 'w') do |file|
    file.write(parsed_response)
  end
end

Protected Instance Methods

input_filename() click to toggle source
# File lib/aigu-rails/accent/locale_downloader.rb, line 25
def input_filename
  "#{::Rails.root}/tmp/locales.json"
end
parsed_response() click to toggle source
# File lib/aigu-rails/accent/locale_downloader.rb, line 21
def parsed_response
  JSON.parse(response.body).to_json
end
response() click to toggle source
# File lib/aigu-rails/accent/locale_downloader.rb, line 29
def response
  self.class.connection.get do |req|
    req.url Aigu::Rails.configuration.default_path
    req.headers['Authorization'] = Aigu::Rails.configuration.api_key
    req.params = {
      language: @locale,
      render_format: 'json',
      render_filename: 'locales.json'
    }
  end
end