Skip to content

Commit 4b8df22

Browse files
:potted_pot: globalField Support Added
1 parent c3e43aa commit 4b8df22

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

.dccache

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

.vscode/launch.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "contentstack-dart",
9+
"request": "launch",
10+
"type": "dart"
11+
}
12+
]
13+
}

lib/src/stack.dart

+41
Original file line numberDiff line numberDiff line change
@@ -446,4 +446,45 @@ class Stack {
446446
}
447447
}
448448
}
449+
450+
///
451+
///
452+
/// [All Global Fields]
453+
///
454+
/// * [Get all global fields]
455+
/// This call returns comprehensive information of all the global fields
456+
/// savailable in a particular stack in your account.
457+
///
458+
/// ```
459+
/// var response = stack.globalField();
460+
/// ```
461+
462+
/// * [Single Global Field]
463+
/// Get a single global field
464+
///
465+
/// This request allows you to fetch comprehensive details of a specific
466+
/// global field.When executing the API call, in the 'URI Parameters' section,
467+
/// provide the unique ID of your global field.
468+
/// ```
469+
/// var response = stack.globalField('sso');
470+
/// ```
471+
/// include_branch (optional)
472+
/// ```
473+
/// var response = stack.globalField('sso', true);
474+
/// ```
475+
476+
Future<T> globalField<T, K>(
477+
[String globalFieldUid, bool includeBranch = false]) {
478+
final parameters = <String, String>{};
479+
parameters['environment'] = _client.stackHeaders['environment'];
480+
if (includeBranch) {
481+
parameters['include_branch'] = true.toString();
482+
}
483+
Uri uri = Uri.https(endpoint, '$apiVersion/global_fields', parameters);
484+
if (globalFieldUid != null && globalFieldUid.isNotEmpty) {
485+
uri = Uri.https(
486+
endpoint, '$apiVersion/global_fields/$globalFieldUid', parameters);
487+
}
488+
return _client.sendRequest<T, K>(uri);
489+
}
449490
}

test/stack_test.dart

+15
Original file line numberDiff line numberDiff line change
@@ -152,5 +152,20 @@ void main() {
152152
final url = params.toUrl('cdn.contentstack.io');
153153
expect('cdn.contentstack.io?key1=value1', url);
154154
});
155+
156+
test('global fields without params', () {
157+
var response = stack.globalField();
158+
print(response);
159+
});
160+
161+
test('Global fields with parameters', () {
162+
var response = stack.globalField('sso', false);
163+
print(response);
164+
});
165+
166+
test('Global fields with parameters', () {
167+
var response = stack.globalField('sso', true);
168+
print(response);
169+
});
155170
});
156171
}

0 commit comments

Comments
 (0)