AuthObject.buildAuthorization constructor

AuthObject.buildAuthorization({
  1. required String userName,
  2. required String webApiKey,
})

Accepts your RetroAchievements.org username and web API key. After receiving these inputs, the function returns you a value that can be used for the authentication parameter by any of the async calls in this library.

Your account's personal Web API Key can be found on the Settings page of RetroAchievements.org. Do not use a Web API Key that is not associated with your account.

@returns An AuthObject that you can pass to any of the API call functions.

@example

final authorization = buildAuthorization(
  userName: 'Scott',
  webApiKey: 'LtjCwW16nJI7cqOyPIQtXk8v1cfF0tmO',
);

Implementation

factory AuthObject.buildAuthorization({required String userName, required String webApiKey}) {
  if (userName.isEmpty || webApiKey.isEmpty) {
    throw ArgumentError('''
    buildAuthorization() requires an object containing a
    userName and webApiKey. eg:

    final authorization = buildAuthorization(
      userName: 'myUserName',
      webApiKey: 'myWebApiKey',
    )
  ''');
  }

  return AuthObject(userName: userName, webApiKey: webApiKey);
}