Sha256: 94306f6f3237e6fdc218dc4b80d57930415fc9eeae0335c32edd7b88547d0014

Contents?: true

Size: 848 Bytes

Versions: 11

Compression:

Stored size: 848 Bytes

Contents

require "net/http"
require "openssl"

module AkamaiCCU
  class Client
    attr_reader :net_klass, :host

    def initialize(host:, net_klass: Net::HTTP)
      @host = host
      @net_klass = net_klass
    end

    def call(path:, method: POST, initheader: JSON_HEADER)
      request(path, method, initheader)
      yield @request if block_given?
      Thread.new { http.request(@request) }.value
    end

    private def base_uri
      @base_uri ||= URI("#{SSL}://#{host}")
    end

    private def http
      @http ||= @net_klass.new(base_uri.host, base_uri.port).tap do |http|
        http.use_ssl = true
        http.verify_mode = OpenSSL::SSL::VERIFY_PEER
      end
    end

    private def request(path, klass = GET, initheader = nil)
      @request ||= @net_klass.const_get(klass).new(base_uri.merge(path).to_s, initheader)
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
akamai_ccu-1.5.4 lib/akamai_ccu/client.rb
akamai_ccu-1.5.3 lib/akamai_ccu/client.rb
akamai_ccu-1.5.2 lib/akamai_ccu/client.rb
akamai_ccu-1.5.1 lib/akamai_ccu/client.rb
akamai_ccu-1.5.0 lib/akamai_ccu/client.rb
akamai_ccu-1.4.1 lib/akamai_ccu/client.rb
akamai_ccu-1.4.0 lib/akamai_ccu/client.rb
akamai_ccu-1.3.9 lib/akamai_ccu/client.rb
akamai_ccu-1.3.8 lib/akamai_ccu/client.rb
akamai_ccu-1.3.7 lib/akamai_ccu/client.rb
akamai_ccu-1.3.6 lib/akamai_ccu/client.rb