Skip to content

Commit 25a1891

Browse files
committedApr 9, 2014
Merge pull request #4 from jvelilla/master
CJ Browser update Add delete support. Add missing Accept header. Setup a bigger timeout.
2 parents 91b44cf + e288d17 commit 25a1891

File tree

3 files changed

+87
-3
lines changed

3 files changed

+87
-3
lines changed
 

‎src/cj_client_proxy.e

+6
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,10 @@ feature -- Execution
5959
Result := client.update_with_template (a_path, tpl, adapted_context (ctx))
6060
end
6161

62+
63+
delete (a_path: READABLE_STRING_GENERAL; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT): CJ_CLIENT_RESPONSE
64+
do
65+
Result := client.delete (a_path, adapted_context (ctx))
66+
end
67+
6268
end

‎src/cj_template_tool.e

+40-3
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ feature -- Change
4343
v: EV_VERTICAL_BOX
4444
hb: EV_HORIZONTAL_BOX
4545
lab: EV_LABEL
46-
tf: EV_TEXT_FIELD
46+
-- tf: EV_TEXT_FIELD
47+
tf: EV_TEXT
4748
tf_passwd: EV_PASSWORD_FIELD
4849
but: EV_BUTTON
49-
table: HASH_TABLE [EV_TEXT_FIELD, STRING_32]
50+
but_delete: detachable EV_BUTTON
51+
table: HASH_TABLE [EV_TEXT_COMPONENT, STRING_32]
5052
is_creation: BOOLEAN
5153
is_password: BOOLEAN
5254
do
@@ -110,15 +112,23 @@ feature -- Change
110112
else
111113
create but.make_with_text ("Update")
112114
but.select_actions.extend (agent on_post (coll, tpl, table, False))
115+
create but_delete.make_with_text ("Delete")
116+
but_delete.select_actions.extend (agent on_delete (coll, tpl, table))
117+
113118
end
114119

115120
v.extend (create {EV_CELL})
116121
v.extend (but)
122+
if but_delete /= Void then
123+
v.extend (but_delete)
124+
v.disable_item_expand (but_delete)
125+
126+
end
117127
v.disable_item_expand (but)
118128
-- FIXME
119129
end
120130

121-
on_post (coll: CJ_COLLECTION; tpl: CJ_TEMPLATE; table: HASH_TABLE [EV_TEXT_FIELD, STRING_32]; is_creation: BOOLEAN)
131+
on_post (coll: CJ_COLLECTION; tpl: CJ_TEMPLATE; table: HASH_TABLE [EV_TEXT_COMPONENT, STRING_32]; is_creation: BOOLEAN)
122132
local
123133
ctx: HTTP_CLIENT_REQUEST_CONTEXT
124134
l_href: STRING_8
@@ -147,6 +157,33 @@ feature -- Change
147157
-- dlg.focus_out_actions.extend (agent dlg.destroy_and_exit_if_last)
148158
end
149159

160+
on_delete (coll: CJ_COLLECTION; tpl: CJ_TEMPLATE; table: HASH_TABLE [EV_TEXT_COMPONENT, STRING_32])
161+
local
162+
ctx: HTTP_CLIENT_REQUEST_CONTEXT
163+
l_href: STRING_8
164+
dlg: EV_INFORMATION_DIALOG
165+
resp: CJ_CLIENT_RESPONSE
166+
do
167+
create ctx.make
168+
across
169+
tpl.data as c
170+
loop
171+
if attached table.item (c.item.name) as tf then
172+
c.item.set_value (tf.text)
173+
end
174+
end
175+
if attached coll.items as l_items and then attached l_items.first as first_item then
176+
l_href := first_item.href
177+
resp := cj_client.delete(l_href, Void )
178+
else
179+
l_href := coll.href
180+
resp := cj_client.delete (l_href, Void)
181+
end
182+
create dlg.make_with_text ("Result")
183+
dlg.set_text (resp.http_response)
184+
dlg.show
185+
end
186+
150187
invariant
151188
widget_attached: widget /= Void
152189

‎src/kernel/cj_client.e

+41
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ feature {NONE} -- Initialization
1616
-- Initialize `Current'.
1717
do
1818
create {LIBCURL_HTTP_CLIENT_SESSION} client.make (a_service) --"http://jfiat.dyndns.org:8190")
19+
client.set_timeout (25)
1920
end
2021

2122
feature -- Access
@@ -71,6 +72,7 @@ feature -- Access
7172
if l_ctx = Void then
7273
create l_ctx.make
7374
end
75+
l_ctx.add_header ("Accept", "application/vnd.collection+json")
7476
l_ctx.add_header ("Content-Type", "application/vnd.collection+json")
7577

7678
if attached cj_template_to_json (tpl) as j then
@@ -112,6 +114,8 @@ feature -- Access
112114
create l_ctx.make
113115
end
114116
l_ctx.add_header ("Content-Type", "application/vnd.collection+json")
117+
l_ctx.add_header ("Accept", "application/vnd.collection+json")
118+
115119

116120
if attached cj_template_to_json (tpl) as j then
117121
d := "{ %"template%": " + j.representation + " }"
@@ -151,6 +155,8 @@ feature -- Access
151155
create l_ctx.make
152156
end
153157
l_ctx.add_header ("Content-Type", "application/vnd.collection+json")
158+
l_ctx.add_header ("Accept", "application/vnd.collection+json")
159+
154160

155161
if attached q.data as q_data then
156162
across
@@ -185,6 +191,41 @@ feature -- Access
185191
end
186192

187193

194+
delete (a_path: READABLE_STRING_GENERAL; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT): CJ_CLIENT_RESPONSE
195+
local
196+
l_http_response: STRING_8
197+
j_body: like json
198+
l_formatted_body: detachable STRING_8
199+
col: detachable CJ_COLLECTION
200+
l_ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT
201+
l_url: STRING_8
202+
do
203+
create l_http_response.make_empty
204+
l_ctx := ctx
205+
if l_ctx = Void then
206+
create l_ctx.make
207+
end
208+
l_ctx.add_header ("Accept", "application/vnd.collection+json")
209+
l_url := a_path.to_string_8
210+
if attached client.delete (l_url, l_ctx) as g_response then
211+
l_url := g_response.url
212+
l_http_response.append ("Status: " + g_response.status.out + "%N")
213+
l_http_response.append (g_response.raw_header)
214+
if attached g_response.body as l_body then
215+
l_http_response.append ("%N%N")
216+
l_http_response.append (l_body)
217+
if attached json (l_body) as j then
218+
j_body := j
219+
col := cj_collection (j)
220+
end
221+
else
222+
l_formatted_body := Void
223+
end
224+
end
225+
create Result.make (l_url, l_http_response, j_body, col)
226+
end
227+
228+
188229
feature {NONE} -- Implementation
189230

190231
shared_ejson: SHARED_EJSON

0 commit comments

Comments
 (0)
Please sign in to comment.