Secure Static IP for Ruby HTTPS using HTTParty & Shield

Learn how to securely route Ruby HTTP traffic through a QuotaGuard Shield proxy using the HTTParty library.

Prerequisites

Ruby installed.

Instructions

Run example
QUOTAGUARDSHIELD_URL=... bin/qgpass ruby app.rb

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

Test in Docker
docker build -t qg-shield-ruby-httparty-example .
docker run -e QUOTAGUARDSHIELD_URL=... qg-shield-ruby-httparty-example

Code Samples

Ruby.rb
#!/usr/bin/env ruby
require 'httparty'
require 'uri'

proxy = URI.parse("http://localhost:8080")

options = {
  http_proxyaddr: proxy.host,
  http_proxyport: proxy.port
}

response = HTTParty.get('https://ip.quotaguard.com/', options)

puts response.body, response.code, response.message, response.headers.inspect
Docker File
# Use official Ruby image
FROM ruby:latest

# Install required gems
RUN gem install httparty

# Create a working directory in the container
WORKDIR /app

# Download and extract qgpass
RUN curl https://s3.amazonaws.com/quotaguard/qgpass-latest.tar.gz | tar xz -C /app/

# Copy the Ruby script into the container
COPY app.rb .

# Run our script through qgpass
CMD [ "/app/bin/qgpass", "ruby", "app.rb" ]