Setup a Static IP for Ruby HTTPS using HTTParty

Learn how to route Ruby HTTP traffic through a QuotaGuard Static IP using the HTTParty library.

Prerequisites

N/A

Instructions

Run example
QUOTAGUARDSTATIC_URL=... ruby httparty.rb

Be sure to set QUOTAGUARDSTATIC_URL to your Connection URL from the QuotaGuard Dashboard.

Test in Docker
docker build -t qg-static-ruby-httparty-example .
docker run -e QUOTAGUARDSTATIC_URL=... qg-static-ruby-httparty-example

Code Samples

httparty.rb
#!/usr/bin/env ruby

require 'httparty'
require 'uri'

raise 'Missing environment variable' unless ENV['QUOTAGUARDSTATIC_URL']
quotaguard = URI.parse(ENV["QUOTAGUARDSTATIC_URL"])

result = HTTParty.get('https://ip.quotaguard.com', {
  http_proxyaddr: quotaguard.host,
  http_proxyport: quotaguard.port,
  http_proxyuser: quotaguard.user,
  http_proxypass: quotaguard.password
})

puts result.body

Docker File
FROM ruby:latest

WORKDIR /app/

RUN gem install httparty

COPY httparty.rb httparty.rb

ENTRYPOINT [ "ruby", "httparty.rb" ]