Skip to content

Commit

Permalink
Fix API examples
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
javierm committed Mar 1, 2023
1 parent 53e643b commit d36cbfa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
15 changes: 9 additions & 6 deletions doc/api/examples/ruby/example_1.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 10 additions & 6 deletions doc/api/examples/ruby/example_2.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
require "http"
require "net/http"
require "json"

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

def build_query(options = {})
Expand Down

0 comments on commit d36cbfa

Please sign in to comment.