Files
grecia/doc/api/examples/ruby/example_1.rb
Javi Martín a5aa39f6e2 Update GraphQL documentation
We don't use the `config/api.yml` file since commit c984e666f, and the
`.delete("\n").delete(" ")` in the code examples isn't necessary (we
should have probably added it in commit 56e42f209).

We're also changing the responses so there are no references to any
specific city.
2024-09-30 12:09:08 +02:00

30 lines
608 B
Ruby

require "net/http"
API_ENDPOINT = "https://demo.consuldemocracy.org/graphql".freeze
def make_request(query_string)
uri = URI(API_ENDPOINT)
uri.query = URI.encode_www_form(query: query_string)
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
{
proposal(id: 1) {
id,
title,
public_created_at
}
}
GRAPHQL
response = make_request(query)
puts "Response code: #{response.code}"
puts "Response body: #{response.body}"