Sha256: c6f83cc7cede5a3c9511c320a8bb85d75fdcbe667cd68dc5a38916e108c417ae

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

module Evrythng
  # Defines HTTP request methods
  module Request
    # Perform an HTTP GET request
    def get(path, options={}, format=format)
      request(:get, path, options, format)
    end

    # Perform an HTTP POST request
    def post(path, options={}, format=format)
      request(:post, path, options, format)
    end

    # Perform an HTTP PUT request
    def put(path, options={}, format=format)
      request(:put, path, options, format)
    end

    # Perform an HTTP DELETE request
    def delete(path, options={}, format=format)
      request(:delete, path, options, format)
    end

    private

    # Perform an HTTP request
    def request(method, path, options, format)
      response = connection(format).send(method) do |request|
        case method.to_sym
        when :get, :delete
          request.url(path, options)
        when :post, :put
          request.path = path
          request.body = options unless options.empty?
        end
      end
      'raw' == format.to_s.downcase ? response : response.body
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
evrythng-0.0.5 lib/evrythng/request.rb