|
| 1 | +<a name="module_services.api"></a> |
| 2 | + |
| 3 | +## services.api |
| 4 | +This module provides a service for conventient access to Topcoder APIs. |
| 5 | + |
| 6 | + |
| 7 | +* [services.api](#module_services.api) |
| 8 | + * _static_ |
| 9 | + * [.default](#module_services.api.default) |
| 10 | + * [.getApiV2(token)](#module_services.api.getApiV2) ⇒ <code>Api</code> |
| 11 | + * [.getApiV3(token)](#module_services.api.getApiV3) ⇒ <code>Api</code> |
| 12 | + * _inner_ |
| 13 | + * [~Api](#module_services.api..Api) |
| 14 | + * [new Api(base, token)](#new_module_services.api..Api_new) |
| 15 | + * [.fetch(enpoint, options)](#module_services.api..Api+fetch) ⇒ <code>Promise</code> |
| 16 | + * [.delete(endpoint, body)](#module_services.api..Api+delete) ⇒ <code>Promise</code> |
| 17 | + * [.get(endpoint)](#module_services.api..Api+get) ⇒ <code>Promise</code> |
| 18 | + * [.post(endpoint, body)](#module_services.api..Api+post) ⇒ <code>Promise</code> |
| 19 | + * [.postJson(endpoint, json)](#module_services.api..Api+postJson) ⇒ <code>Promise</code> |
| 20 | + * [.put(endpoint, body)](#module_services.api..Api+put) ⇒ <code>Promise</code> |
| 21 | + * [.putJson(endpoint, json)](#module_services.api..Api+putJson) ⇒ <code>Promise</code> |
| 22 | + * [.upload(endpoint, body, callback)](#module_services.api..Api+upload) ⇒ <code>Promise</code> |
| 23 | + |
| 24 | +<a name="module_services.api.default"></a> |
| 25 | + |
| 26 | +### services.api.default |
| 27 | +The default export from the module is |
| 28 | + [Api](#module_services.api..Api) class. |
| 29 | + |
| 30 | +**Kind**: static property of [<code>services.api</code>](#module_services.api) |
| 31 | +<a name="module_services.api.getApiV2"></a> |
| 32 | + |
| 33 | +### services.api.getApiV2(token) ⇒ <code>Api</code> |
| 34 | +Returns a new or existing Api object for Topcoder API v2. |
| 35 | + |
| 36 | +**Kind**: static method of [<code>services.api</code>](#module_services.api) |
| 37 | +**Returns**: <code>Api</code> - API v2 service object. |
| 38 | + |
| 39 | +| Param | Type | Description | |
| 40 | +| --- | --- | --- | |
| 41 | +| token | <code>String</code> | Optional. Auth token for Topcoder API v2. | |
| 42 | + |
| 43 | +<a name="module_services.api.getApiV3"></a> |
| 44 | + |
| 45 | +### services.api.getApiV3(token) ⇒ <code>Api</code> |
| 46 | +Returns a new or existing Api object for Topcoder API v3 |
| 47 | + |
| 48 | +**Kind**: static method of [<code>services.api</code>](#module_services.api) |
| 49 | +**Returns**: <code>Api</code> - API v3 service object. |
| 50 | + |
| 51 | +| Param | Type | Description | |
| 52 | +| --- | --- | --- | |
| 53 | +| token | <code>String</code> | Optional. Auth token for Topcoder API v3. | |
| 54 | + |
| 55 | +<a name="module_services.api..Api"></a> |
| 56 | + |
| 57 | +### services.api~Api |
| 58 | +API service object. It is reused for both Topcoder API v2 and v3, |
| 59 | +as in these cases we are fine with the same interface, and the only |
| 60 | +thing we need to be different is the base URL and auth token to use. |
| 61 | + |
| 62 | +**Kind**: inner class of [<code>services.api</code>](#module_services.api) |
| 63 | + |
| 64 | +* [~Api](#module_services.api..Api) |
| 65 | + * [new Api(base, token)](#new_module_services.api..Api_new) |
| 66 | + * [.fetch(enpoint, options)](#module_services.api..Api+fetch) ⇒ <code>Promise</code> |
| 67 | + * [.delete(endpoint, body)](#module_services.api..Api+delete) ⇒ <code>Promise</code> |
| 68 | + * [.get(endpoint)](#module_services.api..Api+get) ⇒ <code>Promise</code> |
| 69 | + * [.post(endpoint, body)](#module_services.api..Api+post) ⇒ <code>Promise</code> |
| 70 | + * [.postJson(endpoint, json)](#module_services.api..Api+postJson) ⇒ <code>Promise</code> |
| 71 | + * [.put(endpoint, body)](#module_services.api..Api+put) ⇒ <code>Promise</code> |
| 72 | + * [.putJson(endpoint, json)](#module_services.api..Api+putJson) ⇒ <code>Promise</code> |
| 73 | + * [.upload(endpoint, body, callback)](#module_services.api..Api+upload) ⇒ <code>Promise</code> |
| 74 | + |
| 75 | +<a name="new_module_services.api..Api_new"></a> |
| 76 | + |
| 77 | +#### new Api(base, token) |
| 78 | +Creates a new Api object. |
| 79 | + |
| 80 | + |
| 81 | +| Param | Type | Description | |
| 82 | +| --- | --- | --- | |
| 83 | +| base | <code>String</code> | Base URL of the API. | |
| 84 | +| token | <code>String</code> | Optional. Authorization token. | |
| 85 | + |
| 86 | +<a name="module_services.api..Api+fetch"></a> |
| 87 | + |
| 88 | +#### api.fetch(enpoint, options) ⇒ <code>Promise</code> |
| 89 | +Sends HTTP request to the specified API endpoint. This method is just |
| 90 | +a convenient wrapper around isomorphic fetch(..): |
| 91 | + |
| 92 | + - If API service has auth token, Authorization header is automatically |
| 93 | + added to the request; |
| 94 | + |
| 95 | + - If no Content-Type header set in options, it is automatically set to |
| 96 | + "application/json". In case you want to avoid it, pass null into |
| 97 | + Content-Type header option. |
| 98 | + |
| 99 | +For additional details see https://github.github.io/fetch/ |
| 100 | + |
| 101 | +**Kind**: instance method of [<code>Api</code>](#module_services.api..Api) |
| 102 | +**Returns**: <code>Promise</code> - It resolves to the HTTP response object. To get the |
| 103 | + actual data you probably want to call .json() method of that object. |
| 104 | + Mind that this promise rejects only on network errors. In case of |
| 105 | + HTTP errors (404, etc.) the promise will be resolved successfully, |
| 106 | + and you should check .status or .ok fields of the response object |
| 107 | + to find out the response status. |
| 108 | + |
| 109 | +| Param | Type | Description | |
| 110 | +| --- | --- | --- | |
| 111 | +| enpoint | <code>String</code> | Should start with slash, like /endpoint. | |
| 112 | +| options | <code>Object</code> | Optional. Fetch options. | |
| 113 | + |
| 114 | +<a name="module_services.api..Api+delete"></a> |
| 115 | + |
| 116 | +#### api.delete(endpoint, body) ⇒ <code>Promise</code> |
| 117 | +Sends DELETE request to the specified endpoint. |
| 118 | + |
| 119 | +**Kind**: instance method of [<code>Api</code>](#module_services.api..Api) |
| 120 | + |
| 121 | +| Param | Type | |
| 122 | +| --- | --- | |
| 123 | +| endpoint | <code>String</code> | |
| 124 | +| body | <code>Blob</code> \| <code>BufferSource</code> \| <code>FormData</code> \| <code>String</code> | |
| 125 | + |
| 126 | +<a name="module_services.api..Api+get"></a> |
| 127 | + |
| 128 | +#### api.get(endpoint) ⇒ <code>Promise</code> |
| 129 | +Sends GET request to the specified endpoint. |
| 130 | + |
| 131 | +**Kind**: instance method of [<code>Api</code>](#module_services.api..Api) |
| 132 | + |
| 133 | +| Param | Type | |
| 134 | +| --- | --- | |
| 135 | +| endpoint | <code>String</code> | |
| 136 | + |
| 137 | +<a name="module_services.api..Api+post"></a> |
| 138 | + |
| 139 | +#### api.post(endpoint, body) ⇒ <code>Promise</code> |
| 140 | +Sends POST request to the specified endpoint. |
| 141 | + |
| 142 | +**Kind**: instance method of [<code>Api</code>](#module_services.api..Api) |
| 143 | + |
| 144 | +| Param | Type | |
| 145 | +| --- | --- | |
| 146 | +| endpoint | <code>String</code> | |
| 147 | +| body | <code>Blob</code> \| <code>BufferSource</code> \| <code>FormData</code> \| <code>String</code> | |
| 148 | + |
| 149 | +<a name="module_services.api..Api+postJson"></a> |
| 150 | + |
| 151 | +#### api.postJson(endpoint, json) ⇒ <code>Promise</code> |
| 152 | +Sends POST request to the specified endpoint, with JSON payload. |
| 153 | + |
| 154 | +**Kind**: instance method of [<code>Api</code>](#module_services.api..Api) |
| 155 | + |
| 156 | +| Param | Type | |
| 157 | +| --- | --- | |
| 158 | +| endpoint | <code>String</code> | |
| 159 | +| json | <code>JSON</code> | |
| 160 | + |
| 161 | +<a name="module_services.api..Api+put"></a> |
| 162 | + |
| 163 | +#### api.put(endpoint, body) ⇒ <code>Promise</code> |
| 164 | +Sends PUT request to the specified endpoint. |
| 165 | + |
| 166 | +**Kind**: instance method of [<code>Api</code>](#module_services.api..Api) |
| 167 | + |
| 168 | +| Param | Type | |
| 169 | +| --- | --- | |
| 170 | +| endpoint | <code>String</code> | |
| 171 | +| body | <code>Blob</code> \| <code>BufferSource</code> \| <code>FormData</code> \| <code>String</code> | |
| 172 | + |
| 173 | +<a name="module_services.api..Api+putJson"></a> |
| 174 | + |
| 175 | +#### api.putJson(endpoint, json) ⇒ <code>Promise</code> |
| 176 | +Sends PUT request to the specified endpoint. |
| 177 | + |
| 178 | +**Kind**: instance method of [<code>Api</code>](#module_services.api..Api) |
| 179 | + |
| 180 | +| Param | Type | |
| 181 | +| --- | --- | |
| 182 | +| endpoint | <code>String</code> | |
| 183 | +| json | <code>JSON</code> | |
| 184 | + |
| 185 | +<a name="module_services.api..Api+upload"></a> |
| 186 | + |
| 187 | +#### api.upload(endpoint, body, callback) ⇒ <code>Promise</code> |
| 188 | +Upload with progress |
| 189 | + |
| 190 | +**Kind**: instance method of [<code>Api</code>](#module_services.api..Api) |
| 191 | + |
| 192 | +| Param | Type | Description | |
| 193 | +| --- | --- | --- | |
| 194 | +| endpoint | <code>String</code> | | |
| 195 | +| body | <code>Object</code> | and headers | |
| 196 | +| callback | <code>function</code> | handler for update progress only works for client side for now | |
| 197 | + |
0 commit comments