Created
July 12, 2018 06:06
-
-
Save Reznov9185/393dce7af4ad403dfdb96fee1b00975b to your computer and use it in GitHub Desktop.
postman_with_ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'uri' | |
require 'net/http' | |
require 'json' | |
url = URI(ARGV[0].to_s) | |
http = Net::HTTP.new(url.host, url.port) | |
case ARGV[3].to_s | |
when "post" | |
request = Net::HTTP::Post.new(url) | |
when "get" | |
request = Net::HTTP::Get.new(url) | |
when "put" | |
request = Net::HTTP::Put.new(url) | |
when "delete" | |
request = Net::HTTP::Delete.new(url) | |
else | |
return | |
end | |
request.basic_auth ARGV[1].to_s, ARGV[2].to_s | |
response = http.request(request) | |
puts JSON.pretty_generate(response.read_body) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment