module WebService extend self #SERVICE_URL = "http://localhost:3000/dblinks" SERVICE_URL = "http://dblink.r15.railsrumble.com/dblinks" def register_link(database_url, is_public: false, verbose: false) require 'uri' require 'net/http' uri = URI(SERVICE_URL) http = Net::HTTP.new(uri.host, uri.port) request = Net::HTTP::Post.new(uri.path) params = { database_url: database_url, is_public: is_public } if verbose puts "HTTP POST: #{SERVICE_URL} #{JSON.generate(params)}" end response = http.post(uri.path, URI.encode_www_form(params)) if verbose puts response.class puts response.body end response_json = JSON.parse(response.body) response_json end end