switch to google creds

This commit is contained in:
Kyle Spearrin 2017-02-04 19:05:39 -05:00
parent db04d6e642
commit 08299902e3

View file

@ -5,6 +5,7 @@ using Google.Apis.Services;
using System.Collections.Generic; using System.Collections.Generic;
using Google.Apis.AndroidPublisher.v2.Data; using Google.Apis.AndroidPublisher.v2.Data;
using System.IO; using System.IO;
using Google.Apis.Auth.OAuth2;
namespace Bit.Publisher namespace Bit.Publisher
{ {
@ -13,7 +14,7 @@ namespace Bit.Publisher
private const string Package = "com.x8bit.bitwarden"; private const string Package = "com.x8bit.bitwarden";
private static string _apkFilePath; private static string _apkFilePath;
private static string _apiKey; private static string _credsFilePath;
private static EditsResource.TracksResource.UpdateRequest.TrackEnum _track; private static EditsResource.TracksResource.UpdateRequest.TrackEnum _track;
static void Main(string[] args) static void Main(string[] args)
@ -25,7 +26,7 @@ namespace Bit.Publisher
try try
{ {
_apiKey = args[0]; _credsFilePath = args[0];
_apkFilePath = args[1]; _apkFilePath = args[1];
var track = args[2].Substring(0, 1).ToLower(); var track = args[2].Substring(0, 1).ToLower();
@ -55,33 +56,37 @@ namespace Bit.Publisher
Console.WriteLine("ERROR: " + e.Message); Console.WriteLine("ERROR: " + e.Message);
} }
} }
Console.ReadLine();
} }
private async Task Run() private async Task Run()
{ {
GoogleCredential creds;
using(var stream = new FileStream(_credsFilePath, FileMode.Open))
{
creds = GoogleCredential.FromStream(stream).CreateScoped(AndroidPublisherService.Scope.Androidpublisher);
}
var service = new AndroidPublisherService(new BaseClientService.Initializer var service = new AndroidPublisherService(new BaseClientService.Initializer
{ {
ApplicationName = "appveyor", HttpClientInitializer = creds
ApiKey = _apiKey,
}); });
var editsRequest = new EditsResource.InsertRequest( var editRequest = service.Edits.Insert(null, Package);
service, var edit = await editRequest.ExecuteAsync();
null,
Package);
var edit = await editsRequest.ExecuteAsync();
Console.WriteLine("Created edit with id {0}.", edit.Id); Console.WriteLine("Created edit with id {0}.", edit.Id);
Apk apk = null; Apk apk = null;
var apkResource = new EditsResource.ApksResource(service);
using(var stream = new FileStream(_apkFilePath, FileMode.Open)) using(var stream = new FileStream(_apkFilePath, FileMode.Open))
{ {
var uploadMedia = apkResource.Upload( var uploadMedia = service.Edits.Apks.Upload(
Package, Package,
edit.Id, edit.Id,
stream, stream,
"application/vnd.android.package-archive"); "application/vnd.android.package-archive");
var progress = await uploadMedia.UploadAsync(); var progress = await uploadMedia.UploadAsync();
if(progress.Status == Google.Apis.Upload.UploadStatus.Completed) if(progress.Status == Google.Apis.Upload.UploadStatus.Completed)
{ {
@ -95,8 +100,7 @@ namespace Bit.Publisher
Console.WriteLine("Version code {0} has been uploaded.", apk.VersionCode); Console.WriteLine("Version code {0} has been uploaded.", apk.VersionCode);
var trackRequest = new EditsResource.TracksResource.UpdateRequest( var trackRequest = service.Edits.Tracks.Update(
service,
new Track new Track
{ {
VersionCodes = new List<int?> { apk.VersionCode } VersionCodes = new List<int?> { apk.VersionCode }
@ -108,10 +112,7 @@ namespace Bit.Publisher
Console.WriteLine("Track {0} has been updated.", updatedTrack.TrackValue); Console.WriteLine("Track {0} has been updated.", updatedTrack.TrackValue);
var commitRequest = new EditsResource.CommitRequest( var commitRequest = service.Edits.Commit(Package, edit.Id);
service,
Package,
edit.Id);
var commitEdit = await commitRequest.ExecuteAsync(); var commitEdit = await commitRequest.ExecuteAsync();
Console.WriteLine("App edit with id {0} has been comitted.", commitEdit.Id); Console.WriteLine("App edit with id {0} has been comitted.", commitEdit.Id);