Class: ActiveRacksource::HTTP
- Inherits:
-
Object
- Object
- ActiveRacksource::HTTP
- Defined in:
- lib/active_racksource/http.rb
Overview
Adapter … acts like Net::HTTP but actually works against a Rack application
Instance Attribute Summary collapse
-
#app ⇒ Object
Rack application.
Instance Method Summary collapse
-
#initialize(app = ActiveResource::Base.app) ⇒ HTTP
constructor
Initialized a new ActiveRacksource::HTTP.
- #method_missing(method, url, *args) ⇒ Object
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 = { } [:method] = method [:data] = data if data .merge!( headers ) if headers rack_response = @app.request url, ActiveRacksource::Response.new rack_response end |
Instance Attribute Details
#app ⇒ Object
Rack application
7 8 9 |
# File 'lib/active_racksource/http.rb', line 7 def app @app end |