Skip to content

Commit

Permalink
Multiple apps
Browse files Browse the repository at this point in the history
  • Loading branch information
leynier committed Jul 26, 2020
1 parent 1569946 commit 3eadd67
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 24 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [0.1.0] - July 26, 2020

* Multiple apps

## [0.0.1] - July 24, 2020

* Initial release
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@ Supports [Dio package](https://pub.dev/packages/dio) and [Http package](https://

## Getting Started

Initialize an instance of the ApklisApi class by passing it the package name as a parameter:
Initialize an instance of the ApklisApi class:

```dart
var apklisApi = ApklisApi(packageName);
var apklisApi = ApklisApi();
```

You can also choose to pass a `Dio` instance or `Client` instance to the `dioClient` and `httpClient` parameters. If both are passed the httpClient will be used.

```dart
var apklisApi = ApklisApi(
packageName,
dioClient: Dio(),
httpClient: Client(),
);
Expand All @@ -27,19 +26,19 @@ var apklisApi = ApklisApi(
To make the request and obtain the information, use the `get` method that returns a Future.

```dart
var info = await apklisApi.get();
var info = await apklisApi.get(['com.example.app1', 'com.example.app2']);
```

If you want to use a specific library, you can use the `getWithDio` and/or `getWithHttp` methods.

```dart
var infoWithDio = await apklisApi.getWithDio();
var infoWithClient = await apklisApi.getWithHttp();
var infoWithDio = await apklisApi.getWithDio(['com.example.app1', 'com.example.app2']);
var infoWithClient = await apklisApi.getWithHttp(['com.example.app1', 'com.example.app2']);
```

Also using the `getWithDio` and/or `getWithHttp` methods you can use a specific instance of `Dio` and `Client` respectively.

```dart
var infoWithDio = await apklisApi.getWithDio(dioClient: Dio());
var infoWithClient = await apklisApi.getWithHttp(httpClient: Client());
var infoWithDio = await apklisApi.getWithDio(['com.example.app1', 'com.example.app2'], dioClient: Dio());
var infoWithClient = await apklisApi.getWithHttp(['com.example.app1', 'com.example.app2'], httpClient: Client());
```
9 changes: 5 additions & 4 deletions example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import 'package:apklis_api/apklis_api.dart';

void main() async {
print('Introduce package name:');
var packageName = stdin.readLineSync(encoding: Encoding.getByName('utf-8'));
var apklisApi = ApklisApi(packageName);
var model = await apklisApi.get();
var packageName1 = stdin.readLineSync(encoding: Encoding.getByName('utf-8'));
var packageName2 = stdin.readLineSync(encoding: Encoding.getByName('utf-8'));
var apklisApi = ApklisApi();
var model = await apklisApi.get([packageName1, packageName2]);
if (model.isOk) {
print(model.result.results.first.name);
print(model.result.results.map((e) => e.name).join('\n'));
} else {
print(model.error);
}
Expand Down
29 changes: 18 additions & 11 deletions lib/apklis_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,28 @@ import 'package:dio/dio.dart';
import 'package:http/http.dart';

class ApklisApi {
static const URL = 'https://api.apklis.cu/v2/application/?package_name=';
final String url;
final String packageName;
static const API_URL = 'https://api.apklis.cu';
final Dio dioClient;
final BaseClient httpClient;

ApklisApi(this.packageName, {this.dioClient, this.httpClient})
: url = URL + packageName;
const ApklisApi({this.dioClient, this.httpClient});

Future<ApklisApiResult> get() async {
Future<ApklisApiResult> get(List<String> apps) async {
if (httpClient != null) {
return await getWithHttp();
return await getWithHttp(apps);
} else if (dioClient != null) {
return await getWithDio();
return await getWithDio(apps);
} else {
return await getWithHttp(httpClient: Client());
return await getWithHttp(apps, httpClient: Client());
}
}

Future<ApklisApiResult> getWithDio({Dio dioClient}) async {
Future<ApklisApiResult> getWithDio(
List<String> apps, {
Dio dioClient,
}) async {
final queryString = apps.map((e) => 'package_name=$e').join('&');
final url = '$API_URL/v2/application/?$queryString';
dioClient ??= this.dioClient;
if (dioClient == null) {
return ApklisApiResult(
Expand Down Expand Up @@ -55,7 +57,12 @@ class ApklisApi {
}
}

Future<ApklisApiResult> getWithHttp({BaseClient httpClient}) async {
Future<ApklisApiResult> getWithHttp(
List<String> apps, {
BaseClient httpClient,
}) async {
final queryString = apps.map((e) => 'package_name=$e').join('&');
final url = '$API_URL/v2/application/?$queryString';
httpClient ??= this.httpClient;
if (httpClient == null) {
return ApklisApiResult(
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: apklis_api
description: API for Apklis (Cuban Android App Store) implemented in Dart
version: 0.0.1
version: 0.1.0
homepage: https://leynier.github.io/apklis-api-dart

environment:
Expand Down

0 comments on commit 3eadd67

Please sign in to comment.