Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development #19

Merged
merged 17 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion . travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ dart_task:
- pub global activate remove_from_coverage
- pub global run remove_from_coverage:remove_from_coverage -f coverage/lcov.info -r '.g.dart$'
- genhtml -o coverage coverage/lcov.info
- open coverage/index.html
- open coverage/index.html
1 change: 1 addition & 0 deletions .dccache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
17 changes: 17 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# .github/workflows/publish.yml
name: Publish to pub.dev

on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*' # tag-pattern on pub.dev: 'v{{version}}'

# Publish using the reusable workflow from dart-lang.
jobs:
publish:
permissions:
id-token: write # Required for authentication using OIDC
uses: dart-lang/setup-dart/.github/workflows/publish.yml@v1
with:
environment: 'pub.dev'
working-directory: .
4 changes: 4 additions & 0 deletions .talismanrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fileignoreconfig:
- filename: pubspec.lock
checksum: d37af197ed50d9896ef5e9e6c4ad4961c11c2c49765e7cb4f4b69695fa562aa5
version: ""
10 changes: 10 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "contentstack-dart",
"request": "launch",
"type": "dart"
}
]
}
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# CHANGELOG

## v0.5.1 - Added support for gcp_na region
#### Added support for gcp_na region

## v0.5.0 - Multiple-reference issue fixed

### **MAR-16-2022**
Expand Down
5 changes: 2 additions & 3 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
MIT License

Copyright (c) 2012 - 2021 Contentstack. All rights reserved.
# MIT License

Copyright (c) 2012 - 2024 Contentstack. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# ![Contentstack](https://www.contentstack.com/docs/static/images/contentstack.png)

