Class: Icapps::Translations::Http

Inherits:
Object
  • Object
show all
Defined in:
lib/icapps/translations/http.rb

Class Method Summary collapse

Class Method Details

.authenticated_response(path, is_json = false) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/icapps/translations/http.rb', line 9

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