# PokerogueAccountApi | pokemon-rogue-battle
Documentation for pokemon-rogue-battle

# Class PokerogueAccountApi

A wrapper for PokéRogue account API requests.

#### Hierarchy (View Summary)

- ApiBase
  - PokerogueAccountApi

- Defined in src/plugins/api/pokerogue-account-api.ts:14

##### Index

### Constructors

constructor

### Properties

base
ERR_GENERIC

### Methods

doFetch
doGet
doPost
getInfo
login
logout
register
toUrlSearchParams

## Constructors

### constructor

- new PokerogueAccountApi(base: string): PokerogueAccountApi

  #### Parameters

  - base: string

  #### Returns PokerogueAccountApi

  Inherited from ApiBase.constructor

  - Defined in src/plugins/api/api-base.ts:15

## Properties

### `Protected` `Readonly` base

base: string

Inherited from ApiBase.base

- Defined in src/plugins/api/api-base.ts:11

### `Readonly` ERR_GENERIC

ERR_GENERIC: string = "There was an error"

Inherited from ApiBase.ERR_GENERIC

- Defined in src/plugins/api/api-base.ts:9

## Methods

### `Protected` doFetch

- doFetch(path: string, config: RequestInit): Promise<Response>

  A generic request helper.

  #### Parameters

  - path: string

    The path to send the request to.

  - config: RequestInit

    The request RequestInit | Configuration.

  #### Returns Promise<Response>

  Inherited from ApiBase.doFetch

  - Defined in src/plugins/api/api-base.ts:65

### `Protected` doGet

- doGet(path: string): Promise<Response>

  Send a GET request.

  #### Parameters

  - path: string

    The path to send the request to.

  #### Returns Promise<Response>

  Inherited from ApiBase.doGet

  - Defined in src/plugins/api/api-base.ts:25

### `Protected` doPost

- doPost< D = undefined>(
  path: string,
  bodyData?: D ,
  dataType?: DataType,
  ): Promise<Response>

  Send a POST request.

  #### Type Parameters

  - D = undefined

  #### Parameters

  - path: string

    THe path to send the request to.

  - `Optional` bodyData: D

    The body-data to send.

  - dataType: DataType = "json"

    The data-type of the bodyData.

  #### Returns Promise<Response>

  Inherited from ApiBase.doPost

  - Defined in src/plugins/api/api-base.ts:35

### getInfo

- getInfo(): Promise<[data: null | AccountInfoResponse , status: number]>

  Request the `UserInfo` of the logged in user. The user is identified by the `session cookie`.

  #### Returns Promise<[data: null | AccountInfoResponse , status: number]>

  - Defined in src/plugins/api/pokerogue-account-api.ts:21

### login

- login(loginData: AccountLoginRequest ): Promise<null | string>

  Send a login request. Sets the session cookie on success.

  #### Parameters

  - loginData: AccountLoginRequest

    The `AccountLoginRequest` to send

  #### Returns Promise<null | string>

  An error message if something went wrong

  - Defined in src/plugins/api/pokerogue-account-api.ts:63

### logout

- logout(): Promise<void>

  Send a logout request. Always (no matter if failed or not) removes the session cookie.

  #### Returns Promise<void>

  - Defined in src/plugins/api/pokerogue-account-api.ts:85

### register

- register(registerData: AccountRegisterRequest ): Promise<null | string>

  Register a new account.

  #### Parameters

  - registerData: AccountRegisterRequest

    The `AccountRegisterRequest` to send

  #### Returns Promise<null | string>

  An error message if something went wrong

  - Defined in src/plugins/api/pokerogue-account-api.ts:42

### `Protected` toUrlSearchParams

- toUrlSearchParams< D extends Record<string, any>>(data: D ): URLSearchParams

  Helper to transform data to URLSearchParams Any key with a value of `undefined` will be ignored. Any key with a value of `null` will be included.

  #### Type Parameters

  - D extends Record<string, any>

  #### Parameters

  - data: D

    the data to transform to URLSearchParams

  #### Returns URLSearchParams

  a URLSearchParams representaton of data

  Inherited from ApiBase.toUrlSearchParams

  - Defined in src/plugins/api/api-base.ts:86