From 82072d15bd5bcec1f24f7064042986b55670bfa9 Mon Sep 17 00:00:00 2001 From: Shreyaschorge Date: Tue, 28 Nov 2023 23:15:04 +0530 Subject: [PATCH] Update readme and package.json --- README.md | 26 +++------ docs/getting-started.md | 116 ---------------------------------------- package.json | 4 +- 3 files changed, 8 insertions(+), 138 deletions(-) delete mode 100644 docs/getting-started.md diff --git a/README.md b/README.md index 18d74cc9..421ce7ce 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,13 @@ # @neynar/nodejs-sdk -@neynar/nodejs-sdk typescript-based, easy-to-use SDK built to interact with [Neynar API's](https://docs.neynar.com/). - -## Instantiate Client -Just set the NEYNAR_API_KEY while instantiating a client and you are good to go. - -``` -import { NeynarAPIClient } from "@neynar/nodejs-sdk"; +@neynar/nodejs-sdk typescript-based, easy-to-use SDK built to interact with [Neynar API's](https://docs.neynar.com/). -const neynarClient = new NeynarAPIClient(process.env.NEYNAR_API_KEY); +## Usage -export default neynarClient; -``` +Please refer our [Getting Started Guide](https://docs.neynar.com/reference/getting-started-with-sdk) -## Use Client +Checkout [examples](https://github.com/neynarxyz/farcaster-examples) using this SDK -Errors are propagated, so the user can handle them as they please, so use try/catch or .catch() and handle errors accordingly +## License -``` -try { - const recentCasts = await neynarClient.fetchRecentCasts(); - console.log("Recent Casts", recentCasts); -} catch (error) { - console.log((error as AxiosError).response?.data || (error as Error)); -} -``` +This project is licensed under the MIT License - see the [LICENSE](https://github.com/neynarxyz/nodejs-sdk/blob/main/LICENSE) file for details. diff --git a/docs/getting-started.md b/docs/getting-started.md deleted file mode 100644 index 0c41209a..00000000 --- a/docs/getting-started.md +++ /dev/null @@ -1,116 +0,0 @@ -Checkout the full github repo here: -https://github.com/neynarxyz/nodejs-sdk - -### Installation - -Install [ Nodejs](https://nodejs.org/en/download/package-manager), [yarn](https://classic.yarnpkg.com/lang/en/docs/install/#mac-stable) (Optional, you can also use npm) - -#### Initiallize project - -```bash -mkdir get-started-with-neynar -cd get-started-with-neynar -npm init -y -npm install -g typescript -tsc --init -``` - -#### Install Neynar SDK and other dependencies - -
-Install using npm -

-    npm i @neynar/nodejs-sdk axios
-    npm i -D typescript ts-node
-    
-
- -
- Install using Yarn -

-    yarn add @neynar/nodejs-sdk axios
-    yarn add -D typescript ts-node
-    
-
- -     - -### Example: Let's use sdk to look up a user by their FID - -Create index.ts file at root level - -```bash -touch index.ts -``` - -Add following code in index.ts - -```typescript -// index.ts - -import { NeynarAPIClient, isApiErrorResponse } from "@neynar/nodejs-sdk"; -import { AxiosError } from "axios"; - -// Instantiate the client -const client = new NeynarAPIClient(""); // Replace with your Neynar API Key. - -(async () => { - try { - // here 19960 (Required*) => User we are looking for. - // 191 (Optional) => is viewer looking for the user. - // Get more info @ https://docs.neynar.com/reference/user-v1 - const user = await client.lookupUserByFid(19960, 191); - - // Stringify and log the response - console.log(JSON.stringify(user)); - } catch (error) { - // isApiErrorResponse can be used to check for Neynar API errors - // handle errors accordingly - if (isApiErrorResponse(error)) { - console.log("API Error", error.response.data); - } else { - console.log("Generic Error", error); - } - } -})(); -``` - -Run the project - -```bash -npx ts-node index.ts -``` - -You should see a response like this. (You might not get beautified/ formated response since we `JSON.stringify` the response in order to log everything) - -```json -{ - "result": { - "user": { - "fid": 19960, - "custodyAddress": "0xd1b702203b1b3b641a699997746bd4a12d157909", - "username": "shreyas-chorge", - "displayName": "Shreyas", - "pfp": { - "url": "https://i.imgur.com/LPzRlQl.jpg" - }, - "profile": { - "bio": { - "text": "Everyday regular normal guy | 👨‍💻 @neynar", - "mentionedProfiles": [] - } - }, - "followerCount": 13, - "followingCount": 55, - "verifications": ["0xd1b702203b1b3b641a699997746bd4a12d157909"], - "activeStatus": "inactive", - "viewerContext": { - "following": true, - "followedBy": false - } - } - } -} -``` - -### Congratulation..!! 🎉 You successfully setup @neynar/nodejs-sdk and used it to look up a user by their FID. diff --git a/package.json b/package.json index a177dfb4..cebe2e5f 100644 --- a/package.json +++ b/package.json @@ -10,12 +10,12 @@ "scripts": { "clean": "del-cli ./build/*", "build": "yarn run clean && tsc", - "generate:neynar-oas": "del-cli src/neynar-api/v1/openapi; openapi-generator-cli generate -i src/oas/src/v1/spec.yaml -g typescript-axios -o src/neynar-api/v1/openapi --config src/oas/openapi-generator-config.json", + "generate:neynar-oas-v1-farcaster": "del-cli src/neynar-api/v1/openapi; openapi-generator-cli generate -i src/oas/src/v1/spec.yaml -g typescript-axios -o src/neynar-api/v1/openapi --config src/oas/openapi-generator-config.json", "generate:neynar-oas-v2-farcaster": "del-cli src/neynar-api/v2/openapi-farcaster; openapi-generator-cli generate -i src/oas/src/v2/spec.yaml -g typescript-axios -o src/neynar-api/v2/openapi-farcaster --config src/oas/openapi-generator-config.json", "generate:neynar-oas-v2-recommendation": "del-cli src/neynar-api/v2/openapi-recommendation; openapi-generator-cli generate -i src/oas/src/v2/recommendation/spec.yaml -g typescript-axios -o src/neynar-api/v2/openapi-recommendation --config src/oas/openapi-generator-config.json" }, "author": "Neynar", - "license": "ISC", + "license": "MIT", "devDependencies": { "@types/node": "^20.8.4", "del-cli": "^5.1.0",