Sha256: df5beac3a4fe36a2d949254c11ed08b9b8f2a5f71fbde421eac0902f57af2080

Contents?: true

Size: 1.04 KB

Versions: 7

Compression:

Stored size: 1.04 KB

Contents

class Kirk::Client
  class InvalidRequestError < ArgumentError ; end

  class Request
    attr_reader :group

    def initialize(group, method = nil, url = nil, handler = nil, body = nil, headers = {})
      @group    = group
      @url      = url
      @handler  = handler
      @body     = body
      @headers  = headers
      @method   = normalize_method(method)

      yield self if block_given?
    end

    %w/url headers handler body/.each do |method|
      class_eval <<-RUBY
        def #{method}(*args)
          @#{method} = args.first unless args.empty?
          @#{method}
        end
      RUBY
    end

    def method(*args)
      @method = normalize_method(args.first) unless args.empty?
      @method
    end

    def validate!
      unless method
        raise InvalidRequestError, "Must specify an HTTP method for the request"
      end

      unless url
        raise InvalidRequestError, "Must specify a URL for the request"
      end
    end

  private

    def normalize_method(method)
      method.to_s.upcase if method
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
kirk-0.2.0.beta.7-java lib/kirk/client/request.rb
kirk-0.2.0.beta.6-java lib/kirk/client/request.rb
kirk-0.2.0.beta.5-java lib/kirk/client/request.rb
kirk-0.2.0.beta.4-java lib/kirk/client/request.rb
kirk-0.2.0.beta.3-java lib/kirk/client/request.rb
kirk-0.2.0.beta.2-java lib/kirk/client/request.rb
kirk-0.2.0.beta.1-java lib/kirk/client/request.rb