Skip to content

Commit fc70bf3

Browse files
committed
add proxy client
1 parent 1ed8edc commit fc70bf3

11 files changed

+114
-0
lines changed

packages/gridproxy_client/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# https://dart.dev/guides/libraries/private-files
2+
# Created by `dart pub`
3+
.dart_tool/
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 1.0.0
2+
3+
- Initial version.

packages/gridproxy_client/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
A sample command-line application with an entrypoint in `bin/`, library code
2+
in `lib/`, and example unit test in `test/`.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# This file configures the static analysis results for your project (errors,
2+
# warnings, and lints).
3+
#
4+
# This enables the 'recommended' set of lints from `package:lints`.
5+
# This set helps identify many issues that may lead to problems when running
6+
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
7+
# style and format.
8+
#
9+
# If you want a smaller set of lints you can change this to specify
10+
# 'package:lints/core.yaml'. These are just the most critical lints
11+
# (the recommended set includes the core lints).
12+
# The core lints are also what is used by pub.dev for scoring packages.
13+
14+
include: package:lints/recommended.yaml
15+
16+
# Uncomment the following section to specify additional rules.
17+
18+
# linter:
19+
# rules:
20+
# - camel_case_types
21+
22+
# analyzer:
23+
# exclude:
24+
# - path/to/excluded/files/**
25+
26+
# For more information about the core and recommended set of lints, see
27+
# https://dart.dev/go/core-lints
28+
29+
# For additional information about configuring this file, see
30+
# https://dart.dev/guides/language/analysis-options
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import 'package:gridproxy_client/gridproxy_client.dart';
2+
import 'package:gridproxy_client/models/nodes.dart';
3+
4+
void main() async {
5+
GridProxyClient client = GridProxyClient('https://gridproxy.dev.grid.tf');
6+
await client.nodes.getNodeStatus(GetNodeStatusOptions(nodeID: 72));
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
library client;
2+
3+
import 'dart:convert';
4+
import 'package:gridproxy_client/src/nodes.dart';
5+
import 'package:http/http.dart' as http;
6+
7+
8+
part 'src/client.dart';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class GetNodeStatusOptions {
2+
int nodeID;
3+
4+
GetNodeStatusOptions({
5+
required this.nodeID,
6+
});
7+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
part of '../gridproxy_client.dart';
2+
3+
class GridProxyClient {
4+
final String baseUrl;
5+
late final Nodes nodes;
6+
7+
GridProxyClient(this.baseUrl) {
8+
nodes = Nodes(this);
9+
}
10+
11+
Future<dynamic> getRequest(String path) async {
12+
try {
13+
final response = await http.get(Uri.parse('$baseUrl$path'));
14+
15+
if (response.statusCode == 200) {
16+
final jsonData = json.decode(response.body);
17+
return jsonData;
18+
} else {
19+
throw Exception('Failed to load data');
20+
}
21+
} catch (e) {
22+
throw Exception('Error: $e');
23+
}
24+
}
25+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import 'package:gridproxy_client/gridproxy_client.dart';
2+
import 'package:gridproxy_client/models/nodes.dart';
3+
4+
class Nodes {
5+
final GridProxyClient client;
6+
7+
Nodes(this.client);
8+
9+
Future<void> getNodeStatus(GetNodeStatusOptions options) async {
10+
final nodeStatus = await client.getRequest('/nodes/72/status');
11+
print(nodeStatus['status']);
12+
}
13+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: gridproxy_client
2+
description: A sample command-line application.
3+
version: 1.0.0
4+
# repository: https://github.com/my_org/my_repo
5+
6+
environment:
7+
sdk: ^3.3.3
8+
9+
# Add regular dependencies here.
10+
dependencies:
11+
http: ^1.2.1
12+
# path: ^1.8.0
13+
14+
dev_dependencies:
15+
lints: ^3.0.0
16+
test: ^1.24.0

packages/gridproxy_client/test/gridproxy_client_test.dart

Whitespace-only changes.

0 commit comments

Comments
 (0)