-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
85 lines (72 loc) · 2.41 KB
/
Copy pathProgram.cs
File metadata and controls
85 lines (72 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using Microsoft.Extensions.DependencyInjection;
using SolidJobs;
using SolidJobs.Models;
var services = new ServiceCollection();
services.AddHttpClient<SolidJobsClient>(http =>
{
http.BaseAddress = new Uri("https://solid.jobs/");
http.DefaultRequestHeaders.Add("X-Api-Version", "1.0");
http.Timeout = TimeSpan.FromSeconds(30);
});
var provider = services.BuildServiceProvider();
var client = provider.GetRequiredService<SolidJobsClient>();
using var cts = new CancellationTokenSource(TimeSpan.FromMinutes(2));
const string campaign = "dotnet-client";
// `dotnet run stats` runs the market-statistics demo instead of the offers demo.
if (args.Contains("stats"))
{
await StatisticsDemo.RunAsync(client, "dotnet-stats", cts.Token);
return;
}
// `dotnet run raport` runs the yearly market-raport demo.
if (args.Contains("raport"))
{
await RaportDemo.RunAsync(client, "dotnet-raport", cts.Token);
return;
}
var firstPage = await client.GetOffersAsync(
Division.IT,
campaign,
new OfferQuery { PageSize = 5 },
cts.Token);
Console.WriteLine($"Found {firstPage.TotalCount} offers (pages: {firstPage.TotalPages}).");
foreach (var job in firstPage.Jobs)
{
Console.WriteLine($"{job.Title} @ {job.Company} [{job.ExperienceLevel}] ({FormatSalary(job.Salary)})");
}
var seniorJava = await client.GetOffersAsync(
Division.IT,
campaign,
new OfferQuery
{
SearchTerms = ["java"],
Cities = ["Warszawa"],
SubCategories = [JobSubCategory.Java],
Experiences = [ExperienceLevel.Senior],
MinimumSalary = 15_000,
Sort = SortField.SalaryTo,
Direction = SortDirection.Desc,
PageSize = 10,
},
cts.Token);
Console.WriteLine($"\nSenior Java in Warsaw: {seniorJava.TotalCount} offers");
foreach (var job in seniorJava.Jobs)
{
Console.WriteLine($"- {job.Title} ({FormatSalary(job.Salary)})");
}
Console.WriteLine("\nAll .NET offers:");
var counter = 0;
await foreach (var job in client.GetAllOffersAsync(
Division.IT,
campaign,
new OfferQuery { SubCategories = [JobSubCategory.DotNet] },
cts.Token))
{
counter++;
Console.WriteLine($"{counter,3}. {job.Title} @ {job.Company}");
}
Console.WriteLine($"Total: {counter}");
static string FormatSalary(Salary salary) =>
salary is { From: null, To: null }
? $"no range ({salary.Currency})"
: $"{salary.From:0}-{salary.To:0} {salary.Currency}/{salary.Period}";