Fix API examples
We were getting many errors when trying to run them, from uninitialized constant `HTTP` to undefined method `headers`. We might move these examples to the documentation repository in the future, but we need to look for possible side-effects first.
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
require "http"
|
||||
require "net/http"
|
||||
|
||||
API_ENDPOINT = "https://demo.consulproject.org/graphql".freeze
|
||||
|
||||
def make_request(query_string)
|
||||
HTTP.headers("User-Agent" => "Mozilla/5.0", accept: "application/json")
|
||||
.get(
|
||||
API_ENDPOINT,
|
||||
params: { query: query_string.delete("\n").delete(" ") }
|
||||
)
|
||||
uri = URI(API_ENDPOINT)
|
||||
uri.query = URI.encode_www_form(query: query_string.delete("\n").delete(" "))
|
||||
request = Net::HTTP::Get.new(uri)
|
||||
request[:accept] = "application/json"
|
||||
|
||||
Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |https|
|
||||
https.request(request)
|
||||
end
|
||||
end
|
||||
|
||||
query = <<-GRAPHQL
|
||||
|
||||
Reference in New Issue
Block a user