Module: RouterHelper
- Defined in:
- lib/router_helper.rb
Instance Method Summary collapse
- #generate_third_party_url ⇒ Object
- #rest_client_url(url, _payload = {}) ⇒ Object
- #services_development_urls ⇒ Object
- #services_production_urls ⇒ Object
- #services_uri ⇒ Object
Instance Method Details
#generate_third_party_url ⇒ Object
45 46 47 48 |
# File 'lib/router_helper.rb', line 45 def generate_third_party_url urls = send("services_#{Rails.env}_urls") urls.map {|key,values| values.map {|k,v| define_method("#{key}_host_service_#{k}") { v }}} end |
#rest_client_url(url, _payload = {}) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/router_helper.rb', line 3 def rest_client_url(url, _payload = {}) payload = _payload[:params] || {} payload[:referer_service] = current_micro_service_name headers = {"#{jwt_header_name}" => jwt_header_token} headers = headers.merge(_payload[:headers]) if _payload[:headers] verb = _payload[:method] begin data = RestClient::Request.execute(method: verb, url: url, payload: payload, headers: headers) data = {code: data.code, data: JSON.parse(data.body), headers: data.headers, cookies: data.} rescue RestClient::Unauthorized, RestClient::Forbidden => err data = JSON.parse(err.response) rescue RestClient::ResourceNotFound => err data = {code: 404, error: "Url not found #{_req.url}" } rescue RestClient::InternalServerError => err data = {code: 500, error: "Url not found #{_req.url}" } end data end |
#services_development_urls ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/router_helper.rb', line 22 def services_development_urls @_services_development_urls ||= {user: {url: "http://localhost", port: 3000}, practice: {url: "http://localhost", port: 3001}, mocktest: {url: "http://localhost", port: 3002}, payment: {url: "http://localhost", port: 3003}, content: {url: "http://localhost", port: 3004}, } end |
#services_production_urls ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/router_helper.rb', line 35 def services_production_urls @_services_production_urls ||= {user: {url: "http://user.embibe.com", port: nil}, mocktest: {url: "http://mocktest.embibe.com", port: nil}, practice: {url: "http://practice.embibe.com", port: nil}, payment: {url: "http://payment.embibe.com", port: nil}, content: {url: "http://content.embibe.com", port: nil}, } end |
#services_uri ⇒ Object
31 32 33 |
# File 'lib/router_helper.rb', line 31 def services_uri @_services_uri ||= send("services_#{Rails.env}_urls") end |