Skip to content

Instantly share code, notes, and snippets.

@Reznov9185
Created July 12, 2018 06:06
Show Gist options
  • Save Reznov9185/393dce7af4ad403dfdb96fee1b00975b to your computer and use it in GitHub Desktop.
Save Reznov9185/393dce7af4ad403dfdb96fee1b00975b to your computer and use it in GitHub Desktop.
postman_with_ruby
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