Skip to content

Commit f730d77

Browse files
author
Vsevolod
committed
Revert "added feature to select range to function get_rows; added function get_all_rows; added test for new feature"
This reverts commit b402b67.
1 parent 20707b0 commit f730d77

File tree

3 files changed

+14
-168
lines changed

3 files changed

+14
-168
lines changed

module/move/gspread/src/actions/gspread.rs

Lines changed: 5 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ mod private
1010
use serde_json::json;
1111
use once_cell::sync::Lazy;
1212
use std::collections::HashMap;
13-
use std::usize;
1413

1514
use crate::gcore::client::InsertDataOption;
1615
use crate::*;
@@ -764,7 +763,7 @@ use std::usize;
764763
}
765764
}
766765

767-
/// # `get_all_rows`
766+
/// # `get_rows`
768767
///
769768
/// Retrieves all rows (excluding the header) from a specific sheet.
770769
///
@@ -783,70 +782,14 @@ use std::usize;
783782
/// - `Error::ApiError`:
784783
/// Occurs if the Google Sheets API returns an error, such as an invalid spreadsheet ID
785784
/// or insufficient permissions.
786-
pub async fn get_all_rows< S : Secret >
787-
(
788-
client : &Client< '_, S >,
789-
spreadsheet_id : &str,
790-
sheet_name : &str,
791-
) -> Result< Vec< Vec< serde_json::Value > > >
792-
{
793-
get_rows( client, spreadsheet_id, sheet_name, RowRange::All ).await
794-
}
795-
796-
/// # `RowRange`
797-
///
798-
/// Enum sprecifies range of rows to retrieve from a sheet.
799-
///
800-
/// ## `Variants`:
801-
/// - `All`:
802-
/// All rows but not header.
803-
/// - `Range`:
804-
/// Specified range of rows.
805-
pub enum RowRange
806-
{
807-
/// All rows but header (the first row in a sheet)
808-
All,
809-
/// The first and the last rows to retrieve. It will include header in response only in case you set `row_start` = 0.
810-
Range
811-
{
812-
row_start : usize,
813-
row_end : usize
814-
}
815-
}
816-
817-
/// # `get_rows`
818-
///
819-
/// Retrieves specified range of rows from a sheet.
820-
///
821-
/// ## Parameters:
822-
/// - `client`:
823-
/// A reference to the `Client` client configured for the Google Sheets API.
824-
/// - `spreadsheet_id`:
825-
/// A `&str` representing the unique identifier of the spreadsheet.
826-
/// - `sheet_name`:
827-
/// A `&str` specifying the name of the sheet whose rows are to be retrieved.
828-
/// - `range`:
829-
/// A `RowRange` variant.
830-
/// ## Returns:
831-
/// - `Result< Vec< Vec< serde_json::Value > > >`
832-
///
833-
/// ## Errors:
834-
/// - `Error::ApiError`:
835-
/// Occurs if the Google Sheets API returns an error, such as an invalid spreadsheet ID
836-
/// or insufficient permissions.
837785
pub async fn get_rows< S : Secret >
838786
(
839787
client : &Client< '_, S >,
840788
spreadsheet_id : &str,
841789
sheet_name : &str,
842-
range : RowRange
843-
)-> Result< Vec< Vec< serde_json::Value > > >
790+
) -> Result< Vec< Vec< serde_json::Value > > >
844791
{
845-
let range = match range
846-
{
847-
RowRange::All => format!( "{}!A2:ZZZ", sheet_name ),
848-
RowRange::Range { row_start, row_end } => format!( "{}!A{}:ZZZ{}", sheet_name, row_start + 1, row_end + 1 )
849-
};
792+
let range = format!( "{}!A2:ZZZ", sheet_name );
850793

851794
match client
852795
.spreadsheet()
@@ -865,40 +808,8 @@ use std::usize;
865808
}
866809
Err( error ) => Err( error )
867810
}
868-
}
869-
870-
// pub async fn get_rows_2< S : Secret >
871-
// (
872-
// client : &Client< '_, S >,
873-
// spreadsheet_id : &str,
874-
// sheet_name : &str,
875-
// ) -> Result< Vec< Vec< serde_json::Value > > >
876-
// {
877-
// // let range = format!( "{}!A2:ZZZ", sheet_name );
878-
// let mut rows = Vec::new();
879-
// let batch_size = 10000;
880-
// for start in 1..180000 {
881-
882-
// }
883-
// match client
884-
// .spreadsheet()
885-
// .values_get( spreadsheet_id, &range )
886-
// .value_render_option( ValueRenderOption::UnformattedValue )
887-
// .doit()
888-
// .await
889-
// {
890-
// Ok( response ) =>
891-
// {
892-
// match response.values
893-
// {
894-
// Some( values ) => Ok( values ),
895-
// None => Ok( Vec::new() )
896-
// }
897-
// }
898-
// Err( error ) => Err( error )
899-
// }
900811

901-
// }
812+
}
902813

903814
/// # `get_cell`
904815
///
@@ -1185,7 +1096,6 @@ crate::mod_interface!
11851096
get_cell,
11861097
get_row,
11871098
get_rows,
1188-
get_all_rows,
11891099
update_row,
11901100
get_header,
11911101
append_row,
@@ -1194,7 +1104,6 @@ crate::mod_interface!
11941104
get_column,
11951105
clear,
11961106
clear_by_custom_row_key,
1197-
copy_to,
1198-
RowRange
1107+
copy_to
11991108
};
12001109
}

