Module: RouterHelper

Defined in:
lib/router_helper.rb

Instance Method Summary collapse

Instance Method Details

#generate_third_party_urlObject



63
64
65
66
# File 'lib/router_helper.rb', line 63

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
23
# 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.cookies}
  rescue RestClient::Unauthorized, 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.message }
  end
  data
end

#services_development_urlsObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/router_helper.rb', line 25

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_production_urlsObject



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/router_helper.rb', line 51

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_urlsObject



36
37
38
39
40
41
42
43
44
45
# File 'lib/router_helper.rb', line 36

def services_staging_urls
  @_services_staging_urls ||= {
    user: {url: "http://10.140.10.54", port: 80},
    horizontal: {url: "http://10.140.10.84", port: 80},
    content: {url: "http://10.140.10.66", port: 80},
    mocktest: {url: "http://mocktest-microservice", port: 9297},
    practice: {url: "http://practice-microservice", port: 9297},
    payment: {url: "http://payment-microservice", port: 9297}
  }
end

#services_uriObject



47
48
49
# File 'lib/router_helper.rb', line 47

def services_uri
  @_services_uri ||= send("services_#{Rails.env}_urls")
end