Class: Preposterous::Request

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/preposterous/request.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, method, path, options = {}) ⇒ Request

Returns a new instance of Request.



16
17
18
# File 'lib/preposterous/request.rb', line 16

def initialize(client, method, path, options={})
  @client, @method, @path, @options = client, method, path, options
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/preposterous/request.rb', line 6

def client
  @client
end

#methodObject (readonly)

Returns the value of attribute method.



6
7
8
# File 'lib/preposterous/request.rb', line 6

def method
  @method
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/preposterous/request.rb', line 6

def options
  @options
end

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/preposterous/request.rb', line 6

def path
  @path
end

Class Method Details

.get(client, path, options = {}) ⇒ Object



8
9
10
# File 'lib/preposterous/request.rb', line 8

def self.get(client, path, options={})
  new(client, :get, path, options).perform
end

.post(client, path, options = {}) ⇒ Object



12
13
14
# File 'lib/preposterous/request.rb', line 12

def self.post(client, path, options={})
  new(client, :post, path, options).perform
end

Instance Method Details

#performObject



31
32
33
# File 'lib/preposterous/request.rb', line 31

def perform
  Preposterous.make_friendly(send("perform_#{method}"))
end

#uriObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/preposterous/request.rb', line 20

def uri
  @uri ||= begin
    uri = URI.parse(path)
    if options[:fields] && options[:fields] != {}
      uri.query = to_query(options[:fields])
    end

    uri.to_s
  end
end