Skip to content

Instantly share code, notes, and snippets.

@clementi
Last active March 7, 2019 23:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clementi/8b68e75dc90be95492be24ec0f771422 to your computer and use it in GitHub Desktop.
Save clementi/8b68e75dc90be95492be24ec0f771422 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'json'
require 'net/http'
def success?(status_code)
status_code[0] == '2'
end
begin
code = ARGV.length < 1 ? ARGF.read : ARGV[0]
uri = URI("http://pointfree.io/snippet?code=#{URI.encode_www_form_component(code)}")
req = Net::HTTP::Get.new(uri)
req['Accept'] = 'application/json'
res = Net::HTTP.start(uri.hostname, uri.port) do |http|
http.request(req)
end
success?(res.code) or raise IOError.new("Received HTTP #{res.code}")
parsed = JSON.parse(res.body)
puts parsed['code']
rescue StandardError => e
puts "Error: #{e.message}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment