Module: EndpointFlux::Rails::Concerns::EndpointController
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/endpoint_flux/rails/concerns/endpoint_controller.rb
Instance Method Summary collapse
- #endpoint_for(namespace) ⇒ Object
- #endpoint_params ⇒ Object
- #present(namespace) ⇒ Object
- #remote_ip ⇒ Object
- #request_object ⇒ Object
Instance Method Details
#endpoint_for(namespace) ⇒ Object
14 15 16 17 |
# File 'lib/endpoint_flux/rails/concerns/endpoint_controller.rb', line 14 def endpoint_for(namespace) return namespace unless ::EndpointFlux.config.endpoints_namespace (::EndpointFlux.config.endpoints_namespace + '/' + namespace).camelize.constantize end |
#endpoint_params ⇒ Object
27 28 29 |
# File 'lib/endpoint_flux/rails/concerns/endpoint_controller.rb', line 27 def endpoint_params params.permit!.except(:controller, :action, :format).to_h.deep_symbolize_keys end |
#present(namespace) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/endpoint_flux/rails/concerns/endpoint_controller.rb', line 7 def present(namespace) _, response = endpoint_for(namespace).perform(request_object) headers.merge! response.headers render json: response.body end |
#remote_ip ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/endpoint_flux/rails/concerns/endpoint_controller.rb', line 31 def remote_ip ip = request.remote_ip.to_s if ip == '127.0.0.1' ip = request.env['HTTP_X_FORWARDED_FOR'] end ip end |
#request_object ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/endpoint_flux/rails/concerns/endpoint_controller.rb', line 19 def request_object ::EndpointFlux::Request.new( headers: headers.merge('Authorization' => request.headers['authorization']), remote_ip: remote_ip, params: endpoint_params ) end |