2024-01-27 23:07:06 +01:00
|
|
|
import 'package:shlink_app/API/Classes/ShortURL/short_url_meta.dart';
|
|
|
|
import 'package:shlink_app/API/Classes/ShortURL/visits_summary.dart';
|
|
|
|
|
|
|
|
/// Data about a short URL
|
|
|
|
class ShortURL {
|
|
|
|
/// Slug of the short URL used in the URL
|
|
|
|
String shortCode;
|
2024-01-28 00:32:09 +01:00
|
|
|
|
2024-01-27 23:07:06 +01:00
|
|
|
/// Entire short URL
|
|
|
|
String shortUrl;
|
2024-01-28 00:32:09 +01:00
|
|
|
|
2024-01-27 23:07:06 +01:00
|
|
|
/// Long URL where the user gets redirected to
|
|
|
|
String longUrl;
|
2024-01-28 00:32:09 +01:00
|
|
|
|
2024-01-27 23:07:06 +01:00
|
|
|
/// Creation date of the short URL
|
|
|
|
DateTime dateCreated;
|
2024-01-28 00:32:09 +01:00
|
|
|
|
2024-01-27 23:07:06 +01:00
|
|
|
/// Visitor data
|
|
|
|
VisitsSummary visitsSummary;
|
2024-01-28 00:32:09 +01:00
|
|
|
|
2024-01-27 23:07:06 +01:00
|
|
|
/// List of tags assigned to this short URL
|
2024-01-28 01:05:35 +01:00
|
|
|
List<String> tags;
|
2024-01-28 00:32:09 +01:00
|
|
|
|
2024-01-27 23:07:06 +01:00
|
|
|
/// Metadata
|
|
|
|
ShortURLMeta meta;
|
2024-01-28 00:32:09 +01:00
|
|
|
|
2024-01-27 23:07:06 +01:00
|
|
|
/// Associated domain
|
|
|
|
String? domain;
|
2024-01-28 00:32:09 +01:00
|
|
|
|
2024-01-27 23:07:06 +01:00
|
|
|
/// Optional title
|
|
|
|
String? title;
|
2024-01-28 00:32:09 +01:00
|
|
|
|
2024-01-27 23:07:06 +01:00
|
|
|
/// Whether the short URL is crawlable by a web crawler
|
|
|
|
bool crawlable;
|
|
|
|
|
2024-01-28 00:32:09 +01:00
|
|
|
ShortURL(
|
|
|
|
this.shortCode,
|
|
|
|
this.shortUrl,
|
|
|
|
this.longUrl,
|
|
|
|
this.dateCreated,
|
|
|
|
this.visitsSummary,
|
|
|
|
this.tags,
|
|
|
|
this.meta,
|
|
|
|
this.domain,
|
|
|
|
this.title,
|
|
|
|
this.crawlable);
|
2024-01-27 23:07:06 +01:00
|
|
|
|
|
|
|
/// Converts the JSON data from the API to an instance of [ShortURL]
|
2024-01-28 00:32:09 +01:00
|
|
|
ShortURL.fromJson(Map<String, dynamic> json)
|
|
|
|
: shortCode = json["shortCode"],
|
|
|
|
shortUrl = json["shortUrl"],
|
|
|
|
longUrl = json["longUrl"],
|
|
|
|
dateCreated = DateTime.parse(json["dateCreated"]),
|
|
|
|
visitsSummary = VisitsSummary.fromJson(json["visitsSummary"]),
|
2024-03-31 21:58:31 +02:00
|
|
|
tags =
|
|
|
|
(json["tags"] as List<dynamic>).map((e) => e.toString()).toList(),
|
2024-01-28 00:32:09 +01:00
|
|
|
meta = ShortURLMeta.fromJson(json["meta"]),
|
|
|
|
domain = json["domain"],
|
|
|
|
title = json["title"],
|
|
|
|
crawlable = json["crawlable"];
|
2024-03-31 21:07:30 +02:00
|
|
|
|
|
|
|
/// Returns an empty class of [ShortURL]
|
2024-01-28 22:55:28 +01:00
|
|
|
ShortURL.empty()
|
2024-03-31 21:58:31 +02:00
|
|
|
: shortCode = "",
|
|
|
|
shortUrl = "",
|
|
|
|
longUrl = "",
|
|
|
|
dateCreated = DateTime.now(),
|
|
|
|
visitsSummary = VisitsSummary(0, 0, 0),
|
|
|
|
tags = [],
|
|
|
|
meta = ShortURLMeta(DateTime.now(), DateTime.now(), 0),
|
|
|
|
domain = "",
|
|
|
|
title = "",
|
|
|
|
crawlable = false;
|
2024-01-28 00:32:09 +01:00
|
|
|
}
|