Sha256: 9d1e2137d3092313b6f91337e25a266168b8031909eeb3fd7f1acfec8c283784

Contents?: true

Size: 920 Bytes

Versions: 3

Compression:

Stored size: 920 Bytes

Contents

module CoinMarketCap
  module Cloud
    module Request
      def get(path, options = {})
        request(:get, path, options)
      end

      def post(path, options = {})
        request(:post, path, options)
      end

      def put(path, options = {})
        request(:put, path, options)
      end

      def delete(path, options = {})
        request(:delete, path, options)
      end

      private

      def request(method, path, options)
        path = [endpoint, path].join('/')
        response = connection.send(method) do |request|
          case method
          when :get, :delete
            request.url(path, options)
          when :post, :put
            request.path = path
            request.body = options.to_json unless options.empty?
          end
          request.options.merge!(options.delete(:request)) if options.key?(:request)
        end
        response.body
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
coinmarketcap-ruby-client-1.1.1 lib/coinmarketcap/cloud/request.rb
coinmarketcap-ruby-client-1.1.0 lib/coinmarketcap/cloud/request.rb
coinmarketcap-ruby-client-1.0.0 lib/coinmarketcap/cloud/request.rb