Sha256: 8ac0450001a464ce8037e612048346439443e9505d01cc7652df713adf7aaa87

Contents?: true

Size: 818 Bytes

Versions: 1

Compression:

Stored size: 818 Bytes

Contents

# frozen_string_literal: true

require 'uri'
require 'net/https'
require 'pry'
module SimpleHelper
  module Https
    class << self
      SimpleHelper::Const.supported_methods.each do |key, http_method|
        define_method key.to_s do |uri, params, headers|
          https = Net::HTTP.new(uri.host, uri.port)
          https.use_ssl = true
          https.verify_mode = OpenSSL::SSL::VERIFY_NONE

          req = http_method.new(uri, headers)
          req.body = params.to_json
          https.request(req)
        rescue Timeout::Error || Net::OpenTimeout
          puts "\e[31mTime out!\e[0m"
        rescue Net::HTTPBadResponse || SocketError
          puts "\e[31mRequest Failed!\e[0m"
        rescue StandardError
          puts "\e[31mAn unknown error occurred!\e[0m"
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
simple_request-0.1.1 lib/simple_helper/https.rb