Skip to content

Commit b517a03

Browse files
committed
refactored
1 parent f2f4d3a commit b517a03

File tree

2 files changed

+89
-90
lines changed

2 files changed

+89
-90
lines changed

sheets/src/eg_sheets_api.e

Lines changed: 6 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ feature -- Spreedsheets Operations
105105
end
106106
end
107107

108-
append_with_id (a_spreadsheet_id: attached like spreadsheet_id; a_data: detachable ARRAY[ARRAY[STRING]]): detachable like last_response.body
108+
append_with_id_raw (a_spreadsheet_id: attached like spreadsheet_id; a_raw_data: STRING): detachable like last_response.body
109109
note
110110
EIS:"name=append.spreedsheets", "src=https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/append", "protocol=uri"
111111
require
@@ -119,7 +119,7 @@ feature -- Spreedsheets Operations
119119
url_encoder: URL_ENCODER
120120
do
121121
l_range := ""
122-
logger.write_information ("append-> spreadsheed_id:" + a_spreadsheet_id)
122+
logger.write_information ("append_with_id_raw-> spreadsheed_id:" + a_spreadsheet_id)
123123
-- path params
124124
l_path_params_s := a_spreadsheet_id
125125
l_path_params_s.append ("/values/") -- spreadsheets/{spreadsheetId}/values/{range}:append
@@ -140,7 +140,7 @@ feature -- Spreedsheets Operations
140140
-- l_qry_params.extend ("SERIAL_NUMBER", "responseDateTimeRenderOption") -- SERIAL_NUMBER|FORMATTED_STRING https://developers.google.com/sheets/api/reference/rest/v4/DateTimeRenderOption
141141

142142

143-
l_post_data := impl_append_post_data2
143+
l_post_data := a_raw_data
144144

145145
-- Google API append require body parameter instead of upload data.
146146
api_post_call (sheets_url ("spreadsheets/" + l_path_params_s, Void), l_qry_params, l_post_data, Void)
@@ -162,9 +162,9 @@ feature -- Spreedsheets Operations
162162
-- l_file.put_string (l_body)
163163
-- l_file.close
164164
elseif l_response.status = {HTTP_STATUS_CODE}.not_found then
165-
logger.write_error ("get_from_id-> Not found:" + l_response.status.out + " %NBody: " + l_body)
165+
logger.write_error ("append_with_id_raw-> Not found:" + l_response.status.out + " %NBody: " + l_body)
166166
else
167-
logger.write_error ("get_from_id-> Status code invalid:" + l_response.status.out + " %NBody: " + l_body)
167+
logger.write_error ("append_with_id_raw-> Status code invalid:" + l_response.status.out + " %NBody: " + l_body)
168168
end
169169
end
170170
end
@@ -471,7 +471,7 @@ feature {NONE} -- Implementation
471471
data_file: detachable PLAIN_TEXT_FILE
472472

473473

474-
impl_append_post_data: TUPLE[data:PATH; content_type: STRING]
474+
impl_append_post_data_sample_2: TUPLE[data:PATH; content_type: STRING]
475475
require
476476
not attached data_file
477477
local
@@ -510,82 +510,6 @@ feature {NONE} -- Implementation
510510
attached data_file
511511
end
512512

513-
impl_append_post_data2: STRING
514-
local
515-
l_res: JSON_OBJECT
516-
l_jsa_main,
517-
l_jsa_line: JSON_ARRAY
518-
j_array: JSON_ARRAY
519-
520-
--{
521-
-- "range": string,
522-
-- "majorDimension": enum (Dimension),
523-
-- "values": [
524-
-- array
525-
-- ]
526-
--}
527-
--// "values": [
528-
-- // [
529-
-- // "Item",
530-
-- // "Cost"
531-
-- // ],
532-
-- // [
533-
-- // "Wheel",
534-
-- // "$20.50"
535-
-- // ],
536-
-- // [
537-
-- // "Door",
538-
-- // "$15"
539-
-- // ],
540-
-- // [
541-
-- // "Engine",
542-
-- // "$100"
543-
-- // ],
544-
-- // [
545-
-- // "Totals",
546-
-- // "$135.50"
547-
-- // ]
548-
-- // ]
549-
550-
do
551-
create l_res.make_with_capacity (5)
552-
l_res.put_string ("Sheet1!A1:B5", "range")
553-
l_res.put_string ("ROWS", "majorDimension") -- "DIMENSION_UNSPECIFIED", "ROWS", "COLUMNS"
554-
555-
create l_jsa_main.make (10)
556-
557-
create j_array.make (1)
558-
create l_jsa_line.make (2)
559-
l_jsa_line.extend (create {JSON_STRING}.make_from_string ("Item"))
560-
l_jsa_line.extend (create {JSON_STRING}.make_from_string ("Cost"))
561-
j_array.add (l_jsa_line)
562-
563-
create l_jsa_line.make (2)
564-
l_jsa_line.extend (create {JSON_STRING}.make_from_string ("Wheel"))
565-
l_jsa_line.extend (create {JSON_STRING}.make_from_string ("$20.50"))
566-
j_array.add (l_jsa_line)
567-
568-
create l_jsa_line.make (2)
569-
l_jsa_line.extend (create {JSON_STRING}.make_from_string ("Door"))
570-
l_jsa_line.extend (create {JSON_STRING}.make_from_string ("$15"))
571-
j_array.add (l_jsa_line)
572-
573-
create l_jsa_line.make (2)
574-
l_jsa_line.extend (create {JSON_STRING}.make_from_string ("Engine"))
575-
l_jsa_line.extend (create {JSON_STRING}.make_from_string ("$100"))
576-
j_array.add (l_jsa_line)
577-
578-
create l_jsa_line.make (2)
579-
l_jsa_line.extend (create {JSON_STRING}.make_from_string ("Totals"))
580-
l_jsa_line.extend (create {JSON_STRING}.make_from_string ("$135.50"))
581-
j_array.add (l_jsa_line)
582-
583-
584-
l_res.put (j_array, "values")
585-
586-
Result := l_res.representation
587-
logger.write_debug ("impl_append_body-> Result: '" + Result.out + "'")
588-
end
589513

