class Bisu::Source::Url

Public Class Methods

new(url) click to toggle source
# File lib/bisu/source/url.rb, line 7
def initialize(url)
  @url = url
end

Public Instance Methods

to_i18() click to toggle source
# File lib/bisu/source/url.rb, line 11
def to_i18
  Logger.info("Downloading dictionary from #{@url}...")

  file = get(@url)
  hash = JSON.parse(file)

  Logger.info("Found #{hash.count} languages.")

  hash
end

Private Instance Methods

get(url) click to toggle source
# File lib/bisu/source/url.rb, line 24
def get(url)
  uri = URI(url)

  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE

  request = Net::HTTP::Get.new(uri.request_uri)
  response = http.request(request)

  raise "Bisu::Source::Url: Http Error #{response.body}" if response.code.to_i >= 400

  response.body
end