Class: Kagerator::Request

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Request

Returns a new instance of Request.



13
14
15
16
17
18
19
20
21
22
# File 'lib/kagerator/request.rb', line 13

def initialize args
  @method = args[:method] or raise ArgumentError, "must pass :method"
  @headers = args[:headers] || {}
  if args[:url]
    @url = args[:url]
  else
    raise ArgumentError, "must pass :url"
  end
  @args = args
end

Class Method Details

.execute(args, &block) ⇒ Object



9
10
11
# File 'lib/kagerator/request.rb', line 9

def self.execute(args, &block)
  new(args).execute(&block)
end

Instance Method Details

#execute(&block) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/kagerator/request.rb', line 24

def execute &block
  response = ::RestClient.send(@method,API_URL+@url,@headers)
  if block_given?
    block.call(response, self, & block)
  end
  Kagerator::Response.new(response)
end