Sha256: 8093b7d7ecf99b52395162aa86058f89c97f36057ddfcfd2fd519ba77b379271

Contents?: true

Size: 920 Bytes

Versions: 21

Compression:

Stored size: 920 Bytes

Contents

require 'acfs/request/callbacks'

module Acfs

  # Encapsulate all data required to make up a request to the
  # underlaying http library.
  #
  class Request
    attr_accessor :body, :format
    attr_reader :url, :headers, :params, :data, :method

    include Request::Callbacks

    def initialize(url, options = {}, &block)
      @url = URI.parse(url.to_s).tap do |url|
        @data    = options.delete(:data) || nil
        @format  = options.delete(:format) || :json
        @headers = options.delete(:headers) || {}
        @params  = options.delete(:params) || {}
        @method  = options.delete(:method) || :get

        url.query = nil # params.any? ? params.to_param : nil
      end.to_s
      on_complete &block if block_given?
    end

    def data?
      !data.nil?
    end

    class << self
      def new(*attrs)
        return attrs[0] if attrs[0].is_a? self
        super
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
acfs-0.34.0.1.b286 lib/acfs/request.rb
acfs-0.34.0 lib/acfs/request.rb
acfs-0.33.1.1.b285 lib/acfs/request.rb
acfs-0.33.1.1.b281 lib/acfs/request.rb
acfs-0.33.1 lib/acfs/request.rb
acfs-0.33.0.1.b278 lib/acfs/request.rb
acfs-0.33.0 lib/acfs/request.rb
acfs-0.32.1.1.b277 lib/acfs/request.rb
acfs-0.32.1.1.b276 lib/acfs/request.rb
acfs-0.32.1.1.b275 lib/acfs/request.rb
acfs-0.32.1.1.b274 lib/acfs/request.rb
acfs-0.32.1.1.b272 lib/acfs/request.rb
acfs-0.32.1 lib/acfs/request.rb
acfs-0.32.0.1.b270 lib/acfs/request.rb
acfs-0.31.0.1.b269 lib/acfs/request.rb
acfs-0.32.0 lib/acfs/request.rb
acfs-0.31.0.1.b265 lib/acfs/request.rb
acfs-0.31.0.1.b263 lib/acfs/request.rb
acfs-0.31.0 lib/acfs/request.rb
acfs-0.30.0.1.b262 lib/acfs/request.rb