Sha256: e2ff0e04c38d0d0fdbf7b1631c2b929c48778f91ad49a222398d0be238940634

Contents?: true

Size: 1.15 KB

Versions: 57

Compression:

Stored size: 1.15 KB

Contents

require "net/http"
require "openssl"

module ShopifyCLI
  class HttpRequest
    class << self
      def post(uri, body, headers)
        req = ::Net::HTTP::Post.new(uri.request_uri)
        request(uri, body, headers, req)
      end

      def put(uri, body, headers)
        req = ::Net::HTTP::Put.new(uri.request_uri)
        request(uri, body, headers, req)
      end

      def get(uri, body, headers)
        req = ::Net::HTTP::Get.new(uri.request_uri)
        request(uri, body, headers, req)
      end

      def delete(uri, body, headers)
        req = ::Net::HTTP::Delete.new(uri.request_uri)
        request(uri, body, headers, req)
      end

      def request(uri, body, headers, req)
        cert_store = OpenSSL::X509::Store.new
        cert_store.set_default_paths

        http = ::Net::HTTP.new(uri.host, uri.port)
        http.use_ssl = true
        http.cert_store = cert_store
        http.verify_mode = OpenSSL::SSL::VERIFY_NONE if ENV["SSL_VERIFY_NONE"]

        req.body = body unless body.nil?
        req["Content-Type"] = "application/json"
        headers.each { |header, value| req[header] = value }
        http.request(req)
      end
    end
  end
end

Version data entries

57 entries across 57 versions & 1 rubygems

Version Path
shopify-cli-2.36.0 lib/shopify_cli/http_request.rb
shopify-cli-2.35.0 lib/shopify_cli/http_request.rb
shopify-cli-2.34.0 lib/shopify_cli/http_request.rb
shopify-cli-2.33.1 lib/shopify_cli/http_request.rb
shopify-cli-2.33.0 lib/shopify_cli/http_request.rb
shopify-cli-2.32.1 lib/shopify_cli/http_request.rb
shopify-cli-2.32.0 lib/shopify_cli/http_request.rb
shopify-cli-2.31.0 lib/shopify_cli/http_request.rb
shopify-cli-2.30.0 lib/shopify_cli/http_request.rb
shopify-cli-2.29.0 lib/shopify_cli/http_request.rb
shopify-cli-2.28.0 lib/shopify_cli/http_request.rb
shopify-cli-2.27.0 lib/shopify_cli/http_request.rb
shopify-cli-2.26.0 lib/shopify_cli/http_request.rb
shopify-cli-2.25.0 lib/shopify_cli/http_request.rb
shopify-cli-2.24.0 lib/shopify_cli/http_request.rb
shopify-cli-2.23.0 lib/shopify_cli/http_request.rb
shopify-cli-2.22.0 lib/shopify_cli/http_request.rb
shopify-cli-2.21.0 lib/shopify_cli/http_request.rb
shopify-cli-2.20.1 lib/shopify_cli/http_request.rb
shopify-cli-2.20.0 lib/shopify_cli/http_request.rb