module/move/gspread/src/actions/gspread_rows_get.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
mod private
99
{
1010
use crate::*;
11-
use actions::gspread::get_all_rows;
11+
use actions::gspread::get_rows;
1212
use gcore::Secret;
1313
use gcore::error::Result;
1414
use gcore::client::Client;
@@ -20,12 +20,9 @@ mod private
2020
sheet_name : &str
2121
) -> Result< Vec< Vec < serde_json::Value > > >
2222
{
23-
match get_all_rows( client, spreadsheet_id, sheet_name ).await
23+
match get_rows( client, spreadsheet_id, sheet_name ).await
2424
{
25-
Ok( rows ) => {
26-
println!("Got {} rows", rows.len());
27-
Ok( rows )
28-
},
25+
Ok( rows ) => Ok( rows ),
2926
Err( error ) => Err( error )
3027
}
3128
}

module/move/gspread/tests/mock/get_rows.rs

Lines changed: 6 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -6,74 +6,14 @@ use gspread::gcore::ApplicationSecret;
66
use httpmock::prelude::*;
77

88
use serde_json::json;
9-
use gspread::actions::gspread::{get_all_rows, get_rows, RowRange};
9+
use gspread::actions::gspread::get_rows;
1010
use gspread::gcore::client::
1111
{
1212
Client,
1313
Dimension,
1414
ValueRange
1515
};
1616

17-
/// # What
18-
/// We check retrieving a range of rows from a sheet
19-
///
20-
/// # How
21-
/// 1. Start a mock server
22-
/// 2. Create a client
23-
/// 3. Call `get_rows` function with specified range
24-
/// 4. Check results
25-
#[ tokio::test ]
26-
async fn test_mock_get_rows_with_range_should_work()
27-
{
28-
let spreadsheet_id = "12345";
29-
let body = ValueRange
30-
{
31-
major_dimension : Some( Dimension::Row ),
32-
range : Some( "tab2!A5:ZZZ7".to_string() ),
33-
values : Some
34-
(
35-
vec!
36-
[
37-
vec![ json!( "Row5Col1" ), json!( "Row5Col2" ) ],
38-
vec![ json!( "Row7Col1" ), json!( "Row7Col2" ) ]
39-
]
40-
)
41-
};
42-
43-
// 1. Start a mock server.
44-
let server = MockServer::start();
45-
let mock = server.mock( | when, then | {
46-
when.method( GET )
47-
.path( "/12345/values/tab2!A5:ZZZ7" );
48-
then.status( 200 )
49-
.header( "Content-Type", "application/json" )
50-
.json_body_obj( &body );
51-
} );
52-
53-
// 2. Create a client.
54-
let endpoint = server.url( "" );
55-
let client : Client< '_, ApplicationSecret > = Client::former()
56-
.endpoint( &*endpoint )
57-
.form();
58-
59-
// 3. Call `get_rows`
60-
let rows = get_rows( &client, spreadsheet_id, "tab2", RowRange::Range { row_start: 4, row_end: 6 } )
61-
.await
62-
.expect( "get_rows failed" );
63-
64-
// 4. Check results.
65-
mock.assert();
66-
67-
assert_eq!( rows.len(), 2 );
68-
assert_eq!( rows[ 0 ].len(), 2 );
69-
assert_eq!( rows[ 0 ][ 0 ], json!( "Row5Col1" ) );
70-
assert_eq!( rows[ 0 ][ 1 ], json!( "Row5Col2" ) );
71-
72-
assert_eq!( rows[ 1 ].len(), 2 );
73-
assert_eq!( rows[ 1 ][ 0 ], json!( "Row7Col1" ) );
74-
assert_eq!( rows[ 1 ][ 1 ], json!( "Row7Col2" ) );
75-
}
76-
7717
/// # What
7818
/// We check that requesting all rows from the second row onward (below the header)
7919
/// correctly parses the response and returns the expected result.
@@ -86,7 +26,7 @@ async fn test_mock_get_rows_with_range_should_work()
8626
/// # How
8727
/// 1. Start a mock server.
8828
/// 2. Create a client.
89-
/// 3. Call `get_all_rows` which sends a GET request to "/{spreadsheet_id}/values/{range}".
29+
/// 3. Call `get_rows` which sends a GET request to "/{spreadsheet_id}/values/{range}".
9030
/// 4. Check results.
9131
#[ tokio::test ]
9232
async fn test_mock_get_rows_should_work()
@@ -123,7 +63,7 @@ async fn test_mock_get_rows_should_work()
12363
.form();
12464

12565
// 3. Call `get_rows`
126-
let rows = get_all_rows( &client, spreadsheet_id, "tab2" )
66+
let rows = get_rows( &client, spreadsheet_id, "tab2" )
12767
.await
12868
.expect( "get_rows failed" );
12969

@@ -175,7 +115,7 @@ async fn test_mock_get_rows_with_empty_columns()
175115
.form();
176116

177117
// 3. Call `get_rows`
178-
let rows = get_all_rows( &client, spreadsheet_id, "tab2" )
118+
let rows = get_rows( &client, spreadsheet_id, "tab2" )
179119
.await
180120
.expect( "get_rows failed" );
181121

@@ -230,7 +170,7 @@ async fn test_mock_get_rows_with_empty_row_in_the_middle()
230170
.form();
231171

232172
// 3. Call `get_rows`
233-
let rows = get_all_rows( &client, spreadsheet_id, "tab2" )
173+
let rows = get_rows( &client, spreadsheet_id, "tab2" )
234174
.await
235175
.expect( "get_rows failed" );
236176

@@ -281,7 +221,7 @@ async fn test_mock_get_rows_empty_should_work()
281221
.endpoint( &*endpoint )
282222
.form();
283223

284-
let rows = get_all_rows( &client, spreadsheet_id, "tab2" )
224+
let rows = get_rows( &client, spreadsheet_id, "tab2" )
285225
.await
286226
.expect( "get_rows failed" );
287227

0 commit comments

Comments
 (0)