Sha256: 4e407c256c71eeb0707055cf7cdbac6ef3e9cc415fef3459ac64ae2e81f4009e

Contents?: true

Size: 1.08 KB

Versions: 13

Compression:

Stored size: 1.08 KB

Contents

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

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

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

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

    private

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

    def formatted_path(path)
      [path, format].compact.join('.')
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
assistly-0.2.6 lib/assistly/request.rb
assistly-0.2.5 lib/assistly/request.rb
assistly-0.2.4 lib/assistly/request.rb
assistly-0.2.3 lib/assistly/request.rb
assistly-0.2.2 lib/assistly/request.rb
assistly-0.2.1 lib/assistly/request.rb
assistly-0.2.0 lib/assistly/request.rb
assistly-0.1.5 lib/assistly/request.rb
assistly-0.1.4 lib/assistly/request.rb
assistly-0.1.3 lib/assistly/request.rb
assistly-0.1.2 lib/assistly/request.rb
assistly-0.1.1 lib/assistly/request.rb
assistly-0.1 lib/assistly/request.rb