Sha256: 005c5e87aace69cb96d1536ae90bd39da4937e478d28b41353935ad3139162bc

Contents?: true

Size: 917 Bytes

Versions: 1

Compression:

Stored size: 917 Bytes

Contents

module Footrest
  module Request

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

    def get(path, options={})
      request_with_params_in_url(:get, path, options)
    end

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

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

    def request_with_params_in_url(method, path, options)
      request(method, options) do |r|
        r.url(File.join(path_prefix, path), options)
      end
    end

    def request_with_params_in_body(method, path, options)
      request(method, options) do |r|
        r.path = File.join(path_prefix, path)
        r.body = options unless options.empty?
      end
    end

    # Generic request
    def request(method, options, &block)
      connection.send(method, &block).body
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
footrest-0.1 lib/footrest/request.rb