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_preprod_urls ⇒ Object
- #services_production_urls ⇒ Object
- #services_staging_urls ⇒ Object
- #services_uri ⇒ Object
Instance Method Details
#generate_third_party_url ⇒ Object
73 74 75 76 |
# File 'lib/router_helper.rb', line 73 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 21 22 |
# 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::, RestClient::Forbidden => err data = JSON.parse(err.response) rescue RestClient::ResourceNotFound => err data = {code: 404, error: "Url not found #{url}" } rescue RestClient::InternalServerError => err data = {code: 500, error: "Server side exception" } rescue Exception => ex data = {code: 503, error: ex. } end data end |
#services_development_urls ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/router_helper.rb', line 24 def services_development_urls @_services_development_urls ||= { user: {url: "http://localhost", port: 3000}, horizontal: {url: "http://localhost", port: 3005}, content: {url: "http://localhost", port: 3004}, practice: {url: "http://localhost", port: 3001}, mocktest: {url: "http://localhost", port: 3002}, payment: {url: "http://localhost", port: 3003} } end |
#services_preprod_urls ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/router_helper.rb', line 46 def services_preprod_urls @_services_preprod_urls ||= { user: {url: "http://user-microservice", port: 80}, horizontal: {url: "http://horizontal-microservice", port: 80}, content: {url: "http://content-microservice", port: 80}, mocktest: {url: "http://mocktest-microservice", port: 80}, practice: {url: "http://practice-microservice", port: 9297}, payment: {url: "http://payment-microservice", port: 9297} } end |
#services_production_urls ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/router_helper.rb', line 61 def services_production_urls @_services_production_urls ||= { user: {url: "http://user-microservice", port: 9297}, horizontal: {url: "http://horizontal-microservice", port: 9297}, content: {url: "http://content-microservice", port: 9297}, mocktest: {url: "http://mocktest-microservice", port: 9297}, practice: {url: "http://practice-microservice", port: 9297}, payment: {url: "http://payment-microservice", port: 9297} } end |
#services_staging_urls ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/router_helper.rb', line 35 def services_staging_urls @_services_staging_urls ||= { user: {url: "http://user-microservice", port: 80}, horizontal: {url: "http://horizontal-microservice", port: 80}, content: {url: "http://content-microservice", port: 80}, mocktest: {url: "http://mocktest-microservice", port: 80}, practice: {url: "http://practice-microservice", port: 9297}, payment: {url: "http://payment-microservice", port: 9297} } end |
#services_uri ⇒ Object
57 58 59 |
# File 'lib/router_helper.rb', line 57 def services_uri @_services_uri ||= send("services_#{Rails.env}_urls") end |