module Aigu class Puller PULL_PATH = '/public_api/latest_revision?language=%s&render_format=json&render_filename=aigu.json' def initialize(opts = {}) @output_file = opts[:'output-file'] @accent_api_key = opts[:'accent-api-key'] @accent_url = opts[:'accent-url'] @locale = opts[:'locale'] end def process! puts "Pulling JSON file `#{@output_file}` from Accent" puts '---' pull puts '---' puts 'Done' end protected def pull uri = URI(@accent_url + format(PULL_PATH, @locale)) http = Net::HTTP.new(uri.host, uri.port) uri.scheme == 'https' && http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(uri) request.add_field('Authorization', @accent_api_key) response = http.request(request) puts 'Response code: ' + response.code if response.code != '200' puts 'Error pulling string revision from Accent' exit 1 end puts "Generating #{@output_file}" File.open(@output_file, 'w+') do |file| file << response.body end end end end