@@ -31,7 +31,7 @@ export class OneNoteApiBase {
31
31
this . queryParams = queryParams ;
32
32
}
33
33
34
- protected requestPromise ( url : string , data ?: XHRData , contentType ?: string , httpMethod ?: string , isFullUrl ?: boolean , urlContainsVersion ?: boolean ) : Promise < ResponsePackage < any > > {
34
+ protected requestPromise ( url : string , data ?: XHRData , contentType ?: string , httpMethod ?: string , isFullUrl ?: boolean , urlContainsVersion ?: boolean , extraQueryParams ?: { [ key : string ] : string } ) : Promise < ResponsePackage < any > > {
35
35
let fullUrl ;
36
36
if ( isFullUrl ) {
37
37
fullUrl = url ;
@@ -40,7 +40,7 @@ export class OneNoteApiBase {
40
40
}
41
41
42
42
// Append specified query params
43
- fullUrl = this . appendQueryParams ( fullUrl ) ;
43
+ fullUrl = this . appendQueryParams ( fullUrl , extraQueryParams ) ;
44
44
45
45
if ( ! contentType ) {
46
46
contentType = "application/json" ;
@@ -55,19 +55,32 @@ export class OneNoteApiBase {
55
55
} ) ) ;
56
56
}
57
57
58
- private appendQueryParams ( url : string ) : string {
59
- let queryParams = this . queryParams ;
60
- if ( ! queryParams ) {
58
+ private appendQueryParams ( url : string , extraQueryParams ?: { [ key : string ] : string } ) : string {
59
+ // Merge both constructor query params and parameter query params
60
+ const newQueryParams = { } ;
61
+ if ( this . queryParams ) {
62
+ for ( const key in this . queryParams ) {
63
+ newQueryParams [ key ] = this . queryParams [ key ] ;
64
+ }
65
+ }
66
+ if ( extraQueryParams ) {
67
+ for ( const key in extraQueryParams ) {
68
+ newQueryParams [ key ] = extraQueryParams [ key ] ;
69
+ }
70
+ }
71
+
72
+ if ( ! newQueryParams || Object . keys ( newQueryParams ) . length === 0 ) {
61
73
return url ;
62
74
}
63
75
64
76
let queryParamArray = [ ] ;
65
- for ( const key in queryParams ) {
66
- if ( queryParams . hasOwnProperty ( key ) ) {
67
- const queryParamValue = encodeURIComponent ( queryParams [ key ] ) ;
77
+ for ( const key in newQueryParams ) {
78
+ if ( newQueryParams . hasOwnProperty ( key ) ) {
79
+ const queryParamValue = encodeURIComponent ( newQueryParams [ key ] ) ;
68
80
queryParamArray . push ( key + "=" + queryParamValue ) ;
69
81
}
70
82
}
83
+
71
84
const serializedQueryParams = queryParamArray . join ( "&" ) ;
72
85
if ( url . indexOf ( "?" ) === - 1 ) {
73
86
return url + "?" + serializedQueryParams ;
0 commit comments