Secure Static IP for Ruby HTTPS using RestClient & Shield

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

Prerequisites

Ruby installed.

Instructions

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

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

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

Code Samples

rest-client.rb
#!/usr/bin/env ruby

require 'rest-client'
require 'uri'

# Use localhost and port 8080 for qgpass
quotaguard = URI.parse("http://localhost:8080")

RestClient.proxy = "http://#{quotaguard.host}:#{quotaguard.port}"

result = RestClient.get('https://ip.quotaguard.com')

puts result.body
Docker File
FROM ruby:latest

WORKDIR /app/

RUN gem install rest-client

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

COPY restclient.rb restclient.rb

ENTRYPOINT [ "/app/bin/qgpass", "ruby", "restclient.rb" ]