Class: Synthra::APIServer::WEBrickRequest

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

Overview

Request adapter for WEBrick

Instance Method Summary collapse

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_ipObject



608
609
610
# File 'lib/synthra/api_server.rb', line 608

def client_ip
  @req.peeraddr[2]
end

#headersObject



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_bodyObject



612
613
614
# File 'lib/synthra/api_server.rb', line 612

def json_body
  JSON.parse(@req.body || "{}") rescue {}
end

#methodObject



588
589
590
# File 'lib/synthra/api_server.rb', line 588

def method
  @req.request_method
end

#options?Boolean

Returns:

  • (Boolean)


592
593
594
# File 'lib/synthra/api_server.rb', line 592

def options?
  method == "OPTIONS"
end

#pathObject



584
585
586
# File 'lib/synthra/api_server.rb', line 584

def path
  @req.path
end

#post?Boolean

Returns:

  • (Boolean)


596
597
598
# File 'lib/synthra/api_server.rb', line 596

def post?
  method == "POST"
end

#query_paramsObject



600
601
602
# File 'lib/synthra/api_server.rb', line 600

def query_params
  @req.query || {}
end