## Dart SDK for Contentstack
Expand All @@ -8,6 +7,8 @@
![Dart CI](https://github.com/contentstack/contentstack-dart/workflows/Dart%20CI/badge.svg)
![dartdoc](https://img.shields.io/badge/dartdoc-latest-<green>.svg)

<!-- ![Coverage](https://raw.githubusercontent.com/contentstack/contentstack-dart/master/coverage_badge.svg?sanitize=true) -->

![issues](https://img.shields.io/github/issues/contentstack/contentstack-dart)
![fork](https://img.shields.io/github/forks/contentstack/contentstack-dart)
![starts](https://img.shields.io/github/stars/contentstack/contentstack-dart)
Expand Down Expand Up @@ -71,9 +72,9 @@ Learn how to work with [Environments](https://www.contentstack.com/docs/develope

### Contentstack Dart SDK: 5-minute Quickstart

#### __Initializing your SDK__
#### **Initializing your SDK**

To initialize the SDK, specify application API key, access token, and environment name of the stack
To initialize the SDK, specify application API key, access token, and environment name of the stack
as shown in the snippet given below (config is optional):

```dart
Expand Down
Empty file added coverage.json
Empty file.
7 changes: 5 additions & 2 deletions example/example.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Contentstack Examples

## Developer's Guide
Expand Down Expand Up @@ -50,7 +49,10 @@ flutter pub get

Now in your dart or flutter code, you can use

```

import 'package:contentstack/contentstack.dart' as contentstack;
```

### Initialize SDK

Expand All @@ -61,7 +63,7 @@ import 'package:contentstack/contentstack.dart' as contentstack;
final stack = contentstack.Stack("apiKey", "deliveryToken", "environment");
```

## Initialize by configuration
## Initialize by configuration

```dart
import 'package:contentstack/contentstack.dart' as contentstack;
Expand Down Expand Up @@ -169,3 +171,4 @@ await assetQuery.find<List<AssetModel>, Null>().then((response) {
}).catchError((error) {
print(error.message.toString());
});
```
9 changes: 8 additions & 1 deletion lib/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,21 @@ class HttpClient extends http.BaseClient {
} else if (T == SyncResult && bodyJson.containsKey('items')) {
return fromJson<T, K>(bodyJson);
} else {
if (bodyJson.containsKey('entries')) {
var previewResponse = stack.livePreview['entries'];
if (previewResponse != null) {
return fromJson<T, K>(mergeLivePreview(bodyJson, previewResponse));
}
}
return fromJson<T, K>(bodyJson);
}
} else {
// Response code other than 200
return bodyJson;
}
}

mergeLivePreview(Map bodyJson, Map previewResponse) {}

/// Generic objects as well as List of generic objects
/// (from a JSON list response).
/// First, you need to have a function that checks the type of the
Expand Down
1 change: 0 additions & 1 deletion lib/src/asset_query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ class AssetQuery extends BaseQuery {
queryParameter['version'] = version.toString();
}


///
/// Includes branch in the response
///
Expand Down
1 change: 0 additions & 1 deletion lib/src/contenttype.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class ContentType {
}
}


///
/// This function provide option to get single entry as well as
/// all the entries. [entryUid] is Optional, If [entryUid]
Expand Down
7 changes: 3 additions & 4 deletions lib/src/entry_queryable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class EntryQueryable {
/// includeEmbeddedItems instance of Entry
/// Include Embedded Objects (Entries and Assets) along with entry/entries details
///
/// [Example for Entry class]
/// Example:
/// ```
/// final stack = contentstack.Stack('apiKey','deliveryToken','environment');
/// final entry = stack.contentType("contentTypeUid").entry("entryUid");
Expand All @@ -93,8 +93,8 @@ class EntryQueryable {
}

///
/// Includes branch in the response
/// [Example for Entry class]
/// Includes branch in the Entry response
/// Example:
/// ```
/// final stack = contentstack.Stack('apiKey','deliveryToken','environment');
/// final entry = stack.contentType("contentTypeUid").entry("entryUid");
Expand Down Expand Up @@ -205,7 +205,6 @@ class EntryQueryable {
});
} else {
parameter['include[]'] = referenceFieldUid;
print('We are in multiple references');
}
}
}
Expand Down
21 changes: 10 additions & 11 deletions lib/src/image_transform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,43 +120,42 @@ class ImageTransformation {
/// the canvas area or offset the canvas on its X and Y axis.
///
/// [canvasValue] could be in the type of string,
/// It could be in the format of dimension: [700,800]
/// ratio: 2:3 , sub-region: [700,800,x0.50,y0.60],
/// or offset :[ 700,800,offset-x0.65,offset-y0.80]
/// It could be in the format of dimension: '700','800'
/// ratio: 2:3 , sub-region: '700','800','x0.50','y0.60',
/// or offset : '700','800','offset-x0.65','offset-y0.80'
/// For more details, Read documentation:
/// https://www.contentstack.com/docs/developers/apis/image-delivery-api/#canvas
///
/// Example: Canvas by width & Height:
///
/// ```dart
/// final stack = contentstack.Stack(apiKey, deliveryToken, environment);
/// final stack = contentstack.Stack('apiKey', 'deliveryToken', 'environment');
/// final imageTransformation = stack.imageTransform(imageUrl);
/// final response = imageTransformation.canvas('700,800');
/// final response = imageTransformation.canvas('700','800');
/// ```
///
/// Example: Canvas by ratio:
///
/// ```dart
/// final stack = contentstack.Stack(apiKey, deliveryToken, environment);
/// final imageTransformation = stack.imageTransform(imageUrl);
/// final stack = contentstack.Stack('apiKey', 'deliveryToken', 'environment');
/// final imageTransformation = stack.imageTransform('imageUrl');
/// final response = imageTransformation.canvas('2:3');
/// ```
///
/// Example: Canvas Sub-region:
///
/// ```dart
/// final stack = contentstack.Stack(apiKey, deliveryToken, environment);
/// final stack = contentstack.Stack('apiKey', 'deliveryToken', 'environment');
/// final imageTransformation = stack.imageTransform(imageUrl);
/// final response = imageTransformation.canvas('700,800,x0.50,y0.60');
/// final response = imageTransformation.canvas('700','800','x0.50','y0.60');
/// ```
///
/// Example: Canvas and offset:
///
/// ```dart
/// final stack = contentstack.Stack(apiKey, deliveryToken, environment);
/// final imageTransformation = stack.imageTransform(imageUrl);
/// final response = imageTransformation.
/// canvas('700,800,offset-x0.65,offset-y0.80');
/// final response = imageTransformation.canvas('700','800','offset-x0.65','offset-y0.80');
/// ```
///
void canvas(String canvasValue) {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ class Query extends BaseQuery {
/// includeEmbeddedItems instance of Query
/// Include Embedded Objects (Entries and Assets) along with entry/entries details
///
/// [Example for Entry class]
/// Example:
/// ```
/// final stack = contentstack.Stack('apiKey, 'deliveryKey, 'environment);
/// final stack = contentstack.Stack('apiKey', 'deliveryKey', 'environment');
/// final query = stack.contentType('contentTypeUid').entry().query();
/// query = query.includeEmbeddedItems()
/// ```
Expand Down
77 changes: 67 additions & 10 deletions lib/src/stack.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import 'dart:async';
import 'dart:convert';

import 'package:contentstack/client.dart';
import 'package:contentstack/contentstack.dart';
import 'package:contentstack/src/asset_query.dart';
import 'package:contentstack/src/sync/publishtype.dart';
import 'package:http/http.dart' as http;
import 'package:http/http.dart';

/// Choosing a Region
/// A Contentstack region refers to the location of the data centers
/// where your organization's data resides
/// * Default [Region](https://www.contentstack.com/docs/developers/contentstack-regions/about-regions/) is: US
enum Region { us, eu, azure_na }
enum Region { us, eu, azure_na, gcp_na }

/// A stack is like a container that holds the content of your app.
/// Learn more about [Stacks](https://www.contentstack.com/docs/developers/set-up-stack/about-stack/).
Expand Down Expand Up @@ -78,6 +80,9 @@ class Stack {
_host = 'azure-na.contentstack.com';
}
}
if (region == Region.gcp_na) {
_host = 'gcp-na-cdn.contentstack.com';
}

if (_apiKey.replaceAll(RegExp('\\W'), '').isEmpty ?? true) {
throw ArgumentError.notNull('apiKey');
Expand Down Expand Up @@ -234,7 +239,7 @@ class Stack {
/// Fetches all Content Types from the Stack.
/// This call returns comprehensive information
/// of all the content types available in a particular stack in your account.
/// API Reference: https://www.contentstack.com/docs/apis/content-delivery-api/#content-types
/// API Reference: https://www.contentstack.com/docs/developers/apis/content-delivery-api/#content-types
/// [queryParameters] is query parameters for the content_types of type [Map]
/// returns list of content_types
///
Expand Down Expand Up @@ -432,18 +437,70 @@ class Stack {
if (livePreview.containsKey('enable')) {
final bool enable = livePreview['enable'] as bool;
if (enable) {
if (livePreviewQuery.containsKey('live_preview') &&
livePreviewQuery['live_preview'] != null) {
livePreview['live_preview'] = livePreviewQuery['live_preview'];
} else {
livePreview['live_preview'] = 'init';
}
if (livePreviewQuery.containsKey('content_type_uid') &&
livePreviewQuery['content_type_uid'] != null) {
livePreview['content_type_uid'] =
livePreviewQuery['content_type_uid'];
var content_type_uid = livePreviewQuery['content_type_uid'];
var _entry_uid = livePreviewQuery['entry_uid'];
var _host = livePreviewQuery['host'];
_executeAPI(content_type_uid, _entry_uid, _host);
}
}
}
}

Future _executeAPI(content_type_uid, entry_uid, host) async {
var _url =
"https://$host}/${this.apiVersion}/content_types/$content_type_uid/entries/$entry_uid";
var _headers = {
'authorization': headers['authorization'],
'api_key': headers['api_key'],
};

await http.get(Uri.parse(_url), headers: _headers).then((response) {
Map bodyJson = json.decode(utf8.decode(response.bodyBytes));
print(bodyJson);
livePreview["entry"] = bodyJson['entry'];
});
}

///
///
/// All Global Fields
///
/// All global fields
/// This call returns comprehensive information of all the global fields
/// savailable in a particular stack in your account.
///
/// ```
/// var response = stack.globalField();
/// ```

/// Single Global Field
/// Get a single global field
///
/// This request allows you to fetch comprehensive details of a specific
/// global field.When executing the API call, in the 'URI Parameters' section,
/// provide the unique ID of your global field.
/// ```
/// var response = stack.globalField('sso');
/// ```
/// include_branch (optional)
/// ```
/// var response = stack.globalField('sso', true);
/// ```

Future<T> globalField<T, K>(
[String globalFieldUid, bool includeBranch = false]) {
final parameters = <String, String>{};
parameters['environment'] = _client.stackHeaders['environment'];
if (includeBranch) {
parameters['include_branch'] = true.toString();
}
Uri uri = Uri.https(endpoint, '$apiVersion/global_fields', parameters);
if (globalFieldUid != null && globalFieldUid.isNotEmpty) {
uri = Uri.https(
endpoint, '$apiVersion/global_fields/$globalFieldUid', parameters);
}
return _client.sendRequest<T, K>(uri);
}
}
Loading
Loading