Sha256: fee838ed572c917fea27fee6c80e91500a17d149256f4561b1f71186f3a169fd

Contents?: true

Size: 740 Bytes

Versions: 20

Compression:

Stored size: 740 Bytes

Contents

require 'open-uri'
require 'openssl'

module TerraformDevKit
  class Request
    def initialize(url, query_strings: [], headers: {})
      @url = url
      @query_strings = query_strings
      @headers = headers
    end

    def execute(raise_on_codes: [])
      url = URI.parse(@url)
      url.query = URI.encode_www_form(@query_strings) unless @query_strings.empty?
      puts "Fetching #{url}"
      options = {
        redirect: false,
        ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE
      }
      options.merge!(@headers)
      open(url, options)
    rescue OpenURI::HTTPError => error
      response = error.io
      raise if raise_on_codes.include?(response.status[0])
      response
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
TerraformDevKit-0.3.8 lib/TerraformDevKit/request.rb
TerraformDevKit-0.3.7 lib/TerraformDevKit/request.rb
TerraformDevKit-0.3.6 lib/TerraformDevKit/request.rb
TerraformDevKit-0.3.5 lib/TerraformDevKit/request.rb
TerraformDevKit-0.3.4 lib/TerraformDevKit/request.rb
TerraformDevKit-0.3.3 lib/TerraformDevKit/request.rb
TerraformDevKit-0.3.2 lib/TerraformDevKit/request.rb
TerraformDevKit-0.3.1 lib/TerraformDevKit/request.rb
TerraformDevKit-0.3.1.pre.rc1 lib/TerraformDevKit/request.rb
TerraformDevKit-0.2.7 lib/TerraformDevKit/request.rb
TerraformDevKit-0.2.6 lib/TerraformDevKit/request.rb
TerraformDevKit-0.2.5 lib/TerraformDevKit/request.rb
TerraformDevKit-0.2.2 lib/TerraformDevKit/request.rb
TerraformDevKit-0.2.0 lib/TerraformDevKit/request.rb
TerraformDevKit-0.1.14 lib/TerraformDevKit/request.rb
TerraformDevKit-0.1.13 lib/TerraformDevKit/request.rb
TerraformDevKit-0.1.12 lib/TerraformDevKit/request.rb
TerraformDevKit-0.1.11 lib/TerraformDevKit/request.rb
TerraformDevKit-0.1.10 lib/TerraformDevKit/request.rb
TerraformDevKit-0.1.9 lib/TerraformDevKit/request.rb