Class: ActiveRacksource::HTTP

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

Overview

Adapter … acts like Net::HTTP but actually works against a Rack application

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app = ActiveResource::Base.app) ⇒ HTTP

Initialized a new ActiveRacksource::HTTP

Parameters

app: a Rack application



14
15
16
# File 'lib/active_racksource/http.rb', line 14

def initialize app = ActiveResource::Base.app
  @app = RackBox::App.new app
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, url, *args) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/active_racksource/http.rb', line 18

def method_missing method, url, *args
  
  case args.length
  when 0
    headers = { }
  when 1
    headers = args.first
  when 2
    if args.last.is_a?Hash
      headers = args.last
      data    = args.first
    else
      raise "not sure howto #{ method.inspect } url:#{ url.inspect } with these args:#{ args.inspect }"
    end
  else
    raise "not sure howto #{ method.inspect } url:#{ url.inspect } with these args:#{ args.inspect }"
  end

  request_options = { }
  request_options[:method] = method
  request_options[:data]   = data   if data
  request_options.merge!( headers ) if headers

  rack_response = @app.request url, request_options

  ActiveRacksource::Response.new rack_response
end

Instance Attribute Details

#appObject

Rack application



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

def app
  @app
end