Skip to content

Commit 5e4e40c

Browse files
committed
Convert: get-dojos-from-earth[.sh -> .rb]
by using the curl-to-ruby website! 🆒 https://jhawthorn.github.io/curl-to-ruby/
1 parent 98a16b4 commit 5e4e40c

File tree

2 files changed

+50
-21
lines changed

2 files changed

+50
-21
lines changed

get-dojos-from-earth.rb

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env ruby
2+
3+
require 'net/http'
4+
require 'uri'
5+
require 'json'
6+
7+
uri = URI.parse("https://zen.coderdojo.com/api/2.0/dojos")
8+
request = Net::HTTP::Post.new(uri)
9+
request.content_type = "application/json"
10+
request["Accept"] = "application/json"
11+
request.body = JSON.dump({
12+
"query" => {
13+
"verified" => 1,
14+
"deleted" => 0,
15+
"fields$" => [
16+
"name",
17+
"geo_point",
18+
"stage",
19+
"url_slug",
20+
"start_time",
21+
"end_time",
22+
"private",
23+
"frequency",
24+
"alternative_frequency",
25+
"day"
26+
]
27+
}
28+
})
29+
30+
req_options = {
31+
use_ssl: uri.scheme == "https",
32+
}
33+
34+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
35+
http.request(request)
36+
end
37+
38+
DOJOS_JSON = JSON.pretty_generate(JSON.parse response.body)
39+
40+
File.open("dojos_earth.json", "w") do |file|
41+
file.write(DOJOS_JSON)
42+
end
43+
44+
# Show next step for developers
45+
puts DOJOS_JSON
46+
puts ''
47+
puts 'Status Code: ' + response.code
48+
puts ''
49+
puts 'Check out JSON data you fetched by:'
50+
puts '$ cat dojos_earth.json'

get-dojos-from-earth.sh

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)