Sha256: 5c39446622386048a47ec05308e2972a0b082e25470d5ad80148abcdef984b28

Contents?: true

Size: 767 Bytes

Versions: 13

Compression:

Stored size: 767 Bytes

Contents

# encoding: utf-8

module FIR
  module Http
    MAX_RETRIES = 5

    %w(get post patch put).each do |_m|
      class_eval <<-METHOD, __FILE__, __LINE__ + 1
        def #{_m}(url, params = {})
          query = :#{_m} == :get ? { params: params } : params
          begin
            res = ::RestClient.#{_m}(url, query)
          rescue => e
            @retries ||= 0
            logger.error(e.message.to_s)
            if @retries < MAX_RETRIES
              @retries += 1
              logger.info("Retry \#{@retries} times......")
              sleep 2
              retry
            else
              exit 1
            end
          end
          JSON.parse(res.body.force_encoding('UTF-8'), symbolize_names: true)
        end
      METHOD
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
omt-cli-1.7.1 lib/fir/util/http.rb
omt-cli-1.7.0 lib/fir/util/http.rb
omt-cli-1.6.9 lib/fir/util/http.rb
omt-cli-1.6.8 lib/fir/util/http.rb
omt-cli-1.6.7 lib/fir/util/http.rb
omt-cli-1.6.6 lib/fir/util/http.rb
omt-cli-1.6.5 lib/fir/util/http.rb
omt-cli-1.6.4 lib/fir/util/http.rb
fir-cli-1.6.3 lib/fir/util/http.rb
fir-cli-1.6.2 lib/fir/util/http.rb
fir-cli-1.6.1 lib/fir/util/http.rb
fir-cli-1.6.0 lib/fir/util/http.rb
fir-cli-1.5.1 lib/fir/util/http.rb