Skip to content

Commit

Permalink
2.0.0 (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
nt4f04uNd authored Jul 20, 2021
2 parents 3fc33dd + d06281e commit 4398e0d
Show file tree
Hide file tree
Showing 13 changed files with 256 additions and 248 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## [1.0.0] - May 09, 2020
## 2.0.0

- null safety
- const constructors
- lints
- fixed that `GeniusApiAuth.token` had `Future<void>` return type isntead of `Future<String>`
- updated dependencies

## 1.0.0

- Initial release.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ final api = GeniusApiRaw(
// Get info about song "https://genius.com/Yxngxr1-riley-reid-lyrics".
final res = await api.getSong(4585202);
print(res.data['song']['full_title']); // Outputs "Riley Reid by ​yxngxr1"
print(res.data!['song']['full_title']); // Outputs "Riley Reid by ​yxngxr1"
```

## Further Reading
Expand Down
21 changes: 9 additions & 12 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
# Defines a default set of lint rules enforced for
# projects at Google. For details and rationale,
# see https://github.com/dart-lang/pedantic#enabled-lints.
include: package:pedantic/analysis_options.yaml

# For lint rules and documentation, see http://dart-lang.github.io/linter/lints.
# Uncomment to specify additional rules.
# linter:
# rules:
# - camel_case_types
include: package:flutter_lints/flutter.yaml

analyzer:
# exclude:
# - path/to/excluded/files/**
exclude:
- example/*

linter:
rules:
public_member_api_docs: true
avoid_print: false

3 changes: 1 addition & 2 deletions example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,5 @@ Future<void> main() async {

// Get info about song "https://genius.com/Yxngxr1-riley-reid-lyrics".
final res = await api.getSong(4585202);
print(res.data['song']['full_title']); // Outputs "Riley Reid by ​yxngxr1"

print(res.data!['song']['full_title']); // Outputs "Riley Reid by ​yxngxr1"
}
38 changes: 21 additions & 17 deletions lib/src/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import 'dart:convert';
import 'dart:io';

import 'package:enum_to_string/enum_to_string.dart';

import 'core.dart';
import 'utils.dart';
import 'package:meta/meta.dart';
Expand All @@ -23,7 +25,7 @@ class GeniusApiAuth {
/// into Genius API, see [authorize].
///
/// Used in [authorize], you don't this in [GeniusApiAuth.server()].
final String clientId;
final String? clientId;

/// Your application's Client Secret, as listed on the
/// [API Client management page](https://genius.com/api-clients).
Expand All @@ -32,7 +34,7 @@ class GeniusApiAuth {
/// after user authorizes with [authorize].
///
/// Used in [token], you don't this in [GeniusApiAuth.client()].
final String clientSecret;
final String? clientSecret;

/// The URI that Genius will redirect the user to after he has authorized in your application.
/// It must be the same as the one set for the API client on [management page](https://genius.com/api-clients).
Expand All @@ -42,9 +44,10 @@ class GeniusApiAuth {

/// Default constructor.
///
/// Prefer using named constructors instead of it as there's no actual reason to specify together both [clientId] and [clientSecret]
///
/// The `redirectUri` in the constructor can be either a [String] or a [Uri].
@Deprecated(
"Prefer using named constructors instead of it as there's no actual reason to specify together both [clientId] and [clientSecret]")
@visibleForTesting
GeniusApiAuth({
this.clientId,
this.clientSecret,
Expand All @@ -55,7 +58,7 @@ class GeniusApiAuth {
/// See [authorize].
///
/// The `redirectUri` in the constructor can be either a [String] or a [Uri].
GeniusApiAuth.client({@required this.clientId, @required dynamic redirectUri})
GeniusApiAuth.client({required this.clientId, required dynamic redirectUri})
: redirectUri = checkUri(redirectUri),
clientSecret = null,
assert(clientId != null && redirectUri != null);
Expand All @@ -64,8 +67,7 @@ class GeniusApiAuth {
/// See [token].
///
/// The `redirectUri` in the constructor can be either a [String] or a [Uri].
GeniusApiAuth.server(
{@required this.clientSecret, @required dynamic redirectUri})
GeniusApiAuth.server({required this.clientSecret, required dynamic redirectUri})
: redirectUri = checkUri(redirectUri),
clientId = null,
assert(clientSecret != null && redirectUri != null);
Expand Down Expand Up @@ -113,7 +115,7 @@ class GeniusApiAuth {
/// Don't use the token flow if you don't have to.
Uri constructAuthorize({
List<GeniusApiAuthScope> scope = const [GeniusApiAuthScope.me],
String state,
String? state,
GeniusApiAuthResponseType responseType = GeniusApiAuthResponseType.code,
}) {
assert(clientId != null,
Expand All @@ -136,7 +138,7 @@ class GeniusApiAuth {
/// See [constructAuthorize] and [openUrlOnDesktop] for the full description.
Future<ProcessResult> authorize({
List<GeniusApiAuthScope> scope = const [GeniusApiAuthScope.me],
String state,
String? state,
GeniusApiAuthResponseType responseType = GeniusApiAuthResponseType.code,
}) {
try {
Expand All @@ -162,7 +164,7 @@ class GeniusApiAuth {
/// The [code] is code query parameter from the redirect to your [redirectUri] in [authorize].
///
/// Throws [GeniusApiException] ([GeniusApiException.apiRequest] will be null).
Future<void> token(String code) async {
Future<String> token(String code) async {
assert(clientSecret != null,
"You haven't specified [clientSecret] for using this method");

Expand All @@ -181,7 +183,7 @@ class GeniusApiAuth {
if (res.statusCode >= 200 && res.statusCode < 300) {
return json['access_token'];
} else {
var message;
String? message;
if (json['meta'] != null) {
message = json['meta']['message'];
}
Expand Down Expand Up @@ -213,14 +215,18 @@ enum GeniusApiAuthScope {
/// ```
/// POST /annotations
/// ```
create_annotation,
// ignore: constant_identifier_names
create_annotation, // for easy serialization in [GeniusApiAuthScopeStringValue] keep it snake case

/// Endpoints
/// ```
/// PUT /annotations/:id
/// DELETE /annotations/:id
/// ```
manage_annotation,
// ignore: constant_identifier_names
manage_annotation, // for easy serialization in [GeniusApiAuthScopeStringValue] keep it snake case

/// Endpoints
/// ```
Expand All @@ -244,16 +250,14 @@ enum GeniusApiAuthResponseType {
extension GeniusApiAuthScopeStringValue on GeniusApiAuthScope {
/// Returns a string with the value of enum
String get stringValue {
if (this == null) return 'null';
return toString().substring('GeniusApiAuthScope.'.length);
return EnumToString.convertToString(this);
}
}

/// Extension to serialize the value of [GeniusApiAuthResponseType].
extension GeniusApiAuthResponseTypeStringValue on GeniusApiAuthResponseType {
/// Returns a string with the value of enum.
String get stringValue {
if (this == null) return 'null';
return toString().substring('GeniusApiAuthResponseType.'.length);
return EnumToString.convertToString(this);
}
}
Loading

0 comments on commit 4398e0d

Please sign in to comment.