BrentonPoke / ToornamentClient

A java api client for the esports bracket website Toornament.
Apache License 2.0
1 stars 2 forks source link

Can't Post Registration #17

Closed elipongr closed 4 years ago

elipongr commented 4 years ago

So when i am Trying to do this:

 registrations = new Registrations(toornamentClient,tournamentId);
        RegistrationQuery registrationQuery = RegistrationQuery
                .builder()
                .name(toornamentName)
                .email(toornamentMail)
                .tournament_id(tournamentId)
                .type(RegistrationType.PLAYER)
                .customField("beschwoerername",summonerName)
                .customField("discordname",user.getId())
                .build();
        Registration registrationResponse =registrations.register(registrationQuery);

I am getting following Error:

No content to map due to end-of-input
 at [Source: (String)""; line: 1, column: 0]
[JDA MainWS-ReadThread] ERROR net.dv8tion.jda.api.JDA - One of the EventListeners had an uncaught exception
com.toornament.exception.ToornamentException
    at com.toornament.concepts.Registrations.register(Registrations.java:65)
    at commands.RegisterCommand.registerUserToTournament(RegisterCommand.java:71)

Note: .customField is a selfmade attribute by me in tha RegistrationQuery Class:

  @JsonProperty("custom_fields")
    @Singular()
    private Map<String,String> customFields;

Note2: you can see the full code here: https://github.com/ownedbypeli/pelis-tournament-manager/blob/master/src/main/java/commands/RegisterCommand.java

Also i debugged the code and and the body object seems to be okey it looks like:

{
  "name" : "ownedbypeli",
  "type" : "player",
  "tournament_id" : "3516126849330733056",
  "email" : "pelipongracz@gmail.com",
  "lineup" : [ ],
  "custom_fields" : {
    "beschwoerername" : "peli",
    "discordname" : "239677780600684544"
  }
}
BrentonPoke commented 4 years ago

Sorry about the long wait, I've been trying to take care of something with my university.

So I think I see now what you're trying to do. Just to be clear, i'm following Toornament's documentation here for the creation of custom fields. I'm actually surprised to find that they never created a discord id as part of the spec. I have noticed some errors on my part, like the Full Name field, and I'll fix that.

However, after some digging, I see there are some things I didn't quite account for as far as total control. I wasn't aware that you could create your own custom fields outside the spec and also wasn't aware that you could change the machine names like "instagram" and "vimeo". And therein lies the problem you're running into. If you want to use an entirely custom field, you have to create it in your tournament first the method signature for that is createCustomField(String tournamentID, Custom query) in Tournaments.java. After that, the registration flow should go something like this:

Registrations registration = client.registrations("3563800755903569920");
            RegistrationQueryBuilder query = RegistrationQuery.builder();
            CustomFields fields = new CustomFields();
            fields.setInstagram("brenton_poke");
            fields.setTwitter("@brentonpoke");

            Participant participant = new Participant();
            participant.setName("Brenton");
            participant.setCustomUserIdentifier("TuskegeeHeir");

            query.type(RegistrationType.TEAM)
                .name("Terrance")
                .email("person@mail.com")
                .customFields(fields)
                .lineup(participant)
                .tournament_id("3563800755903569920");

            registration.register(query.build());

But I am having trouble doing this myself due to some authorization issues I haven't gotten to the bottom of yet. :upside_down_face:

elipongr commented 4 years ago

But how do i add then discordName and beschwoerename to the customfield object? I didnt understood that thats why i made a map for that.

Also are you sure its a problem with the object? Because i copied the body object and tried it in Postman and there it worked.

Are you 100% sure this code is correct?

Because as i said, the RegistrationQuery object i created seems correct, even if changed CustomFields to a map.

As i said the error is No content to map due to end-of-input at [Source: (String)""; line: 1, column: 0]

