Skip to content

Commit

Permalink
feat: initial api
Browse files Browse the repository at this point in the history
  • Loading branch information
Complexlity committed Aug 9, 2024
1 parent 464efaa commit e43a72a
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 3 deletions.
54 changes: 51 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,51 @@
export const complexlity = () => {
console.log("Here we gooo!!");
};
import { services, TService, Service } from "./services";


class uniFarcasterSdk {
private hubUrl: string = "DEFAULT_HUB_URL";
private neynarApiKey: string | undefined;
private airstackApiKey: string | undefined;
private activeService: Service = services.hub;

constructor(config: {
hubUrl?: string;
neynarApiKey?: string;
airstackApiKey?: string;
activeService?: TService;
}) {
this.hubUrl = config.hubUrl ?? "DEFAULT_HUB_URL";
this.neynarApiKey = config.neynarApiKey;
this.airstackApiKey = config.airstackApiKey;
this.activeService = this.getActiveService(config.activeService);
}

//TODO: Make more composable
private getActiveService(service?: TService): Service {
if (service === "neynar" && this.neynarApiKey) {
return services.neynar;
} else if (service === "airstack" && this.airstackApiKey) {
return services.airstack;
} else {
return services.hub;
}
}

public getUserByFid(fid: number, viewerFid: number): User {

Check failure on line 33 in src/index.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find name 'User'.

Check failure on line 33 in src/index.ts

View workflow job for this annotation

GitHub Actions / publish

Cannot find name 'User'.
return this.activeService.getUserByFid(fid, viewerFid);
}

public getUserByUsername(username: string, viewerFid: number): User {

Check failure on line 37 in src/index.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find name 'User'.

Check failure on line 37 in src/index.ts

View workflow job for this annotation

GitHub Actions / publish

Cannot find name 'User'.
return this.activeService.getUserByUsername(username, viewerFid);
}

public getCastByHash(hash: string, viewerFid: number): Cast {

Check failure on line 41 in src/index.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find name 'Cast'.

Check failure on line 41 in src/index.ts

View workflow job for this annotation

GitHub Actions / publish

Cannot find name 'Cast'.
return this.activeService.getCastByHash(hash, viewerFid);
}

public getCastByUrl(url: string, viewerFid: number): Cast {

Check failure on line 45 in src/index.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find name 'Cast'.

Check failure on line 45 in src/index.ts

View workflow job for this annotation

GitHub Actions / publish

Cannot find name 'Cast'.
return this.activeService.getCastByUrl(url, viewerFid);
}

}

export default uniFarcasterSdk;
1 change: 1 addition & 0 deletions src/playground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const sdk = new uniFarcasterSdk({
airstackApiKey: "string | undefined",
});


const user: User = sdk.getUserByFid(11244, 213144);
const user2: User = sdk.getUserByUsername("complexlity", 213144);
const cast: Cast = sdk.getCastByHash("0xa0bc828", 213144);
Expand Down
5 changes: 5 additions & 0 deletions src/services/airstack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Service } from ".";

export const airstackService: Service= {
name: "airstack"
}
5 changes: 5 additions & 0 deletions src/services/hub.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Service } from ".";

export const hubService: Service = {
name: "hub"
}
15 changes: 15 additions & 0 deletions src/services/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { neynarService } from "./neynar";
import { airstackService } from "./airstack";
import { hubService } from "./hub";


export const services = {
neynar: neynarService,
airstack: airstackService,
hub: hubService
}

export type Service = {name: string} & any


export type TService = keyof typeof services;
5 changes: 5 additions & 0 deletions src/services/neynar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Service } from ".";

export const neynarService: Service = {
name: "neynar"
}

0 comments on commit e43a72a

Please sign in to comment.