This repository has been archived by the owner on May 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
326 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Bcfier.Api | ||
{ | ||
public class GitHubAsset | ||
{ | ||
public string url { get; set; } | ||
public int id { get; set; } | ||
public string name { get; set; } | ||
public object label { get; set; } | ||
public GitHubAuthor uploader { get; set; } | ||
public string content_type { get; set; } | ||
public string state { get; set; } | ||
public int size { get; set; } | ||
public int download_count { get; set; } | ||
public string created_at { get; set; } | ||
public string updated_at { get; set; } | ||
public string browser_download_url { get; set; } | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Bcfier.Api | ||
{ | ||
public class GitHubAuthor | ||
{ | ||
public string login { get; set; } | ||
public int id { get; set; } | ||
public string avatar_url { get; set; } | ||
public string gravatar_id { get; set; } | ||
public string url { get; set; } | ||
public string html_url { get; set; } | ||
public string followers_url { get; set; } | ||
public string following_url { get; set; } | ||
public string gists_url { get; set; } | ||
public string starred_url { get; set; } | ||
public string subscriptions_url { get; set; } | ||
public string organizations_url { get; set; } | ||
public string repos_url { get; set; } | ||
public string events_url { get; set; } | ||
public string received_events_url { get; set; } | ||
public string type { get; set; } | ||
public bool site_admin { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Bcfier.Api | ||
{ | ||
public class GitHubRelease | ||
{ | ||
public string url { get; set; } | ||
public string assets_url { get; set; } | ||
public string upload_url { get; set; } | ||
public string html_url { get; set; } | ||
public int id { get; set; } | ||
public string tag_name { get; set; } | ||
public string target_commitish { get; set; } | ||
public string name { get; set; } | ||
public bool draft { get; set; } | ||
public GitHubAuthor author { get; set; } | ||
public bool prerelease { get; set; } | ||
public DateTime created_at { get; set; } | ||
public DateTime published_at { get; set; } | ||
public List<GitHubAsset> assets { get; set; } | ||
public string tarball_url { get; set; } | ||
public string zipball_url { get; set; } | ||
public string body { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using RestSharp; | ||
using DataFormat = RestSharp.DataFormat; | ||
|
||
namespace Bcfier.Api | ||
{ | ||
public static class GitHubRest | ||
{ | ||
internal static RestClient Client | ||
{ | ||
get { return new RestClient(@"https://api.github.com/"); } | ||
} | ||
|
||
internal static async Task<List<GitHubRelease>> GetReleases(CancellationTokenSource cancel) | ||
{ | ||
if (cancel.IsCancellationRequested) | ||
return null; | ||
|
||
|
||
var request = new RestRequest("repos/teocomi/bcfier/releases?access_token=ef85819857533da4a216df2ae8e6db642827e922", Method.GET); | ||
request.AddHeader("Content-Type", "application/json"); | ||
request.RequestFormat = DataFormat.Json; | ||
request.OnBeforeDeserialization = resp => { resp.ContentType = "application/json"; }; | ||
|
||
var response = await DoTaskAsync<List<GitHubRelease>>(request, cancel); | ||
|
||
return cancel.IsCancellationRequested || !CheckResponse(response, HttpStatusCode.OK) ? null : response.Data; | ||
} | ||
internal static async Task<GitHubRelease> GetLatestRelease(CancellationTokenSource cancel) | ||
{ | ||
if (cancel.IsCancellationRequested) | ||
return null; | ||
|
||
|
||
var request = new RestRequest("repos/teocomi/bcfier/releases/latest?access_token=ef85819857533da4a216df2ae8e6db642827e922", Method.GET); | ||
request.AddHeader("Content-Type", "application/json"); | ||
request.RequestFormat = DataFormat.Json; | ||
|
||
var response = await DoTaskAsync<GitHubRelease>(request, cancel); | ||
//if cancellation oending or invalid reponse return null, otherwise the data | ||
return cancel.IsCancellationRequested || !CheckResponse(response, HttpStatusCode.OK) ? null : response.Data; | ||
} | ||
|
||
private static async Task<IRestResponse<T>> DoTaskAsync<T>(RestRequest request, CancellationTokenSource cancel) where T : class | ||
{ | ||
IRestResponse<T> response = null; | ||
try | ||
{ | ||
if (cancel != null) | ||
response = await Client.ExecuteTaskAsync<T>(request, cancel.Token); | ||
} | ||
catch (OperationCanceledException ex) | ||
{ | ||
var gg = ex.Data; | ||
return null; | ||
} | ||
return response; | ||
} | ||
|
||
private static bool CheckResponse(IRestResponse response, HttpStatusCode expectedCode) | ||
{ | ||
try | ||
{ | ||
if (null == response || response.StatusCode != expectedCode) | ||
return false; | ||
} | ||
catch (Exception ex1) | ||
{ | ||
MessageBox.Show("exception: " + ex1); | ||
} | ||
return true; | ||
} | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.