Class: Tortilla::RequestBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/tortilla.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRequestBuilder

Returns a new instance of RequestBuilder.



10
11
12
13
14
# File 'lib/tortilla.rb', line 10

def initialize
  @url = ""
  @headers = {}
  @response_parser = nil
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/tortilla.rb', line 16

def method_missing(meth,*args,&block)
  @url = @url+"/"+meth.to_s

  if(!args.first.nil? && !args.nil?)
    @url+"/"+args.first
  end

  return self
end

Instance Attribute Details

#headersObject

Returns the value of attribute headers.



7
8
9
# File 'lib/tortilla.rb', line 7

def headers
  @headers
end

#response_parserObject

Returns the value of attribute response_parser.



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

def response_parser
  @response_parser
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

Instance Method Details

#get(*args) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/tortilla.rb', line 26

def get(*args)
  puts @url
  response = HTTParty.get(@url)
  if(!@response_parser.nil?)
    parsed = @response_parser.call(response)
  else
    parsed = JSON.parse(response.body)
  end

  return parsed
end