Skip to content

Commit c29665d

Browse files
committed
Fetch repo & package data from github & nuget apis.
1 parent fe34641 commit c29665d

9 files changed

Lines changed: 87 additions & 7 deletions

File tree

src/app/root/components/footer/footer.component.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,17 @@
2020
<a href="{{settings.gitHubRepo}}" target="blank" class="nav-link">
2121
<i class="fa fa-github"></i>
2222
GitHub
23+
<a href="{{settings.gitHubRepo + '/stargazers'}}" target="blank" class="badge badge-light">
24+
<i class="fa fa-star"></i>
25+
{{ (gitHubRepo$ | async)?.stargazers_count}}
26+
</a>
2327
</a>
2428
<a href="{{settings.nugetPackage}}" target="blank" class="nav-link">
2529
<i class="fa fa-download"></i>
2630
Nuget
31+
<span class="badge badge-light">
32+
{{ (nugetPackage$ | async)?.data[0].totalDownloads}}
33+
</span>
2734
</a>
2835
</div>
2936
</nav>
Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
1-
import {Component} from "@angular/core";
1+
import {Component, OnInit} from "@angular/core";
2+
import {Observable} from "rxjs";
23
import {environment} from "../../../../environments/environment";
4+
import {LibService} from "../../services";
5+
import {IGitHubRepo, INugetPackage} from "../../models";
36

47
@Component({
58
selector: "app-footer",
69
templateUrl: "./footer.component.html",
710
styleUrls: ["./footer.component.sass"]
811
})
9-
export class FooterComponent {
12+
export class FooterComponent implements OnInit {
1013

1114
year: number = new Date().getFullYear();
1215
settings = environment;
16+
17+
gitHubRepo$: Observable<IGitHubRepo>;
18+
nugetPackage$: Observable<INugetPackage>;
19+
20+
constructor (private libService: LibService) {}
21+
22+
ngOnInit() {
23+
this.gitHubRepo$ = this.libService.fetchGitHubRepo();
24+
this.nugetPackage$ = this.libService.fetchNugetPackage();
25+
}
1326
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface IGitHubRepo {
2+
id: string;
3+
stargazers_count: number;
4+
}

src/app/root/models/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from "./git-hub-repo.model";
2+
export * from "./nuget-package.model";
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export interface INugetPackage {
2+
data: {
3+
id: string;
4+
version: string;
5+
description: string;
6+
summary: string;
7+
title: string;
8+
licenseUrl: string;
9+
tags: string[];
10+
authors: string[];
11+
totalDownloads: number;
12+
verified: boolean;
13+
versions: {
14+
version: string,
15+
downloads: number,
16+
"@id": string;
17+
}[];
18+
}[];
19+
}

src/app/root/services/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import {GlobalService} from "./global.service";
2+
import {LibService} from "./lib.service";
23

34
export * from "./global.service";
5+
export * from "./lib.service";
46

57
export const SERVICES: any[] = [
6-
GlobalService
8+
GlobalService,
9+
LibService
710
];
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import {Injectable} from "@angular/core";
2+
import {HttpClient} from "@angular/common/http";
3+
import {Observable} from "rxjs";
4+
import {environment} from "../../../environments/environment";
5+
import {IGitHubRepo, INugetPackage} from "../models";
6+
7+
/**
8+
* A library service to fetch git-hb & nuget-package data.
9+
*/
10+
@Injectable()
11+
export class LibService {
12+
13+
constructor (private http: HttpClient) {}
14+
15+
/**
16+
* Fetches the git-hub-repo data.
17+
*/
18+
public fetchGitHubRepo(): Observable<IGitHubRepo> {
19+
return this.http.get<IGitHubRepo>(environment.gitHubApi);
20+
}
21+
22+
/**
23+
* Fetches the nuget-package data.
24+
*/
25+
public fetchNugetPackage(): Observable<INugetPackage> {
26+
return this.http.get<INugetPackage>(environment.nugetApi);
27+
}
28+
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
export const environment = {
22
production: true,
3-
gitHubRepo: "https://github.com/dotnet-validator/lib",
3+
gitHubRepo: "https://github.com/DotNetValidator/DotNetValidator",
4+
gitHubApi: "https://api.github.com/repos/DotNetValidator/DotNetValidator",
45
nugetPackage: "https://www.nuget.org/packages/DotNetValidator/",
5-
stackOverflow: "https://stackoverflow.com/questions/tagged/dotnet-validator",
6+
nugetApi: "https://api-v2v3search-0.nuget.org/query?q=packageid:dotnetvalidator",
7+
stackOverflow: "https://stackoverflow.com/questions/tagged/DotNetValidator",
68
};

src/environments/environment.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44

55
export const environment = {
66
production: false,
7-
gitHubRepo: "https://github.com/dotnet-validator/lib",
7+
gitHubRepo: "https://github.com/DotNetValidator/DotNetValidator",
8+
gitHubApi: "https://api.github.com/repos/DotNetValidator/DotNetValidator",
89
nugetPackage: "https://www.nuget.org/packages/DotNetValidator/",
9-
stackOverflow: "https://stackoverflow.com/questions/tagged/dotnet-validator",
10+
nugetApi: "https://api-v2v3search-0.nuget.org/query?q=packageid:dotnetvalidator",
11+
stackOverflow: "https://stackoverflow.com/questions/tagged/DotNetValidator",
1012
};
1113

1214
/*

0 commit comments

Comments
 (0)