Sha256: ca4f40720c1a64fd6f13cdc04b6c2081dd76e9df7921db70ed2022291c7287ea

Contents?: true

Size: 805 Bytes

Versions: 3

Compression:

Stored size: 805 Bytes

Contents

require 'colorize'
require 'net/http'
require 'json'

module Icapps
  module Translations
    class Http
      class << self
        def authenticated_response(path, is_json=false)
          uri = URI("#{config.url}/#{path}")
          puts "[VERBOSE] Connecting to url '#{uri}'.".colorize(:white) if options[:verbose]

          http = Net::HTTP.new(uri.host, uri.port)
          request =  Net::HTTP::Get.new(uri)
          request.add_field "Authorization", "Token token=#{config.project_key}"
          response = http.request(request)
          is_json ? JSON.parse(response.body) : response.body
        end

        private

        def options
          ::Icapps::Translations.options
        end

        def config
          ::Icapps::Translations.config
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
icapps-translations-0.2.0 lib/icapps/translations/http.rb
icapps-translations-0.1.1 lib/icapps/translations/http.rb
icapps-translations-0.1.0 lib/icapps/translations/http.rb