seperated todoist and habitica api calls into services
This commit is contained in:
@@ -67,8 +67,8 @@
|
||||
<Reference Include="Microsoft.Threading.Tasks.Extensions, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Bcl.Async.1.0.165\lib\net45\Microsoft.Threading.Tasks.Extensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.6.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
@@ -129,6 +129,10 @@
|
||||
<Project>{1EDCF34E-E1B1-4F82-AEC7-90C35A267967}</Project>
|
||||
<Name>Habitica.Todoist.Integration.Model</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Habitica.Todoist.Integration.Services\Habitica.Todoist.Integration.Services.csproj">
|
||||
<Project>{A804D4CC-B5CC-466F-AF3D-E850B16D2D15}</Project>
|
||||
<Name>Habitica.Todoist.Integration.Services</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" />
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Habitica.Todoist.Integration.Model.Habitica;
|
||||
using Habitica.Todoist.Integration.Model.Todoist;
|
||||
using Habitica.Todoist.Integration.Services;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
@@ -27,17 +28,10 @@ namespace Habitica.Todoist.Integration.Console
|
||||
{
|
||||
ConfigBuild();
|
||||
|
||||
SyncResponse response = null;
|
||||
using (var client = new WebClient())
|
||||
{
|
||||
client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
|
||||
var token = "*";
|
||||
var body = $"token={todoistApiKey}&sync_token={token}&resource_types=[\"items\"]";
|
||||
response = JsonConvert.DeserializeObject<SyncResponse>(client.UploadString($"{todoistApiUrl}sync", body));
|
||||
}
|
||||
|
||||
|
||||
foreach (var item in response.Items)
|
||||
var todoistClient = new TodoistClientService(todoistApiKey);
|
||||
var syncResponse = todoistClient.GetUpdatedItems().ConfigureAwait(false).GetAwaiter().GetResult();
|
||||
|
||||
foreach (var item in syncResponse.Items)
|
||||
{
|
||||
var newTask = new Task
|
||||
{
|
||||
@@ -47,18 +41,8 @@ namespace Habitica.Todoist.Integration.Console
|
||||
Priority = GetHabiticaDifficulty(item.GetDifficulty().GetValueOrDefault())
|
||||
};
|
||||
|
||||
using (var client = new WebClient())
|
||||
{
|
||||
client.Headers["Content-Type"] = "application/json";
|
||||
client.Headers["x-api-user"] = habiticaUserId;
|
||||
client.Headers["x-api-key"] = habiticaApiKey;
|
||||
client.Headers["x-client"] = "console-test";
|
||||
|
||||
var result = client.UploadString($"{habiticaApiUrl}tasks/user", "POST", JsonConvert.SerializeObject(newTask, Formatting.Indented));
|
||||
|
||||
System.Console.WriteLine(result);
|
||||
System.Console.ReadKey();
|
||||
}
|
||||
var habiticaClient = new HabiticaClientService(habiticaUserId, habiticaApiKey);
|
||||
var task = habiticaClient.CreateUserTask(newTask).ConfigureAwait(false).GetAwaiter().GetResult();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<package id="Microsoft.Extensions.FileSystemGlobbing" version="3.1.2" targetFramework="net472" />
|
||||
<package id="Microsoft.Extensions.Primitives" version="3.1.2" targetFramework="net472" />
|
||||
<package id="Microsoft.Net.Http" version="2.2.22" targetFramework="net471" />
|
||||
<package id="Newtonsoft.Json" version="6.0.3" targetFramework="net471" />
|
||||
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net472" />
|
||||
<package id="System.Buffers" version="4.5.0" targetFramework="net472" />
|
||||
<package id="System.Memory" version="4.5.3" targetFramework="net472" />
|
||||
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net472" />
|
||||
|
||||
Reference in New Issue
Block a user