require "net/http" require "uri" command :ping do |c| c.syntax = 'loom ping [options]' c.summary = 'ping the server as an authenticated user' c.description = 'ping the server to check if you have been authenticated' c.option '--env String', String, 'sets the authentication endpoint to a specific environment (for testing only).' c.example 'ping theengine.co', 'loom ping' c.action do |args, options| #default options options.default :env => "prod" if options.env == "prod" host = "theengine.co" elsif options.env == "staging" host = "theengineco-staging.herokuapp.com" elsif options.env == "local" host = "localhost:3000" else say "Environment #{options.env} is not supported" return end say "Pinging: #{host}" # send along the credentials endpoint = URI.parse("http://#{host}/api/v1/ping_authenticated?auth_token=#{get_token}") response = Net::HTTP.get_response(endpoint) if response.code == "200" say "Ping successful!" else say "Ping failed! #{response.body}" end end end