@@ -64,7 +64,48 @@ feature -- Spreedsheets Operations
6464 end
6565 end
6666
67- get_from_id (a_spreadsheet_id : attached like spreadsheet_id ): detachable like last_response .body
67+ get_from_id (a_spreadsheet_id : attached like spreadsheet_id ; a_params : detachable EG_SPREADSHEET_PARAMETERS ): detachable like last_response .body
68+ -- POST /spreadsheets/`a_spreadsheet_id'
69+ note
70+ EIS :" name=get.spreedsheets" , " src=https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/get" , " protocol=uri"
71+ require
72+ not a_spreadsheet_id .is_empty
73+ local
74+ l_file : PLAIN_TEXT_FILE
75+ l_qry_params : STRING_TABLE [STRING ]
76+ do
77+
78+ logger .write_information (" get_from_id-> Now getting sheet from id:" + a_spreadsheet_id )
79+
80+ api_get_call (sheets_url (" spreadsheets/" + a_spreadsheet_id , Void ), a_params )
81+ check
82+ attached last_response as l_response and then
83+ attached l_response .body as l_body
84+ then
85+ parse_last_response
86+ if l_response .status = {HTTP_STATUS_CODE }.ok then
87+ Result := l_body
88+
89+ debug
90+ create l_file .make_create_read_write (" /tmp/hitme_sheet_json-get_from_id.json" )
91+ logger .write_information (" get_from_id->Writing body into " + l_file .path .utf_ 8 _name )
92+ l_file .close
93+ l_file .wipe_out
94+ l_file .open_append
95+
96+ l_file .put_string (l_body )
97+ l_file .close
98+ end
99+ elseif l_response .status = {HTTP_STATUS_CODE }.not_found then
100+ logger .write_error (" get_from_id-> Not found:" + l_response .status .out + " %NBody: " + l_body )
101+ else
102+ logger .write_error (" get_from_id-> Status code invalid:" + l_response .status .out + " %NBody: " + l_body )
103+ end
104+ end
105+ end
106+
107+
108+ get_from_id 2 (a_spreadsheet_id : attached like spreadsheet_id ): detachable like last_response .body
68109 -- POST /spreadsheets/`a_spreadsheet_id'
69110 note
70111 EIS :" name=get.spreedsheets" , " src=https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/get" , " protocol=uri"
@@ -305,6 +346,7 @@ feature {NONE} -- Implementation
305346 logger .write_debug (" internal_api_call-> a_api_url:" + a_api_url + " method:" + a_method )
306347 -- TODO improve this, so we can check the required scopes before we
307348 -- do an api call.
349+ -- TODO add a class with the valid scopes.
308350 create config .make_default (" " , " " )
309351 config .set_scope (" https://www.googleapis.com/auth/spreadsheets" )
310352
@@ -313,8 +355,8 @@ feature {NONE} -- Implementation
313355 create api_service .make (create {OAUTH_ 20 _GOOGLE_API }, config )
314356 -- | TODO improve cypress service creation procedure to make configuration optional.
315357
316- print (" %N===Google OAuth Workflow using OAuth access token for the owner of the application ===%N" )
317358 -- | TODO rewrite prints as logs
359+ logger .write_debug (" %N===Google OAuth Workflow using OAuth access token for the owner of the application ===%N" )
318360
319361 -- Create the access token that will identifies the user making the request.
320362 create l_access_token .make_token_secret (access_token , " NOT_NEEDED" )
@@ -337,14 +379,14 @@ feature {NONE} -- Implementation
337379 request .add_header (" Content-Type" , " application/json; charset=UTF-8" )
338380 request .add_payload (a_payload )
339381 else
340- request .add_header (" Content-length" , " " )
382+ request .add_header (" Content-length" , " 0 " )
341383 end
342384
343385 api_service .sign_request (ll_access_token , request )
344386
345387 logger .write_debug (" internal_api_call->uri:'" + request .uri + " '" )
346388 if attached request .upload_file as l_s then
347- logger .write_debug (" internal_api_call->upload file:'" + l_s + " '" )
389+ logger .write_debug (" internal_api_call->upload file:'" + l_s . out + " '" )
348390 end
349391 if attached {OAUTH_RESPONSE } request .execute as l_response then
350392 last_response := l_response
@@ -454,7 +496,7 @@ feature {NONE} -- Implementation
454496 create l_raw_file .make_open_read (l_upload_data .file_name .absolute_path .name )
455497 if l_raw_file .exists then
456498 logger .write_debug (" upload_data-> Content-type: '" + l_upload_data .content_type + " '" )
457- logger .write_debug (" upload_data-> upload file name: '" + l_upload_data .file_name .absolute_path .name + " '" )
499+ logger .write_debug (" upload_data-> upload file name: '" + l_upload_data .file_name .absolute_path .name . out + " '" )
458500 request .add_header (" Content-Type" , l_upload_data .content_type )
459501 request .set_upload_filename (l_upload_data .file_name .absolute_path .name )
460502 request .add_form_parameter (" source" , l_upload_data .file_name .name .as_string_ 32 )
0 commit comments