forked from lwlizhe/flutter_novel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
1,424 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,71 @@ | ||
import 'package:flutter_novel/app/novel/entity/entity_book_detail.dart'; | ||
import 'package:flutter_novel/base/http/manager_net_request.dart'; | ||
|
||
class NovelApi { | ||
static const String DMZJ_REFERER_URL = "http://images.dmzj.com/"; | ||
static const String BASE_URL = "http://api.zhuishushenqi.com/"; | ||
|
||
static const String BASE_URL = "https://v3api.dmzj.com/novel/"; | ||
|
||
static const String HOME_RECOMMEND = BASE_URL + "recommend.json"; | ||
|
||
static const String QUERY_AUTO_COMPLETE_KEYWORD = | ||
"http://api.zhuishushenqi.com/book/auto-complete?query="; | ||
static const String QUERY_AUTO_COMPLETE_QUERY_KEYWORD = | ||
BASE_URL + "book/auto-complete?query="; | ||
static const String QUERY_HOT_QUERY_KEYWORD = BASE_URL + "book/hot-word"; | ||
static const String QUERY_BOOK_DETAIL_INFO = BASE_URL + "book/"; | ||
|
||
var client = NetRequestManager.instance; | ||
|
||
Future<List<String>> getSearchWord(String keyWord) async { | ||
Future<BaseResponse<List<String>>> getSearchWord(String keyWord) async { | ||
var response; | ||
List<String> result = []; | ||
response = | ||
await client.getRequest(url: QUERY_AUTO_COMPLETE_KEYWORD + keyWord); | ||
bool isOk = response.data["ok"]; | ||
if (isOk) { | ||
for (var data in response.data["keywords"]) { | ||
result.add(data); | ||
BaseResponse<List<String>> result = BaseResponse(); | ||
List<String> resultData = []; | ||
try { | ||
response = | ||
await client.getRequest(QUERY_AUTO_COMPLETE_QUERY_KEYWORD + keyWord); | ||
bool isOk = response?.data["ok"]; | ||
if (isOk) { | ||
for (var data in response.data["keywords"]) { | ||
resultData.add(data); | ||
} | ||
} | ||
result.isSuccess = isOk; | ||
result.data = resultData; | ||
} catch (e) { | ||
print("$e"); | ||
result.isSuccess = false; | ||
} | ||
return result; | ||
} | ||
|
||
Future<BaseResponse<List<String>>> getHotSearchWord() async { | ||
var response; | ||
BaseResponse<List<String>> result = BaseResponse(); | ||
|
||
List<String> resultData = []; | ||
try { | ||
response = await client.getRequest(QUERY_HOT_QUERY_KEYWORD); | ||
for (var data in response.data["hotWords"]) { | ||
resultData.add(data); | ||
} | ||
result.isSuccess = true; | ||
result.data = resultData; | ||
} catch (e) { | ||
print("$e"); | ||
} | ||
return result; | ||
} | ||
|
||
Future<BaseResponse<NovelDetailInfo>> getNovelDetailInfo( | ||
String bookId) async { | ||
BaseResponse<NovelDetailInfo> result = BaseResponse()..isSuccess = false; | ||
try { | ||
var response = await client.getRequest(QUERY_BOOK_DETAIL_INFO + bookId); | ||
result.isSuccess = true; | ||
result.data = NovelDetailInfo.fromJson(response.data); | ||
} catch (e) { | ||
print("$e"); | ||
} | ||
return result; | ||
} | ||
} | ||
|
||
class BaseResponse<T> { | ||
bool isSuccess; | ||
T data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,211 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'entity_book_detail.g.dart'; | ||
|
||
@JsonSerializable() | ||
class NovelDetailInfo extends Object { | ||
|
||
@JsonKey(name: '_id') | ||
String id; | ||
|
||
@JsonKey(name: 'title') | ||
String title; | ||
|
||
@JsonKey(name: 'author') | ||
String author; | ||
|
||
@JsonKey(name: 'majorCate') | ||
String majorCate; | ||
|
||
@JsonKey(name: 'cover') | ||
String cover; | ||
|
||
@JsonKey(name: 'longIntro') | ||
String longIntro; | ||
|
||
@JsonKey(name: 'starRatingCount') | ||
int starRatingCount; | ||
|
||
@JsonKey(name: 'starRatings') | ||
List<StarRatings> starRatings; | ||
|
||
@JsonKey(name: 'isMakeMoneyLimit') | ||
bool isMakeMoneyLimit; | ||
|
||
@JsonKey(name: 'contentLevel') | ||
int contentLevel; | ||
|
||
@JsonKey(name: 'isFineBook') | ||
bool isFineBook; | ||
|
||
@JsonKey(name: 'safelevel') | ||
int safelevel; | ||
|
||
@JsonKey(name: 'allowFree') | ||
bool allowFree; | ||
|
||
@JsonKey(name: 'originalAuthor') | ||
String originalAuthor; | ||
|
||
@JsonKey(name: 'anchors') | ||
List<dynamic> anchors; | ||
|
||
@JsonKey(name: 'authorDesc') | ||
String authorDesc; | ||
|
||
@JsonKey(name: 'rating') | ||
Rating rating; | ||
|
||
@JsonKey(name: 'hasCopyright') | ||
bool hasCopyright; | ||
|
||
@JsonKey(name: 'buytype') | ||
int buytype; | ||
|
||
@JsonKey(name: 'sizetype') | ||
int sizetype; | ||
|
||
@JsonKey(name: 'superscript') | ||
String superscript; | ||
|
||
@JsonKey(name: 'currency') | ||
int currency; | ||
|
||
@JsonKey(name: 'contentType') | ||
String contentType; | ||
|
||
@JsonKey(name: '_le') | ||
bool le; | ||
|
||
@JsonKey(name: 'allowMonthly') | ||
bool allowMonthly; | ||
|
||
@JsonKey(name: 'allowVoucher') | ||
bool allowVoucher; | ||
|
||
@JsonKey(name: 'allowBeanVoucher') | ||
bool allowBeanVoucher; | ||
|
||
@JsonKey(name: 'hasCp') | ||
bool hasCp; | ||
|
||
@JsonKey(name: 'banned') | ||
int banned; | ||
|
||
@JsonKey(name: 'postCount') | ||
int postCount; | ||
|
||
@JsonKey(name: 'totalFollower') | ||
int totalFollower; | ||
|
||
@JsonKey(name: 'latelyFollower') | ||
int latelyFollower; | ||
|
||
@JsonKey(name: 'followerCount') | ||
int followerCount; | ||
|
||
@JsonKey(name: 'wordCount') | ||
int wordCount; | ||
|
||
@JsonKey(name: 'serializeWordCount') | ||
int serializeWordCount; | ||
|
||
@JsonKey(name: 'retentionRatio') | ||
String retentionRatio; | ||
|
||
@JsonKey(name: 'updated') | ||
String updated; | ||
|
||
@JsonKey(name: 'isSerial') | ||
bool isSerial; | ||
|
||
@JsonKey(name: 'chaptersCount') | ||
int chaptersCount; | ||
|
||
@JsonKey(name: 'lastChapter') | ||
String lastChapter; | ||
|
||
@JsonKey(name: 'gender') | ||
List<dynamic> gender; | ||
|
||
@JsonKey(name: 'tags') | ||
List<dynamic> tags; | ||
|
||
@JsonKey(name: 'advertRead') | ||
bool advertRead; | ||
|
||
@JsonKey(name: 'donate') | ||
bool donate; | ||
|
||
@JsonKey(name: 'copyright') | ||
String copyright; | ||
|
||
@JsonKey(name: '_gg') | ||
bool gg; | ||
|
||
@JsonKey(name: 'isForbidForFreeApp') | ||
bool isForbidForFreeApp; | ||
|
||
@JsonKey(name: 'isAllowNetSearch') | ||
bool isAllowNetSearch; | ||
|
||
@JsonKey(name: 'limit') | ||
bool limit; | ||
|
||
@JsonKey(name: 'copyrightInfo') | ||
String copyrightInfo; | ||
|
||
@JsonKey(name: 'copyrightDesc') | ||
String copyrightDesc; | ||
|
||
NovelDetailInfo(this.id,this.title,this.author,this.majorCate,this.cover,this.longIntro,this.starRatingCount,this.starRatings,this.isMakeMoneyLimit,this.contentLevel,this.isFineBook,this.safelevel,this.allowFree,this.originalAuthor,this.anchors,this.authorDesc,this.rating,this.hasCopyright,this.buytype,this.sizetype,this.superscript,this.currency,this.contentType,this.le,this.allowMonthly,this.allowVoucher,this.allowBeanVoucher,this.hasCp,this.banned,this.postCount,this.totalFollower,this.latelyFollower,this.followerCount,this.wordCount,this.serializeWordCount,this.retentionRatio,this.updated,this.isSerial,this.chaptersCount,this.lastChapter,this.gender,this.tags,this.advertRead,this.donate,this.copyright,this.gg,this.isForbidForFreeApp,this.isAllowNetSearch,this.limit,this.copyrightInfo,this.copyrightDesc,); | ||
|
||
factory NovelDetailInfo.fromJson(Map<String, dynamic> srcJson) => _$NovelDetailInfoFromJson(srcJson); | ||
|
||
Map<String, dynamic> toJson() => _$NovelDetailInfoToJson(this); | ||
|
||
} | ||
|
||
|
||
@JsonSerializable() | ||
class StarRatings extends Object { | ||
|
||
@JsonKey(name: 'count') | ||
int count; | ||
|
||
@JsonKey(name: 'star') | ||
int star; | ||
|
||
StarRatings(this.count,this.star,); | ||
|
||
factory StarRatings.fromJson(Map<String, dynamic> srcJson) => _$StarRatingsFromJson(srcJson); | ||
|
||
Map<String, dynamic> toJson() => _$StarRatingsToJson(this); | ||
|
||
} | ||
|
||
|
||
@JsonSerializable() | ||
class Rating extends Object { | ||
|
||
@JsonKey(name: 'score') | ||
double score; | ||
|
||
@JsonKey(name: 'count') | ||
int count; | ||
|
||
@JsonKey(name: 'tip') | ||
String tip; | ||
|
||
@JsonKey(name: 'isEffect') | ||
bool isEffect; | ||
|
||
Rating(this.score,this.count,this.tip,this.isEffect,); | ||
|
||
factory Rating.fromJson(Map<String, dynamic> srcJson) => _$RatingFromJson(srcJson); | ||
|
||
Map<String, dynamic> toJson() => _$RatingToJson(this); | ||
|
||
} | ||
|
||
|
Oops, something went wrong.