Sha256: 697ab6e149fc460071ba9ae95e32885687bc4023a793a223a4dac0e6db380974

Contents?: true

Size: 938 Bytes

Versions: 12

Compression:

Stored size: 938 Bytes

Contents

module Footrest
  module Request

    def fullpath(path)
      raise "fullpath should be overridden"
    end

    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) do |r|
        r.url(fullpath(path), options)
      end
    end

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

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

  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
footrest-0.5.7 lib/footrest/request.rb
footrest-0.5.6 lib/footrest/request.rb
footrest-0.5.5 lib/footrest/request.rb
footrest-0.5.3 lib/footrest/request.rb
footrest-0.5.2 lib/footrest/request.rb
footrest-0.5.1 lib/footrest/request.rb
footrest-0.5.0 lib/footrest/request.rb
footrest-0.4.1 lib/footrest/request.rb
footrest-0.3.1 lib/footrest/request.rb
footrest-0.3.0 lib/footrest/request.rb
footrest-0.2.2 lib/footrest/request.rb
footrest-0.2.0 lib/footrest/request.rb