Sha256: bdcf77a061c84c08c7cc143663f9eab85cc8cd3f4e0593d16b87bac0aa0d7997

Contents?: true

Size: 1.13 KB

Versions: 10

Compression:

Stored size: 1.13 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, options.fetch(:format, format)].compact.join('.')
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
angellist_api-0.1.0 lib/angellist_api/request.rb
angellist_api-0.0.9 lib/angellist_api/request.rb
angellist_api-0.0.8 lib/angellist_api/request.rb
angellist_api-0.0.7 lib/angellist_api/request.rb
angellist_api-0.0.6 lib/angellist_api/request.rb
angellist_api-0.0.5 lib/angellist_api/request.rb
angellist_api-0.0.4 lib/angellist_api/request.rb
angellist_api-0.0.3 lib/angellist_api/request.rb
angellist_api-0.0.2 lib/angellist_api/request.rb
angellist_api-0.0.1 lib/angellist_api/request.rb