Skip to content

Commit 9f5be3f

Browse files
committed
Initial commit
0 parents  commit 9f5be3f

16 files changed

+696
-0
lines changed

.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Files and directories created by pub.
2+
.dart_tool/
3+
.packages
4+
5+
# Conventional directory for build outputs.
6+
build/
7+
8+
# Omit committing pubspec.lock for library packages; see
9+
# https://dart.dev/guides/libraries/private-files#pubspeclock.
10+
pubspec.lock

.idea/.gitignore

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/libraries/Dart_Packages.xml

+404
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/libraries/Dart_SDK.xml

+28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 1.0.0
2+
3+
- Initial version.

LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Cosmas Ken
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<!--
2+
This README describes the package. If you publish this package to pub.dev,
3+
this README's contents appear on the landing page for your package.
4+
5+
For information about how to write a good package README, see the guide for
6+
[writing package pages](https://dart.dev/guides/libraries/writing-package-pages).
7+
8+
For general information about developing packages, see the Dart guide for
9+
[creating packages](https://dart.dev/guides/libraries/create-library-packages)
10+
and the Flutter guide for
11+
[developing packages and plugins](https://flutter.dev/developing-packages).
12+
-->
13+
14+
Reloadly is a wrapper library for Reloadly that helps Send airtime online with a simple integration
15+
16+
## Features
17+
18+
Getting reloadly token
19+
Getting reloadly balance
20+
More methods in next update
21+
22+
## Getting started
23+
24+
Depends on dio :4.0.0
25+
26+
## Usage
27+
28+
## Installing
29+
Add reloadly to your pubspec.yaml file:
30+
31+
reloadly: 1.0.0
32+
33+
Import reloadly in files that it will be used:
34+
35+
import 'package:reloadly/reloadly.dart';
36+
37+
## Get token
38+
var reloadly = Reloadly();
39+
<!-- To get token use this method
40+
Takes a client_id and client_secret
41+
-->
42+
String token = await reloadly.getToken('YOUR_CLIENT_ID_HERE','client_secret');
43+
44+
## Get balance
45+
var reloadly = Reloadly();
46+
<!-- To get balance use this method.
47+
The method takes the token received from the above method
48+
-->
49+
String balance= await reloadly.getBalance(token);
50+
51+
52+
## How to Contribute
53+
Want to contribute to the project? We will be proud to highlight you as one of our collaborators. Here are some points where you can contribute and make Get (and Flutter) even better.
54+
55+
Helping to translate the readme into other languages.
56+
Adding documentation to the readme.
57+
Write articles or make videos teaching how to use reloadly (they will be inserted in the Readme and in the future in our Wiki).
58+
Offering PRs for code/tests.
59+
Including new functions.
60+
Any contribution is welcome!.

analysis_options.yaml

+30
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

example/reloadly_example.dart

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import 'package:reloadly/reloadly.dart';
2+
3+
Future<void> main() async {
4+
var reloadly = Reloadly();
5+
//gettoken
6+
String token = await reloadly.getToken('YOUR_CLIENT_ID_HERE','client_secret');
7+
//get balance
8+
String balance= await reloadly.getBalance(token);
9+
10+
11+
}

lib/reloadly.dart

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/// Support for doing something awesome.
2+
///
3+
/// More dartdocs go here.
4+
library reloadly;
5+
6+
export 'src/reloadly_base.dart';
7+
8+
// TODO: Export any libraries intended for clients of this package.

lib/src/reloadly_base.dart

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import 'dart:convert';
2+
3+
import 'package:dio/dio.dart' as dio;
4+
String balanceUrl='https://topups.reloadly.com/accounts/balance';
5+
String tokenUrl='https://auth.reloadly.com/oauth/token';
6+
7+
/// Checks if you are awesome. Spoiler: you are.
8+
class Awesome {
9+
bool get isAwesome => true;
10+
}
11+
12+
class Reloadly{
13+
Future<String> getToken(String client_id,String client_secret) async {
14+
var net = dio.Dio();
15+
var body = {
16+
"client_id": client_id,
17+
"client_secret": client_secret,
18+
"grant_type": "client_credentials",
19+
"audience": "https://topups.reloadly.com"
20+
};
21+
try{
22+
dio.Response token = await net.post(tokenUrl,
23+
data: body,
24+
options: dio.Options(
25+
headers: {
26+
'Content-type': 'application/json'
27+
},
28+
));
29+
Map<dynamic, dynamic> tokendata = token.data;
30+
return tokendata["access_token"];
31+
// print(_token);
32+
33+
} catch (error, stacktrace) {
34+
throw Exception("Exception occured: $error stackTrace: $stacktrace");
35+
}
36+
}
37+
Future<String> getBalance(String tokenString) async {
38+
var net = dio.Dio();
39+
40+
try{
41+
dio.Response token = await net.get(balanceUrl,
42+
options: dio.Options(
43+
headers: {
44+
'Authorization': 'Bearer '+tokenString,
45+
'Content-type': 'application/json'
46+
},
47+
));
48+
49+
print(token.toString());
50+
Map<String, dynamic> map = json.decode(token.toString());
51+
//balance.value =map["balance"].toString() ;
52+
return map["balance"].toString();
53+
54+
} catch (error, stacktrace) {
55+
throw Exception("Exception occured: $error stackTrace: $stacktrace");
56+
}
57+
}
58+
}

pubspec.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: reloadly
2+
description: A starting point for Dart libraries or applications.
3+
version: 1.0.1
4+
# homepage: https://www.example.com
5+
6+
environment:
7+
sdk: '>=2.14.2 <3.0.0'
8+
9+
10+
dependencies:
11+
dio: ^4.0.0
12+
13+
14+
dev_dependencies:
15+
lints: ^1.0.0
16+
test: ^1.16.0

reloadly.iml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="WEB_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<excludeFolder url="file://$MODULE_DIR$/.dart_tool" />
7+
<excludeFolder url="file://$MODULE_DIR$/.pub" />
8+
<excludeFolder url="file://$MODULE_DIR$/build" />
9+
</content>
10+
<orderEntry type="sourceFolder" forTests="false" />
11+
<orderEntry type="library" name="Dart SDK" level="project" />
12+
<orderEntry type="library" name="Dart Packages" level="project" />
13+
</component>
14+
</module>

test/reloadly_test.dart

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import 'package:reloadly/reloadly.dart';
2+
import 'package:test/test.dart';
3+
4+
void main() {
5+
group('A group of tests', () {
6+
final awesome = Awesome();
7+
8+
setUp(() {
9+
// Additional setup goes here.
10+
});
11+
12+
test('First Test', () {
13+
expect(awesome.isAwesome, isTrue);
14+
});
15+
});
16+
}

0 commit comments

Comments
 (0)