590514
end
591515

sheets/test/test_sheets_api.e

Lines changed: 83 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ feature -- {NONE}
2323
retrieve_access_token
2424
-- test_create_sheet
2525
-- test_get_sheet ("1v1N4nRa6mmLcP9rUuyQPiCnLuUcBQFDEC7E0CDg3ASI")
26-
test_append_sheet ("19cKCmQBWJoMePX0Iy6LueHRw0sS2bMcyP1Auzbkvj6M") --pg
26+
test_append_sheet ("19cKCmQBWJoMePX0Iy6LueHRw0sS2bMcyP1Auzbkvj6M", impl_append_post_data_sample) --pg
2727
--test_append_sheet ("1j5CTkpgOc6Y5qgYdA_klZYjNhmN2KYocoZAdM4Y61tw") --jv
2828

2929
-- set_from_json_credentials_file_path (create {PATH}.make_from_string (CREDENTIALS_PATH))
@@ -106,17 +106,12 @@ feature -- Tests
106106
end
107107
end
108108

109-
test_append_sheet (an_id: attached like {EG_SHEETS_API}.spreadsheet_id)
109+
test_append_sheet (an_id: attached like {EG_SHEETS_API}.spreadsheet_id; a_data: STRING)
110110
local
111111
l_esapi: EG_SHEETS_API
112-
l_data: ARRAY[ARRAY[STRING]]
113112
do
114-
l_data := <<
115-
<<"test1", "test2">>,
116-
<<"test3", "test4">>
117-
>>
118113
create l_esapi.make (last_token.token)
119-
if attached l_esapi.append_with_id (an_id, l_data) as l_spreedsheet_get_result then
114+
if attached l_esapi.append_with_id_raw (an_id, a_data) as l_spreedsheet_get_result then
120115
if l_esapi.has_error then
121116
-- debug ("test_create_sheet")
122117
print ("test_append_sheet-> Error %N" )
@@ -156,4 +151,84 @@ feature {NONE} -- Implementations
156151

157152
CREDENTIALS_PATH: STRING="credentials.json" -- get this file from https://console.developers.google.com/
158153
-- Credentials path to json file.
154+
155+
156+
157+
impl_append_post_data_sample: STRING
158+
local
159+
l_res: JSON_OBJECT
160+
l_jsa_main,
161+
l_jsa_line: JSON_ARRAY
162+
j_array: JSON_ARRAY
163+
164+
--{
165+
-- "range": string,
166+
-- "majorDimension": enum (Dimension),
167+
-- "values": [
168+
-- array
169+
-- ]
170+
--}
171+
--// "values": [
172+
-- // [
173+
-- // "Item",
174+
-- // "Cost"
175+
-- // ],
176+
-- // [
177+
-- // "Wheel",
178+
-- // "$20.50"
179+
-- // ],
180+
-- // [
181+
-- // "Door",
182+
-- // "$15"
183+
-- // ],
184+
-- // [
185+
-- // "Engine",
186+
-- // "$100"
187+
-- // ],
188+
-- // [
189+
-- // "Totals",
190+
-- // "$135.50"
191+
-- // ]
192+
-- // ]
193+
194+
do
195+
create l_res.make_with_capacity (5)
196+
l_res.put_string ("Sheet1!A1:B5", "range")
197+
l_res.put_string ("ROWS", "majorDimension") -- "DIMENSION_UNSPECIFIED", "ROWS", "COLUMNS"
198+
199+
create l_jsa_main.make (10)
200+
201+
create j_array.make (1)
202+
create l_jsa_line.make (2)
203+
l_jsa_line.extend (create {JSON_STRING}.make_from_string ("Item"))
204+
l_jsa_line.extend (create {JSON_STRING}.make_from_string ("Cost"))
205+
j_array.add (l_jsa_line)
206+
207+
create l_jsa_line.make (2)
208+
l_jsa_line.extend (create {JSON_STRING}.make_from_string ("Wheel"))
209+
l_jsa_line.extend (create {JSON_STRING}.make_from_string ("$20.50"))
210+
j_array.add (l_jsa_line)
211+
212+
create l_jsa_line.make (2)
213+
l_jsa_line.extend (create {JSON_STRING}.make_from_string ("Door"))
214+
l_jsa_line.extend (create {JSON_STRING}.make_from_string ("$15"))
215+
j_array.add (l_jsa_line)
216+
217+
create l_jsa_line.make (2)
218+
l_jsa_line.extend (create {JSON_STRING}.make_from_string ("Engine"))
219+
l_jsa_line.extend (create {JSON_STRING}.make_from_string ("$100"))
220+
j_array.add (l_jsa_line)
221+
222+
create l_jsa_line.make (2)
223+
l_jsa_line.extend (create {JSON_STRING}.make_from_string ("Totals"))
224+
l_jsa_line.extend (create {JSON_STRING}.make_from_string ("$135.50"))
225+
j_array.add (l_jsa_line)
226+
227+
228+
l_res.put (j_array, "values")
229+
230+
Result := l_res.representation
231+
logger.write_debug ("impl_append_body-> Result: '" + Result.out + "'")
232+
end
233+
159234
end

0 commit comments

Comments
 (0)