Sha256: 7076a9f82b2e1adfce2166620e98d629993b959c29cc4629785bfd9ba361eb15

Contents?: true

Size: 843 Bytes

Versions: 6

Compression:

Stored size: 843 Bytes

Contents

module Grenache
  class Http
    class HttpClient
      include HTTParty

      def initialize config
        @config = config
      end

      def request uri, body, params = {}
        options = {body: body}

        if params[:timeout]
          options[:timeout] = params[:timeout]
        else
          options[:timeout] = timeout if timeout
        end

        if tls?
          options[:pem]         = pem
          options[:ssl_ca_file] = ssl_ca_file
        end

        self.class.post uri, options
      end

      private

      def tls?
        !! @config.cert_pem
      end

      def pem
        cert = File.read @config.cert_pem
        key = File.read @config.key
        cert + key
      end

      def ssl_ca_file
        @config.ca
      end

      def timeout
        @config.service_timeout
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
grenache-ruby-http-0.2.11 lib/grenache/http/http_client.rb
grenache-ruby-http-0.2.9 lib/grenache/http/http_client.rb
grenache-ruby-http-0.2.8 lib/grenache/http/http_client.rb
grenache-ruby-http-0.2.7 lib/grenache/http/http_client.rb
grenache-ruby-http-0.2.4 lib/grenache/http/http_client.rb
grenache-ruby-http-0.2.3 lib/grenache/http/http_client.rb