/[eiffelstudio]/trunk/Src/web/eiffel-cloud/modules/es_cloud/webapi/es_cloud_webapi_handler.e
ViewVC logotype

Contents of /trunk/Src/web/eiffel-cloud/modules/es_cloud/webapi/es_cloud_webapi_handler.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 103675 - (show annotations)
Tue Nov 12 12:35:53 2019 UTC (2 months, 1 week ago) by jfiat
File size: 3714 byte(s)
Added webapi to access the plans.
1 note
2 description: "Summary description for {ES_CLOUD_WEBAPI_HANDLER}."
3 date: "$Date$"
4 revision: "$Revision$"
5
6 deferred class
7 ES_CLOUD_WEBAPI_HANDLER
8
9 inherit
10 CMS_WEBAPI_HANDLER
11 rename
12 make as make_with_cms_api
13 end
14
15 WSF_URI_TEMPLATE_HANDLER
16 rename
17 execute as handler_execute
18 end
19
20 feature {NONE} -- Initialization
21
22 make (a_mod_api: ES_CLOUD_API)
23 do
24 make_with_cms_api (a_mod_api.cms_api)
25 es_cloud_api := a_mod_api
26 end
27
28 feature -- API
29
30 es_cloud_api: ES_CLOUD_API
31
32 feature -- Execution
33
34 handler_execute (req: WSF_REQUEST; res: WSF_RESPONSE)
35 -- Execute handler for `req' and respond in `res'.
36 do
37 if attached {WSF_STRING} req.path_parameter ("version") as p_version then
38 execute (p_version.value, req, res)
39 else
40 report_version_missing_error (req, res)
41 end
42 end
43
44 report_version_missing_error (req: WSF_REQUEST; res: WSF_RESPONSE)
45 do
46 new_bad_request_error_response ("Missing {version} parameter", req, res).execute
47 end
48
49 execute (a_version: READABLE_STRING_GENERAL; req: WSF_REQUEST; res: WSF_RESPONSE)
50 deferred
51 end
52
53 feature -- Helper
54
55 user_by_uid (a_uid: READABLE_STRING_GENERAL): detachable CMS_USER
56 do
57 Result := api.user_api.user_by_id_or_name (a_uid)
58 end
59
60 add_cloud_user_links_to (a_version: READABLE_STRING_GENERAL; u: ES_CLOUD_USER; rep: HM_WEBAPI_RESPONSE)
61 do
62 rep.add_link ("cloud_account", "user/" + u.id.out, cloud_user_link (a_version, u))
63 end
64
65 cloud_link (a_version: READABLE_STRING_GENERAL): STRING
66 do
67 Result := api.webapi_path ("/cloud/" + url_encoded (a_version) + "/")
68 end
69
70 cloud_plans_link (a_version: READABLE_STRING_GENERAL): STRING
71 do
72 Result := cloud_link (a_version) + "plan/"
73 end
74
75 cloud_plan_link (a_version: READABLE_STRING_GENERAL; pid: INTEGER): STRING
76 do
77 Result := cloud_plans_link (a_version) + pid.out
78 end
79
80 cloud_user_link (a_version: READABLE_STRING_GENERAL; a_user: ES_CLOUD_USER): STRING
81 do
82 Result := cloud_link (a_version) + "account/" + a_user.id.out
83 end
84
85 cloud_user_installations_link (a_version: READABLE_STRING_GENERAL; a_user: ES_CLOUD_USER): STRING
86 do
87 Result := cloud_user_link (a_version, a_user) + "/installations"
88 end
89
90 cloud_user_installation_link (a_version: READABLE_STRING_GENERAL; a_user: ES_CLOUD_USER; iid: READABLE_STRING_GENERAL): STRING
91 do
92 Result := cloud_user_installations_link (a_version, a_user) + "/" + url_encoded (iid)
93 end
94
95 cloud_user_installation_sessions_link (a_version: READABLE_STRING_GENERAL; a_user: ES_CLOUD_USER; iid: READABLE_STRING_GENERAL): STRING
96 do
97 Result := cloud_user_installation_link (a_version, a_user, iid) + "/session/"
98 end
99
100 cloud_user_installation_session_link (a_version: READABLE_STRING_GENERAL; a_user: ES_CLOUD_USER; iid, sid: READABLE_STRING_GENERAL): STRING
101 do
102 Result := cloud_user_installation_sessions_link (a_version, a_user, iid) + url_encoded (sid)
103 end
104
105 feature {NONE} -- Implementation
106
107 remove_last_segment (a_location: STRING_8; a_keep_ending_slash: BOOLEAN)
108 local
109 i: INTEGER
110 do
111 if a_location.ends_with_general ("/") then
112 i := a_location.count - 1
113 else
114 i := a_location.count
115 end
116 i := a_location.last_index_of ('/', i)
117 if i > 0 then
118 if a_keep_ending_slash then
119 a_location.keep_head (i)
120 else
121 a_location.keep_head (i - 1)
122 end
123 end
124 end
125
126 detachable_html_encoded (s: detachable READABLE_STRING_GENERAL): detachable STRING_8
127 -- html encoded version of `s` if set, otherwise Void.
128 do
129 if s /= Void then
130 Result := api.html_encoded (s)
131 end
132 end
133
134 note
135 copyright: "2011-2017, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
136 license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
137 end

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.23