Right now I am currently running into this error message while making a simple GET request in ruby:
#<SocketError: Failed to open TCP connection to api.github.com:443 (getaddrinfo: nodename nor servname provided, or not known)>
This is my ruby code:
require 'uri'
require 'net/http'
class RequestDouble
def initialize(endpoint)
@endpoint = endpoint
end
def send_get_request
url = URI(endpoint)
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Get.new(url)
request['Content-Type'] = 'application/json'
response = https.request(request)
JSON.parse(response.read_body)
rescue StandardError => e
{ 'status' => 500, 'detail' => 'Something went wrong' }
end
private
attr_accessor :endpoint
end
And this is the execution of the request:
github_request = RequestDouble.new('https://api.github.com/repos/robskrob/personal-site')
github_request.send_get_request
Does anyone see why I'm getting the above SocketError
message? Does anyone know how I can successfully make the GET request in ruby? This request https://api.github.com/repos/robskrob/personal-site
works just fine in postman and in my browser.