public Registration register(RegistrationQuery registration) { Builder urlBuilder = new Builder(); this.logger.debug("Scopes {}", this.client.getScope()); if (this.client.getScope().contains(Scope.ORGANIZER_REGISTRATION)) { urlBuilder.scheme("https").host("api.toornament.com").addEncodedPathSegment("organizer").addEncodedPathSegment("v2").addEncodedPathSegment("tournaments").addEncodedPathSegment(this.tournamentID).addEncodedPathSegment("registrations"); } else if (this.client.getScope().contains(Scope.MANAGE_REGISTRATIONS)) { urlBuilder.scheme("https").host("api.toornament.com").addEncodedPathSegment("participant").addEncodedPathSegment("v2").addEncodedPathSegment("me").addEncodedPathSegment("registrations"); }

this.logger.debug("url: {}", urlBuilder.build().toString());
RequestBody body =

RequestBody.create(MediaType.parse("application/json"), registration.toString()); Request request = this.client.getRequestBuilder().post(body).url(urlBuilder.build()).build();

try {
    String responseBody =

this.client.executeRequest(request).body().string(); return (Registration)this.mapper.readValue(responseBody, this.mapper.constructType(Registration.class)); } catch (NullPointerException | IOException var6) { System.out.println(var6.getMessage()); throw new ToornamentException("Got Exception posting Participant"); } }

Am Do., 14. Mai 2020 um 13:56 Uhr schrieb Brenton Poke < notifications@github.com>:

Sorry about the long wait, I've been trying to take care of something with my university.

So I think I see now what you're trying to do. Just to be clear, i'm following Toornament's documentation here https://developer.toornament.com/v2/core-concepts/custom-fields#custom-field-address for the creation of custom fields. I'm actually surprised to find that they never created a discord id as part of the spec. I have noticed some errors on my part, like the Full Name field, and I'll fix that.

However, after some digging, I see there are some things I didn't quite account for as far as total control. I wasn't aware that you could create your own custom fields outside the spec and also wasn't aware that you could change the machine names like "instagram" and "vimeo". And therein lies the problem you're running into. If you want to use an entirely custom field, you have to create it in your tournament first the method signature for that is createCustomField(String tournamentID, Custom query) in Tournaments.java. After that, the registration flow should go something like this:

Registrations registration = client.registrations("3563800755903569920");

        RegistrationQueryBuilder query = RegistrationQuery.builder();

        CustomFields fields = new CustomFields();

        fields.setInstagram("brenton_poke");

        fields.setTwitter("@brentonpoke");

        Participant participant = new Participant();

        participant.setName("Brenton");

        participant.setCustomUserIdentifier("TuskegeeHeir");

        query.type(RegistrationType.TEAM)

            .name("Terrance")

            .email("person@mail.com")

            .customFields(fields)

            .lineup(participant)

            .tournament_id("3563800755903569920");

        registration.register(query.build());

But I am having trouble doing this myself due to some authorization issues I haven't gotten to the bottom of yet. 🙃

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/BrentonPoke/ToornamentClient/issues/17#issuecomment-628585298, or unsubscribe https://github.com/notifications/unsubscribe-auth/AITHVUTVX3NH6O7KLHYZ2QTRRPL7XANCNFSM4M5OMGJQ .

elipongr commented 4 years ago

Actually i debuged the code deeper and found out that i am getting a 401:

[image: grafik.png]

BrentonPoke commented 4 years ago

I can't see the image. Can you edit that response in github to display it? I'm getting a 401 even in postman, but not sure why. Depending on what your image shows, I might get closer to figuring it out.

elipongr commented 4 years ago

grafik

elipongr commented 4 years ago

In Postman it is working grafik grafik

BrentonPoke commented 4 years ago

Ok, i see my error in postman; I was not submitting the API key in the headers. That's the reason behind the 401. I also found the offending code. The highlighted line is a non-authenticated version of the request builder, meaning it wasn't applying the API key. So now I just have to take care of the deserialization, because that's failing. But that should be much simpler than hunting this down. I can probably have that part figured out sometime tonight. Screenshot from 2020-05-14 18-03-43

elipongr commented 4 years ago

Okey good, good luck mate!

BrentonPoke commented 4 years ago

So I got the issue resolved, but almost missed the fact that a bunch of tests were failing (the badge on the README didn't update >:-| ). Check the commit 7278a97353a318519cd19ccb8b1463cb255d5827

elipongr commented 4 years ago

Yeah it seems to work now.

But how should i add beschwoerername and discordName to the body without my customfield map