{"id":13718411,"url":"https://github.com/devRant-Community/devrant-lite","last_synced_at":"2025-05-07T10:32:05.198Z","repository":{"id":90575809,"uuid":"360233645","full_name":"devRant-Community/devrant-lite","owner":"devRant-Community","description":"Tiny, fully-featured REST client for the unofficial devRant API","archived":true,"fork":false,"pushed_at":"2021-04-22T12:44:25.000Z","size":29,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-09-24T01:04:04.597Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/devRant-Community.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-04-21T16:18:11.000Z","updated_at":"2023-09-19T21:50:56.000Z","dependencies_parsed_at":"2023-03-04T19:15:37.326Z","dependency_job_id":null,"html_url":"https://github.com/devRant-Community/devrant-lite","commit_stats":null,"previous_names":["devrant-community/devrant-lite"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devRant-Community%2Fdevrant-lite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devRant-Community%2Fdevrant-lite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devRant-Community%2Fdevrant-lite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devRant-Community%2Fdevrant-lite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devRant-Community","download_url":"https://codeload.github.com/devRant-Community/devrant-lite/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224585525,"owners_count":17335871,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T01:00:26.584Z","updated_at":"2024-11-14T07:31:15.939Z","avatar_url":"https://github.com/devRant-Community.png","language":"JavaScript","readme":"# devRant Lite\n\nTiny, fully-featured REST client for the [unofficial devRant API](https://devrantapi.docs.apiary.io/).\n\n[![npm](https://img.shields.io/npm/v/devrant-lite.svg)](https://npm.im/devrant-lite) [![Node CI](https://github.com/Skayo/devrant-lite/actions/workflows/nodejs.yml/badge.svg)](https://github.com/Skayo/devrant-lite/actions/workflows/nodejs.yml)\n\n## Features\n\n- Promise driven via Async / Await\n- [Typescript support](https://github.com/Skayo/devrant-lite/blob/main/index.d.ts)\n- Works both in Node and in browsers\n- Under 1kb\n- Minimal dependencies\n- Test suite\n\n## Why another devRant API client?\n\nI have built this library because existing ones [have not been recently maintained](https://github.com/leahlundqvist/RantScript/),\nor don't support all existing endpoints.\n\n## Installation\n\n```sh\nyarn add devrant-lite\n```\nor\n```sh\nnpm install devrant-lite\n```\n\nThen you can include the following at the top of your code:\n\n```javascript\nimport DevRant from 'devrant-lite';\n\nconst client = DevRant.withCredentials('username', 'password');\n\nclient.get(...)\nclient.post(...)\n```\n\n## Usage\n\n### Authentication\n\nYou will need to create an account on [https://devrant.com/](https://devrant.com), if you haven't already.\nOtherwise, you will only have access to some public endpoints, like `devrant/rants`.\n\nThere are three ways of authentication:\n\n1. **No Authentication**:\n   ```javascript\n   const client = new DevRant();\n   \n   const { rants } = await client.get('devrant/rants');\n   ```\n\n2. **With User Credentials**:\n   \u003e I recommend grabbing the auth token with the `.getAuthToken()` method afterwards and using the `.withAuthToken()` method next time.\n   ```javascript\n   const client = DevRant.withCredentials('username', 'password');\n   \n   const { data } = await client.get('users/me/notif-feed', {\n     last_time: 0\n   });\n   ```\n\n3. **With Auth Token**:\n   ```javascript\n   const client = DevRant.withAuthToken({\n     key: '123abcdefghijklmnopqrstuvxyz',\n     id: 12345678,\n     user_id: 12345 \n   });\n   \n   const { data } = await client.get('users/me/notif-feed', {\n     last_time: 0\n   });\n   ```\n\n## Methods\n\n### `new DevRant(options)`\n\nThe constructor accepts an `options` object with the following options:\n\n##### `options.baseUrl`\n\nSets the base url for the api.\nUseful for proxying or testing.\nDefault: `'https://devrant.com/api'`\n\n##### `options.app`\n\nSets the app ID to use.\nThe app id will be sent with every request.\nDefault: `3`\n\n##### `options.plat`\n\nSimilar as the app ID, this sets the platform ID,\nwhich will also be sent with every request.\nDefault: `3`\n\n### `DevRant.withCredentials(username, password, options)`\n\nA helper function which creates a new instance of the `DevRant` class and then sends a request to the `users/auth-token` endpoint to get an auth token.\nWhen the request was successful it sets the auth token with the `setAuthToken(auth_token)` method.\n\n### `DevRant.withAuthToken(auth_token, options)`\n\nA helper function which creates a new instance of the `DevRant` class and then sets the auth token with the `setAuthToken(auth_token)` method.\n\n### `client.get(endpoint, parameters)`\n\nUse the `post` method for actions that get state.\nReturns a Promise resolving to the API response object, or rejecting on error.\nThe response and error objects will also have a **hidden** `headers` property with the HTTP response headers returned by\nthe devRant API.\n\n```javascript\nconst client = DevRant.withCredentials('username', 'password');\n\n// Get todays top rants\nconst { rants } = await client.get(\"devrant/rants\", {\n\tsort:  'top',\n\trange: 'day',\n\tlimit: 20,\n\tskip:  0,\n});\n```\n\n### `client.post(endpoint, parameters)`\n\nSame return as `get()`.\n\nUse the `post` method for actions that change or create state.\nFor example, to post a new rant:\n\n```javascript\nconst client = DevRant.withCredentials('username', 'password');\n\n// Post a rant with text \"Hello World!\"\nawait client.post('devrant/rants', {\n\trant: 'Hello World!',\n\ttags: 'hello, world',\n\ttype: 6\n});\n```\n\n### `client.delete(endpoint, query_parameters)`\n\nSame return as `get()` and `post()`.\n\nUse the `delete()` method for actions that delete state. For example, to delete a rant:\n\n```javascript\nconst client = DevRant.withCredentials('username', 'password');\n\n// Delete rant with ID 12345\nawait client.delete('devrant/rants/12345');\n```\n\n### `client.setAuthToken(auth_token)`\n\nSets the auth token to be used for authentication. An auth token object consists of the `id`, `key` and `user_id` properties.\n\n### `client.getAuthToken()`\n\nReturns the auth token used for authentication.\n\n## Examples\n\nYou can find many more examples for various resources/endpoints in [the tests](test).\n\n## Troubleshooting\n\n### Headers on success\n\n```javascript\nconst response = await client.get('devrant/rants');\nconsole.log(`Content Length: ${response.headers.get('Content-Type')}`);\nconsole.log(response.rants[0]);\n```\n\n### API errors\n\n`.get()`, `.post()` and `.delete()` reject on error, so you can use try/catch to handle errors. The error object contains an `error` property with the error message and the default `success` property,\nwhich is `false`, in this case. The error object will also have a **hidden** `headers` property with the HTTP response headers returned by the devRant API.\n\n```javascript\ntry {\n\tconst response = await client.get(\"some/endpoint\");\n\t// ... use response here ...\n} catch (e) {\n\tif ('success' in e) {\n\t\t// devRant API error\n\t\tconsole.error(e.error);\n\t} else {\n\t\t// non-API error, e.g. network problem or invalid JSON in response\n\t}\n}\n```\n\n## Contributing\n\n1. Fork/clone the repo\n2. Run `yarn/npm install`\n3. Place your credentials in a [.env](https://www.npmjs.com/package/dotenv) file in the project's root directory, under the following variables:\n   ```dotenv\n   DEVRANT_USERNAME=...\n   DEVRANT_PASSWORD=...\n   ```\n4. Run `yarn/npm test` and make sure all tests pass\n5. Make sure all tests pass. **NOTE: tests will take over 10 minutes to finish.**\n6. Commit using a [descriptive message](https://chris.beams.io/posts/git-commit/) (please squash commits into one per fix/improvement!)\n7. Run `git push` and submit your PR!\n\n## Credits\n\nAuthors:\n\n- [@Skayo](https://github.com/Skayo)\n","funding_links":[],"categories":["Uncategorized"],"sub_categories":["Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FdevRant-Community%2Fdevrant-lite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FdevRant-Community%2Fdevrant-lite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FdevRant-Community%2Fdevrant-lite/lists"}