Sha256: 32ca72bfb5eb0fb8ee9264060155c488c58b3d41a26d05935e9cb8543e22937c

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 KB

Contents

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

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

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

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

    private

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

    def formatted_path(path, options={})
      path
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
angellist_api-1.0.1 lib/angellist_api/request.rb
angellist_api-0.1.2 lib/angellist_api/request.rb
angellist_api-1.0.0 lib/angellist_api/request.rb