Skip to content
This repository was archived by the owner on May 25, 2025. It is now read-only.

Commit e7867d3

Browse files
committed
feat: initial commit for repository package
- Added .gitignore file - Created README.md - Added analysis options - Created repository library - Added tests
0 parents  commit e7867d3

File tree

7 files changed

+757
-0
lines changed

7 files changed

+757
-0
lines changed

.gitignore

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.build/
9+
.buildlog/
10+
.history
11+
.svn/
12+
.swiftpm/
13+
migrate_working_dir/
14+
15+
# IntelliJ related
16+
*.iml
17+
*.ipr
18+
*.iws
19+
.idea/*
20+
21+
# Visual Studio Code related
22+
.classpath
23+
.project
24+
.settings/
25+
.vscode/*
26+
27+
# packages file containing multi-root paths
28+
.packages.generated
29+
30+
# Flutter/Dart/Pub related
31+
**/doc/api/
32+
**/ios/Flutter/.last_build_id
33+
.dart_tool/
34+
.flutter-plugins
35+
.flutter-plugins-dependencies
36+
.packages
37+
.pub-cache/
38+
.pub/
39+
build/
40+
flutter_*.png
41+
linked_*.ds
42+
unlinked.ds
43+
unlinked_spec.ds
44+
.fvm/
45+
46+
# Android related
47+
**/android/**/gradle-wrapper.jar
48+
**/android/.gradle
49+
**/android/captures/
50+
**/android/local.properties
51+
**/android/**/GeneratedPluginRegistrant.java
52+
**/android/key.properties
53+
**/android/.idea/
54+
**/android/app/debug
55+
**/android/app/profile
56+
**/android/app/release
57+
*.jks
58+
59+
# iOS/XCode related
60+
**/ios/**/*.mode1v3
61+
**/ios/**/*.mode2v3
62+
**/ios/**/*.moved-aside
63+
**/ios/**/*.pbxuser
64+
**/ios/**/*.perspectivev3
65+
**/ios/**/*sync/
66+
**/ios/**/.sconsign.dblite
67+
**/ios/**/.tags*
68+
**/ios/**/.vagrant/
69+
**/ios/**/DerivedData/
70+
**/ios/**/Icon?
71+
**/ios/**/Pods/
72+
**/ios/**/.symlinks/
73+
**/ios/**/profile
74+
**/ios/**/xcuserdata
75+
**/ios/.generated/
76+
**/ios/Flutter/App.framework
77+
**/ios/Flutter/Flutter.framework
78+
**/ios/Flutter/Flutter.podspec
79+
**/ios/Flutter/Generated.xcconfig
80+
**/ios/Flutter/app.flx
81+
**/ios/Flutter/app.zip
82+
**/ios/Flutter/.last_build_id
83+
**/ios/Flutter/flutter_assets/
84+
**/ios/Flutter/flutter_export_environment.sh
85+
**/ios/ServiceDefinitions.json
86+
**/ios/Runner/GeneratedPluginRegistrant.*
87+
88+
# Coverage
89+
coverage/
90+
91+
# Submodules
92+
packages/**/pubspec.lock
93+
94+
# Web related
95+
lib/generated_plugin_registrant.dart
96+
97+
# Symbolication related
98+
app.*.symbols
99+
100+
# Obfuscation related
101+
app.*.map.json
102+
103+
# Exceptions to the above rules.
104+
!**/ios/**/default.mode1v3
105+
!**/ios/**/default.mode2v3
106+
!**/ios/**/default.pbxuser
107+
!**/ios/**/default.perspectivev3
108+
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
109+
!/dev/ci/**/Gemfile.lock
110+
!.vscode/extensions.json
111+
!.vscode/launch.json
112+
!.idea/codeStyles/
113+
!.idea/dictionaries/
114+
!.idea/runConfigurations/
115+
116+
# Ignore non-CI golden files and failures
117+
**/test/**/goldens/**/*.*
118+
**/test/**/failures/**/*.*
119+
!**/test/**/goldens/ci/*.*

README.md

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
A Dart package that provides a repository for managing news headlines data.
2+
It abstracts the data source and provides a clean API for
3+
fetching, creating, updating, deleting, and searching headlines.
4+
5+
## Features
6+
7+
- **Fetch Headlines:** Retrieve a paginated list of news headlines. Supports optional filtering by category, source, and event country.
8+
- **Get Headline by ID:** Fetch a specific headline by its unique identifier.
9+
- **Create Headline:** Add a new headline to the data source.
10+
- **Update Headline:** Modify an existing headline in the data source.
11+
- **Delete Headline:** Remove a headline from the data source.
12+
- **Search Headlines:** Search for headlines based on a query string.
13+
- **Stream Headlines:** Get a stream of headlines that updates periodically.
14+
- **Error Handling:** Provides custom exceptions for specific error scenarios
15+
(e.g., `HeadlinesFetchException`, `HeadlineNotFoundException`, `HeadlineCreateException`, `HeadlineUpdateException`, `HeadlineDeleteException`, `HeadlinesSearchException`).
16+
17+
## Getting started
18+
19+
To use this package, add `ht_headlines_repository` as a dependency in your `pubspec.yaml` file.
20+
21+
```yaml
22+
dependencies:
23+
ht_headlines_repository:
24+
git:
25+
url: https://github.com/Headlines-Toolkit/ht-headlines-client.git
26+
ref: main
27+
```
28+
29+
Then, import the package in your Dart code:
30+
31+
```dart
32+
import 'package:ht_headlines_repository/ht_headlines_repository.dart';
33+
```
34+
35+
## Usage
36+
37+
Create an instance of `HtHeadlinesRepository` by passing a `HtHeadlinesClient` instance.
38+
39+
```dart
40+
import 'package:ht_headlines_client/ht_headlines_client.dart';
41+
import 'package:ht_headlines_repository/ht_headlines_repository.dart';
42+
43+
void main() async {
44+
// Replace with your HtHeadlinesClient implementation
45+
final headlinesClient = MyHeadlinesClient();
46+
final headlinesRepository =
47+
HtHeadlinesRepository(client: headlinesClient);
48+
49+
// --- getHeadlines ---
50+
try {
51+
// Fetch headlines (paginated)
52+
final headlinesPage1 = await headlinesRepository.getHeadlines(limit: 10);
53+
print('Page 1: ${headlinesPage1.items}');
54+
55+
// Fetch headlines with filtering
56+
final filteredHeadlines = await headlinesRepository.getHeadlines(
57+
limit: 5,
58+
category: 'technology',
59+
source: 'TechCrunch',
60+
);
61+
print('Filtered Headlines: ${filteredHeadlines.items}');
62+
63+
if (headlinesPage1.hasMore) {
64+
final headlinesPage2 = await headlinesRepository.getHeadlines(
65+
limit: 10,
66+
startAfterId: headlinesPage1.cursor,
67+
);
68+
print('Page 2: ${headlinesPage2.items}');
69+
}
70+
} on HeadlinesFetchException catch (e) {
71+
print('Error fetching headlines: $e');
72+
}
73+
74+
// --- getHeadline ---
75+
try {
76+
final headline = await headlinesRepository.getHeadline(id: 'some_id');
77+
if (headline != null) {
78+
print('Headline: $headline');
79+
} else {
80+
print('Headline not found.');
81+
}
82+
} on HeadlineNotFoundException catch (e) {
83+
print('Error fetching headline: $e');
84+
} on HeadlinesFetchException catch (e) {
85+
print('Error fetching headline: $e');
86+
}
87+
88+
// --- createHeadline ---
89+
try {
90+
final newHeadline = Headline(
91+
id: 'new_id',
92+
title: 'New Headline',
93+
description: 'This is a new headline.',
94+
url: 'https://example.com/new-headline',
95+
publishedAt: DateTime.now(),
96+
);
97+
final createdHeadline =
98+
await headlinesRepository.createHeadline(headline: newHeadline);
99+
print('Created Headline: $createdHeadline');
100+
} on HeadlineCreateException catch (e) {
101+
print('Error creating headline: $e');
102+
}
103+
104+
// --- updateHeadline ---
105+
try {
106+
final updatedHeadline = Headline(
107+
id: 'existing_id', // Replace with an existing headline ID
108+
title: 'Updated Headline',
109+
description: 'This headline has been updated.',
110+
);
111+
final result =
112+
await headlinesRepository.updateHeadline(headline: updatedHeadline);
113+
print('Updated Headline: $result');
114+
} on HeadlineUpdateException catch (e) {
115+
print('Error updating headline: $e');
116+
}
117+
118+
// --- deleteHeadline ---
119+
try {
120+
await headlinesRepository.deleteHeadline(id: 'existing_id'); // Replace with existing ID
121+
print('Headline deleted successfully.');
122+
} on HeadlineDeleteException catch (e) {
123+
print('Error deleting headline: $e');
124+
}
125+
126+
// --- searchHeadlines ---
127+
try {
128+
final searchedHeadlines =
129+
await headlinesRepository.searchHeadlines(query: 'example');
130+
print('Searched Headlines: $searchedHeadlines.items}');
131+
} on HeadlinesSearchException catch (e) {
132+
print('Error searching headlines: $e');
133+
}
134+
135+
// --- getHeadlinesStream ---
136+
try {
137+
headlinesRepository
138+
.getHeadlinesStream(limit: 5, interval: const Duration(seconds: 30))
139+
.listen((headlines) {
140+
print('Streamed Headlines: ${headlines.items}');
141+
});
142+
} on HeadlinesFetchException catch (e) {
143+
print('Error fetching headlines stream: $e');
144+
}
145+
}
146+
```
147+
148+
149+
## Additional information
150+
151+
This package is designed to be data source agnostic, allowing you to easily switch
152+
between different backend implementations by providing a different `HtHeadlinesClient`.
153+
154+
For issues and contributions, please refer to the [GitHub repository](https://github.com/Headlines-Toolkit/ht-headlines-client).

analysis_options.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include: package:very_good_analysis/analysis_options.7.0.0.yaml

lib/ht_headlines_repository.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/// repository for managing news headline data. It abstracts the data source
2+
/// and provides a clean API for fetching, creating, updating, deleting, and
3+
/// searching headlines.
4+
library;
5+
6+
export 'package:ht_headlines_client/ht_headlines_client.dart'
7+
show
8+
Headline,
9+
HeadlineCreateException,
10+
HeadlineDeleteException,
11+
HeadlineNotFoundException,
12+
HeadlineUpdateException,
13+
HeadlinesException,
14+
HeadlinesFetchException,
15+
HeadlinesSearchException,
16+
HtHeadlinesClient;
17+
18+
export 'src/ht_headlines_repository.dart';

0 commit comments

Comments
 (0)