Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding V2 stats as the main and moving V1 stats to their own V1 calls to be deprecated later #4

Open
wants to merge 39 commits into
base: master
Choose a base branch
from

Conversation

Fyb3roptik
Copy link
Contributor

No description provided.

@Fyb3roptik Fyb3roptik mentioned this pull request Mar 19, 2019
@henhouse
Copy link
Owner

Sorry I've been so slow at reviewing this. I will try to get around to it soon.

@Fyb3roptik
Copy link
Contributor Author

Sorry it was a lot of commits lol. There was some back and forth on endpoints

@Fyb3roptik
Copy link
Contributor Author

Added 2FA login as well. Now we can use this library to authenticate users with Epic!

Copy link
Owner

@henhouse henhouse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for taking so long to get around to reviewing this. Truth be told, I haven't played Fortnite in ages. I finally got around to patching my game and figured I should take a look at this. I haven't tested its functionality yet since I wanted to take a look at the code first.

I've made a few minor comments, mostly Go-convention related, that you can take a look at and let me know what you think. Great work!

@@ -166,13 +195,13 @@ func (s *Session) QueryPlayerById(accountId string) (*statsResponse, error) {
req.Header.Set("Authorization", fmt.Sprintf("%v %v", AuthBearer, s.AccessToken))

sr := &statsResponse{}
resp, err := s.client.Do(req, sr)
resp, _, err := s.client.Do(req, sr)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add the new return variable if it's just thrown away? I'd prefer the X-Epic-Device-ID to be built into the error with fmt.Errorf(). What is this device ID for? An identifier of you from them?

epic.go Outdated
@@ -79,7 +99,19 @@ type AccountInfo struct {
}

// Stats is the structure which holds the player's stats for the 3 different game modes offered in Battle Royal.
type FinalStats struct {
Solo *Stats
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's some weird formatting going on here. Are you using gofmt or goimports? It will automatically format your code and fix these issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes sorry I forgot to run it on these. I have more updates coming from my end!

epic.go Outdated
@@ -27,6 +29,9 @@ const (
PC = "pc"
Xbox = "xb1"
PS4 = "ps4"
TOUCH = "touch"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use uppercase on consts in Go (standard convention).

client.go Outdated
@@ -24,8 +28,26 @@ var userAgent = fmt.Sprintf(
Version, runtime.Version(), runtime.GOOS, runtime.GOARCH,
)

func newClient() *Client {
func newClient(use_proxy bool) *Client {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use camel case in Go for variables.

client.go Outdated
// Return default HTTP client for now. @todo replace with defined client
if use_proxy {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm is this more of a personal usage? I am not sure how needed a feature is since Epic can already track you through the user account you're using. What more would adding an ability to proxy requests through Tor give?

"KillsPerMatch": "2.92",
"KillsPerMinute": "0.46",
"Score": 56247
"Touch": {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switch back to spaces instead of tabs in here.

client.go Outdated
// Setup localhost TOR proxy
torProxyUrl, err := url.Parse("socks5://127.0.0.1:9050") // port 9150 is for Tor Browser
if err != nil {
fmt.Println("Unable to parse URL:", err)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer a log.Fatalln() here instead of using os.Exit() in the code. It will call that for you. We also want to write our logs to stderr.

session.go Outdated
@@ -44,35 +44,35 @@ func Create(username, password, launcherToken, gameToken string) *Session {
// Prepare request.
req, err := c.NewRequest(http.MethodPost, oauthTokenURL, strings.NewReader(data.Encode()))
if err != nil {
log.Fatalln(err)
return nil, "", err
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These will never be reached since log.Fatalln() calls os.Exit(). I declared these fatal since the building of the request should never fail, in theory, and if it does, something is very, very wrong with the setup of the request.

@@ -116,15 +149,10 @@ type leaderboardEntry struct {

// QueryPlayer looks up a player by their username and platform, and returns information about that player, namely, the
// statistics for the 3 different party modes.
func (s *Session) QueryPlayer(name string, accountId string, platform string) (*Player, error) {
func (s *Session) QueryPlayer(name string, accountId string) (*Player, error) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not the biggest fan of empty arguments. Perhaps it should be QueryPlayerById() and QueryPlayerByName()? What do you think?

@Fyb3roptik
Copy link
Contributor Author

I have some more changes coming soon. Some of the formatting will be fixed

@Fyb3roptik
Copy link
Contributor Author

I have made some updates that fix the API calls. Currently your version will not work!

@Fyb3roptik Fyb3roptik requested a review from henhouse November 22, 2019 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants