Sha256: 5b69e53eb69834ec22a0e9ed1320f15d2be3a3126dd4e2635104f054ccdc3108

Contents?: true

Size: 694 Bytes

Versions: 4

Compression:

Stored size: 694 Bytes

Contents

# frozen_string_literal: true

module DoHClient
  module Client
    class Request
      def get(url, query)
        res = http.headers(headers).get(url, params: query);
        return JSON.parse(res.body.to_s) if res.code == 200
        raise ResponseError, res.body.to_s
      end

      def self.get(url, query)
        new.get(url, query);
      end

      def headers
        {
          accept: "application/dns-json",
          user_agent: "curl/7.54.0"
        }
      end

      def http
        if proxy = ENV["HTTPS_RPOXY"] || ENV["https_proxy"]
          uri = URI(proxy)
          HTTP.via(uri.hostname, uri.port)
        else
          HTTP
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
doh_client-0.2.1 lib/doh_client/client/request.rb
doh_client-0.2.0 lib/doh_client/client/request.rb
doh_client-0.1.1 lib/doh_client/client/request.rb
doh_client-0.1.0 lib/doh_client/client/request.rb