Skip to content

Commit e8b6867

Browse files
Merge pull request #11 from contentstack/improvements
Improvements
2 parents 5b93b54 + 7d24305 commit e8b6867

15 files changed

+82
-87
lines changed

AUTHERS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Below is a list of people and organizations that have contributed to the
1+
# Below is a list of people and organizations that have contributed to the
22

33
[Contentstack LLC](http://contentstack.com/).
44

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# CHANGELOG
22

3+
## `v0.3.0 - Package Improvements`
4+
5+
### __JUN-05-2021__
6+
7+
#### v0.3.0 Package Improvements
8+
9+
- pub dependencies version mismach fixed
10+
- Included UTF-8 encoding
11+
- Removed unused dependencies
12+
13+
_______________________
14+
315
## `v0.2.0 - Support of IncludeEmbeddedItems()`
416

517
### __APR-05-2021__

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2012 - 2020 Contentstack. All rights reserved.
3+
Copyright (c) 2012 - 2021 Contentstack. All rights reserved.
44

55

66
Permission is hereby granted, free of charge, to any person obtaining a copy

analysis_options.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@ linter:
3131
avoid_unused_constructor_parameters: true
3232
await_only_futures: true
3333
camel_case_types: true
34-
# prefer_void_to_null: true
3534
cancel_subscriptions: true
3635
cascade_invocations: true
3736
comment_references: true
38-
# constant_identifier_names: true
3937
control_flow_in_finally: true
4038
directives_ordering: true
4139
empty_catches: true

coverage.json

Whitespace-only changes.

example/example.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Add this to your package's pubspec.yaml file:
3636

3737
```dart
3838
dependencies:
39-
contentstack: any
39+
contentstack: latest
4040
```
4141

4242
You can install packages from the command line:
@@ -60,6 +60,14 @@ To initialize the SDK, specify application context, stack’s API Key, delivery
6060
import 'package:contentstack/contentstack.dart' as contentstack;
6161
final stack = contentstack.Stack("apiKey", "deliveryToken", "environment");
6262
```
63+
64+
## Initialize by configuration
65+
66+
```dart
67+
import 'package:contentstack/contentstack.dart' as contentstack;
68+
final stack = contentstack.Stack("apiKey", "deliveryToken", "environment", host: 'your_host', branch: 'development');
69+
```
70+
6371
## Basic Queries
6472

6573
To retrieve a single entry from a content type use the code snippet given below:

lib/client.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'dart:async';
22
import 'dart:convert';
33

4+
import 'package:contentstack/constant.dart';
45
import 'package:contentstack/contentstack.dart';
56
import 'package:contentstack/src/stack.dart';
67
import 'package:http/http.dart' as http;
@@ -9,8 +10,6 @@ class HttpClient extends http.BaseClient {
910
final http.Client _client;
1011
final Stack stack;
1112
final Map<String, String> stackHeaders;
12-
// Request timout period 30 Seconds
13-
static const timeout = 30;
1413

1514
factory HttpClient(Map<String, String> headers,
1615
{http.Client client, Stack stack}) {
@@ -29,11 +28,11 @@ class HttpClient extends http.BaseClient {
2928
}
3029

3130
Future<T> sendRequest<T, K>(Uri uri) async {
32-
stackHeaders['Content-Type'] = 'application/json';
33-
stackHeaders['X-User-Agent'] = 'contentstack-dart/0.1.1';
31+
stackHeaders[CONTENT_TYPE] = CONTENT_TYPE_VALUE;
32+
stackHeaders[X_USER_AGENT] = X_USER_AGENT_VALUE;
3433
final response = await http
3534
.get(uri, headers: stackHeaders)
36-
.timeout(const Duration(seconds: timeout));
35+
.timeout(const Duration(seconds: TIMEOUT));
3736
Object bodyJson;
3837
try {
3938
bodyJson = jsonDecode(response.body);
@@ -46,7 +45,8 @@ class HttpClient extends http.BaseClient {
4645
rethrow;
4746
}
4847
if (response.statusCode == 200) {
49-
final Map bodyJson = jsonDecode(response.body);
48+
// Decode response to Utf8Codec
49+
final Map bodyJson = json.decode(utf8.decode(response.bodyBytes));
5050
if (T == EntryModel && bodyJson.containsKey('entry')) {
5151
return fromJson<T, K>(bodyJson['entry']);
5252
} else if (K == EntryModel && bodyJson.containsKey('entries')) {
@@ -61,6 +61,7 @@ class HttpClient extends http.BaseClient {
6161
return fromJson<T, K>(bodyJson);
6262
}
6363
} else {
64+
// Response code other than 200
6465
return bodyJson;
6566
}
6667
}

lib/constant.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const SDK_VERSION = '0.3.0';
2+
const SDK_NAME = 'contentstack-dart';
3+
const CONTENT_TYPE = 'Content-Type';
4+
const CONTENT_TYPE_VALUE = 'application/json';
5+
const X_USER_AGENT = 'X-User-Agent';
6+
const X_USER_AGENT_VALUE = '$SDK_NAME-v$SDK_VERSION';
7+
const TIMEOUT = 30;

lib/src/error/error.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'package:json_annotation/json_annotation.dart';
22
part 'error.g.dart';
33

4-
/// If there is something wrong with the API request,
4+
/// If there is something wrong with the API request,
55
/// Contentstack returns an error.
66
/// Learn more about [Errors](https://www.contentstack.com/docs/developers/apis/content-delivery-api/#errors).
77
@JsonSerializable(createFactory: true)

lib/src/image_transform.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class ImageTransformation {
1717
final HttpClient client;
1818
final Map<String, String> queryParameter = <String, String>{};
1919
final URLQueryParams query = URLQueryParams();
20+
2021
ImageTransformation(this._imageUrl, this.client);
2122

2223
/// The auto function lets you enable the functionality that automates

0 commit comments

Comments
 (0)