Skip to content

Commit

Permalink
- Changed Credentials class to expect "api_key" as the JSON key, even…
Browse files Browse the repository at this point in the history
… though the property is "apiKey"

- Added JSON example to README
- Updated package info
  • Loading branch information
Herohtar committed Jul 14, 2018
1 parent 6451c18 commit fdf3c9a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 13 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [1.0.0] - 2018-07-13
## v1.0.1 - 2018-07-14

* Changed Credentials class serializer to use "api_key" as the key name even though the property name is "apiKey"
* Added JSON example to README

## v1.0.0 - 2018-07-13

* Initial release.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ The idea behind this package is to provide a simple way to use various credentia
You can store your API keys, usernames, passwords, etc. in a JSON file that is either listed in your `.gitignore` or completely outside the project directory and load them into this class. You could also retrieve them from other JSON sources.

## Example
### credentials.json
```json
{
"api_key": "YOUR-API-KEY",
"username": "yourUsername",
"password": "yourPassword"
}
```

### Dart code
```dart
import 'package:credentials_helper/credentials_helper.dart';
Expand Down
12 changes: 4 additions & 8 deletions lib/src/credentials.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,19 @@ part 'credentials.g.dart';
/// Holds various types of credentials
@JsonSerializable(includeIfNull: false)
class Credentials extends Object with _$CredentialsSerializerMixin {
@JsonKey(name: 'api_key')
final String apiKey;

final String username;

final String password;

/// Constructs a new [Credentials] object.
Credentials(
{
this.apiKey,
this.username,
this.password
}
);
Credentials({this.apiKey, this.username, this.password});

/// Constructs a new [Credentials] object from a JSON map
factory Credentials.fromJson(Map<String, dynamic> json) => _$CredentialsFromJson(json);
factory Credentials.fromJson(Map<String, dynamic> json) =>
_$CredentialsFromJson(json);

/// Constructs a new [Credentials] object from a JSON file
factory Credentials.fromFile(String fileName) {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/credentials.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: credentials_helper
description: Provides a helper class to simplify loading credentials from JSON
version: 1.0.0
version: 1.0.1
author: "Herohtar <[email protected]>"
homepage: https://github.com/herohtar/credentials_helper

Expand Down
2 changes: 1 addition & 1 deletion test/credentials_helper_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ void main() {
const String username = 'testUserName';
const String password = 'testPassword';
const String fileName = 'test_credentials.json';
const String jsonString = '{"apiKey":"$apiKey","username":"$username","password":"$password"}';
const String jsonString = '{"api_key":"$apiKey","username":"$username","password":"$password"}';

test('tests the default constructor', () {
Credentials credentials = Credentials(
Expand Down

0 comments on commit fdf3c9a

Please sign in to comment.