Skip to content

Commit

Permalink
Force ApiStrategy
Browse files Browse the repository at this point in the history
  • Loading branch information
FeroxRev committed Aug 1, 2016
1 parent 9a074d8 commit 5fbf7fc
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 89 deletions.
3 changes: 2 additions & 1 deletion PokemonGo.RocketAPI/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ public class Client
internal string ApiUrl { get; set; }
internal AuthTicket AuthTicket { get; set; }

public Client(ISettings settings)
public Client(ISettings settings, IApiFailureStrategy apiFailureStrategy)
{
Settings = settings;
ApiFailure = apiFailureStrategy;

Login = new Rpc.Login(this);
Player = new Rpc.Player(this);
Expand Down
176 changes: 88 additions & 88 deletions PokemonGo.RocketAPI/Rpc/Login.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Google.Protobuf;
using PokemonGo.RocketAPI.Enums;
using PokemonGo.RocketAPI.Exceptions;
using PokemonGo.RocketAPI.Extensions;
using PokemonGo.RocketAPI.Helpers;
using PokemonGo.RocketAPI.Login;
using POGOProtos.Networking.Requests;
using POGOProtos.Networking.Requests.Messages;

namespace PokemonGo.RocketAPI.Rpc
{
public delegate void GoogleDeviceCodeDelegate(string code, string uri);
public class Login : BaseRpc
{
//public event GoogleDeviceCodeDelegate GoogleDeviceCodeEvent;
private ILoginType login;

public Login(Client client) : base(client)
{
login = SetLoginType(client.Settings);
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Google.Protobuf;
using PokemonGo.RocketAPI.Enums;
using PokemonGo.RocketAPI.Exceptions;
using PokemonGo.RocketAPI.Extensions;
using PokemonGo.RocketAPI.Helpers;
using PokemonGo.RocketAPI.Login;
using POGOProtos.Networking.Requests;
using POGOProtos.Networking.Requests.Messages;

namespace PokemonGo.RocketAPI.Rpc
{
public delegate void GoogleDeviceCodeDelegate(string code, string uri);
public class Login : BaseRpc
{
//public event GoogleDeviceCodeDelegate GoogleDeviceCodeEvent;
private ILoginType login;

public Login(Client client) : base(client)
{
login = SetLoginType(client.Settings);
}

private static ILoginType SetLoginType(ISettings settings)
{
switch (settings.AuthType)
Expand All @@ -36,67 +36,67 @@ private static ILoginType SetLoginType(ISettings settings)
default:
throw new ArgumentOutOfRangeException(nameof(settings.AuthType), "Unknown AuthType");
}
}

}

public async Task DoLogin()
{
{
_client.AuthToken = await login.GetAccessToken().ConfigureAwait(false);
await SetServer().ConfigureAwait(false);
}

private async Task SetServer()
{
#region Standard intial request messages in right Order

var getPlayerMessage = new GetPlayerMessage();
var getHatchedEggsMessage = new GetHatchedEggsMessage();
var getInventoryMessage = new GetInventoryMessage
{
LastTimestampMs = DateTime.UtcNow.ToUnixTime()
};
var checkAwardedBadgesMessage = new CheckAwardedBadgesMessage();
var downloadSettingsMessage = new DownloadSettingsMessage
{
Hash = "05daf51635c82611d1aac95c0b051d3ec088a930"
};

#endregion

var serverRequest = RequestBuilder.GetInitialRequestEnvelope(
new Request
{
RequestType = RequestType.GetPlayer,
RequestMessage = getPlayerMessage.ToByteString()
}, new Request
{
RequestType = RequestType.GetHatchedEggs,
RequestMessage = getHatchedEggsMessage.ToByteString()
}, new Request
{
RequestType = RequestType.GetInventory,
RequestMessage = getInventoryMessage.ToByteString()
}, new Request
{
RequestType = RequestType.CheckAwardedBadges,
RequestMessage = checkAwardedBadgesMessage.ToByteString()
}, new Request
{
RequestType = RequestType.DownloadSettings,
RequestMessage = downloadSettingsMessage.ToByteString()
});


var serverResponse = await PostProto<Request>(Resources.RpcUrl, serverRequest);

if (serverResponse.AuthTicket == null)
{
_client.AuthToken = null;
throw new AccessTokenExpiredException();
}

_client.AuthTicket = serverResponse.AuthTicket;
_client.ApiUrl = serverResponse.ApiUrl;
}

}
}
}

private async Task SetServer()
{
#region Standard intial request messages in right Order

var getPlayerMessage = new GetPlayerMessage();
var getHatchedEggsMessage = new GetHatchedEggsMessage();
var getInventoryMessage = new GetInventoryMessage
{
LastTimestampMs = DateTime.UtcNow.ToUnixTime()
};
var checkAwardedBadgesMessage = new CheckAwardedBadgesMessage();
var downloadSettingsMessage = new DownloadSettingsMessage
{
Hash = "05daf51635c82611d1aac95c0b051d3ec088a930"
};

#endregion

var serverRequest = RequestBuilder.GetInitialRequestEnvelope(
new Request
{
RequestType = RequestType.GetPlayer,
RequestMessage = getPlayerMessage.ToByteString()
}, new Request
{
RequestType = RequestType.GetHatchedEggs,
RequestMessage = getHatchedEggsMessage.ToByteString()
}, new Request
{
RequestType = RequestType.GetInventory,
RequestMessage = getInventoryMessage.ToByteString()
}, new Request
{
RequestType = RequestType.CheckAwardedBadges,
RequestMessage = checkAwardedBadgesMessage.ToByteString()
}, new Request
{
RequestType = RequestType.DownloadSettings,
RequestMessage = downloadSettingsMessage.ToByteString()
});


var serverResponse = await PostProto<Request>(Resources.RpcUrl, serverRequest);

if (serverResponse.AuthTicket == null)
{
_client.AuthToken = null;
throw new AccessTokenExpiredException();
}

_client.AuthTicket = serverResponse.AuthTicket;
_client.ApiUrl = serverResponse.ApiUrl;
}

}
}

0 comments on commit 5fbf7fc

Please sign in to comment.