Class: Synthra::APIServer::WEBrickRequest
- Inherits:
-
Object
- Object
- Synthra::APIServer::WEBrickRequest
- Defined in:
- lib/synthra/api_server.rb
Overview
Request adapter for WEBrick
Instance Method Summary collapse
- #client_ip ⇒ Object
- #headers ⇒ Object
-
#initialize(req) ⇒ WEBrickRequest
constructor
A new instance of WEBrickRequest.
- #json_body ⇒ Object
- #method ⇒ Object
- #options? ⇒ Boolean
- #path ⇒ Object
- #post? ⇒ Boolean
- #query_params ⇒ Object
Constructor Details
#initialize(req) ⇒ WEBrickRequest
Returns a new instance of WEBrickRequest.
580 581 582 |
# File 'lib/synthra/api_server.rb', line 580 def initialize(req) @req = req end |
Instance Method Details
#client_ip ⇒ Object
608 609 610 |
# File 'lib/synthra/api_server.rb', line 608 def client_ip @req.peeraddr[2] end |
#headers ⇒ Object
604 605 606 |
# File 'lib/synthra/api_server.rb', line 604 def headers Hash[@req.header.map { |k, v| [k.tr("_", "-").downcase, v.first] }] end |
#json_body ⇒ Object
612 613 614 |
# File 'lib/synthra/api_server.rb', line 612 def json_body JSON.parse(@req.body || "{}") rescue {} end |
#method ⇒ Object
588 589 590 |
# File 'lib/synthra/api_server.rb', line 588 def method @req.request_method end |
#options? ⇒ Boolean
592 593 594 |
# File 'lib/synthra/api_server.rb', line 592 def method == "OPTIONS" end |
#path ⇒ Object
584 585 586 |
# File 'lib/synthra/api_server.rb', line 584 def path @req.path end |
#post? ⇒ Boolean
596 597 598 |
# File 'lib/synthra/api_server.rb', line 596 def post? method == "POST" end |
#query_params ⇒ Object
600 601 602 |
# File 'lib/synthra/api_server.rb', line 600 def query_params @req.query || {} end |