Module: Raas::Client::Rails::RaasControllerModule

Included in:
RaasController
Defined in:
app/controllers/raas/client/rails/raas_controller_module.rb

Constant Summary collapse

MSA_REPORT =
"report"
MSA_DT =
"datatraveler"
MIME_TYPE_HTML =
"html"
MIME_TYPE_FILE =
"file"
MIME_TYPE_JSON =
"json"

Instance Method Summary collapse

Instance Method Details

#datatraveler_sessionObject



39
40
41
42
43
44
# File 'app/controllers/raas/client/rails/raas_controller_module.rb', line 39

def datatraveler_session()
  Rails.logger.warn("session parameter=#{params}")
  prepare(params)
  response = @restClient.createExternalSession(MSA_DT,@backUrl,@subUrl, params[:subDomain])
  render json: response.body
end

#deleteObject

/raas/delete



95
96
97
98
99
100
101
102
103
104
105
106
# File 'app/controllers/raas/client/rails/raas_controller_module.rb', line 95

def delete()
  prepare(params)
  path = params[:path]
  parameters = params[:parameters]
  if parameters.nil?
    payload = nil
  else
    payload = JSON.parse(parameters)
  end      
  Rails.logger.warn("delete path=#{path} parameters=#{parameters}");
  return @restClient.delete(path,payload)
end

#getObject

/raas/get



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/controllers/raas/client/rails/raas_controller_module.rb', line 51

def get()
  prepare(params)
  path = params[:path]
  parameters = params[:parameters]
  mimeType = params[:mimeType]
  fileName = params[:fileName]
  type = params[:type]
  #by default return HTML
  if mimeType.nil?
    mimeType = MIME_TYPE_HTML
  end
  #by default return download.pdf
  if fileName.nil?
    fileName = "download"
  end
  if type.nil?
    type = "application/pdf"
  end
  #by default empty Hash if nothing is assigned
  if parameters.nil?
    payload = Hash.new
  else
    payload = parameters
  end
  Rails.logger.warn("get path=#{path} parameters=#{payload}");
  response = @restClient.get(path,payload)
  handleMime(mimeType, fileName, type, response)
end

#handleMime(mimeType, fileName, type, response) ⇒ Object

How you return the value? This can be changed by passing mimeType through parameter



81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/controllers/raas/client/rails/raas_controller_module.rb', line 81

def handleMime(mimeType, fileName,type, response)
  case mimeType
  when MIME_TYPE_HTML
    #sanitize response automatically
    render html: response.body
  when MIME_TYPE_JSON
    render json: response.body
  when MIME_TYPE_FILE
    send_data(response, filename: fileName, type: type)
  end
  # p "#{fileName} #{type} #{mimeType}"
end

#healthObject

/raas/health



11
12
13
14
# File 'app/controllers/raas/client/rails/raas_controller_module.rb', line 11

def health()
  prepare(params)
  render plain: "Moving #{@tenant}/#{@sub}";
end

#postObject

/raas/post



109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'app/controllers/raas/client/rails/raas_controller_module.rb', line 109

def post()
  prepare(params)
  path = params[:path]
  requestBody = params[:requestbody]
  if requestBody.nil?
    payload = nil
  else
    payload = JSON.parse(requestBody)
  end      
  Rails.logger.warn("post path=#{path} requestBody=#{requestBody}");
  response = @restClient.post(path,payload)
  return response.body;
end

#prepare(params) ⇒ Object



16
17
18
19
20
21
# File 'app/controllers/raas/client/rails/raas_controller_module.rb', line 16

def prepare(params)
  @backUrl = params[:backUrl]
  @subUrl = params[:subUrl]
  prepare_tenant_and_sub()
  @restClient = RestClient.new(@tenant, @sub, @tenant_alias, @sub_alias, @sub_domain)
end

#prepare_tenant_and_subObject



23
24
25
26
27
28
29
30
# File 'app/controllers/raas/client/rails/raas_controller_module.rb', line 23

def prepare_tenant_and_sub()
  # For Overload
  @tenant = params[:tenant]
  @sub = params[:sub]
  @tenant_alias = params[:tenantAlias]
  @sub_alias = params[:subAlias]
  @sub_domain = params[:subDomain]
end

#putObject

/raas/put



124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'app/controllers/raas/client/rails/raas_controller_module.rb', line 124

def put()
  prepare(params)
  path = params[:path]
  requestBody = params[:requestbody]
  if requestBody.nil?
    payload = nil
  else
    payload = JSON.parse(requestBody)
  end      
  Rails.logger.warn("post path=#{path} requestBody=#{requestBody}");
  response = @restClient.put(path,payload)
  return response.body;
end

#report_sessionObject



32
33
34
35
36
37
# File 'app/controllers/raas/client/rails/raas_controller_module.rb', line 32

def report_session()
  Rails.logger.warn("session parameter=#{params}");
  prepare(params)
  response = @restClient.createExternalSession(MSA_REPORT,@backUrl,@subUrl, params[:subDomain])
  render json: response.body
end