Skip to content

Commit

Permalink
Refactor board-related functions and interfaces
Browse files Browse the repository at this point in the history
- Renamed `getBoardPin` to `getBoardPins`
- Updated `searchBoards` to use a new search boards parser
- Restructured board-related interfaces for better type definitions
- Updated import and export statements in interfaces index
- Modified board search and parsing logic
  • Loading branch information
rit3zh committed Feb 12, 2025
1 parent 7a37575 commit 61280af
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/functions/getBoardPin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import request from "../fetch/request";
import type { IBoardSectionPinsOptions } from "../interfaces/index";
import parseBoards from "../parser/parser.boards";

export async function getBoardPin<T extends IBoardSectionPinsOptions>(
export async function getBoardPins<T extends IBoardSectionPinsOptions>(
options: T
) {
const {
Expand Down
7 changes: 4 additions & 3 deletions src/functions/searchBoards.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Api } from "../api/api";
import request from "../fetch/request";
import type { BoardResponse } from "../interfaces";
import type { ISearchBoardsResponse } from "../interfaces";
import parseBoards from "../parser/parser.boards";
import searchBoardsParser from "../parser/search.boards.parser";

/**
* Searches for boards based on the given query and optional bookmark.
Expand All @@ -16,7 +17,7 @@ import parseBoards from "../parser/parser.boards";
export async function searchBoards(
query: string,
bookmark?: string
): Promise<BoardResponse> {
): Promise<ISearchBoardsResponse> {
if (!query) throw Error("No query specified");

// Define the request parameters
Expand Down Expand Up @@ -54,5 +55,5 @@ export async function searchBoards(
const data = await request.get(URL);

// Parse the response data and return it
return parseBoards(data);
return searchBoardsParser(data);
}
44 changes: 44 additions & 0 deletions src/interfaces/Board.Data.Pins.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Represents the owner of a Pinterest board.
* This is typically the return type when fetching board owner details.
*/
interface BoardOwner {
/** Unique identifier for the board owner */
id?: string;
/** Username of the board owner on Pinterest */
username?: string;
/** Full name of the board owner */
fullName?: string;
/** URL to the avatar image of the board owner */
avatarURL?: string;
/** Number of followers the board owner has, can be a string or number */
followers?: number | string;
}

/**
* Represents a Pinterest board.
* This is typically the return type when fetching board details.
*/
export interface IBoards {
title?: string;
user?: User;
id?: string;
aggregatedPinId?: string;
image?: string;
video?: string;
description?: string;
}

interface User {
name?: string;
username?: string;
image?: string;
id?: string;
nodeId?: string;
type?: string;
}

export interface IBoardPinsResponse {
bookmark: string;
response: IBoards[];
}
2 changes: 1 addition & 1 deletion src/interfaces/Board.Results.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IBoards } from "./Search.Boards";
import { IBoards } from "./Board.Data.Pins";

/**
* Represents the response data for board search, including optional pagination and board data.
Expand Down
21 changes: 14 additions & 7 deletions src/interfaces/Search.Boards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ export interface BoardOwner {
* Represents a Pinterest board.
* This is typically the return type when fetching board details.
*/
export interface IBoards {
title?: string;
user?: User;
export interface ISearchBoards {
name?: string;
id?: string;
aggregatedPinId?: string;
image?: string;
video?: string;
description?: string;
type?: string;
thumbnailURL?: string;
thumbnailImagesURL?: string[];
coverURL?: string;
slashURL?: string;
pinCount?: number;
user?: User;
}

interface User {
Expand All @@ -37,3 +39,8 @@ interface User {
nodeId?: string;
type?: string;
}

export interface ISearchBoardsResponse {
bookmark: string;
response: ISearchBoards[];
}
2 changes: 2 additions & 0 deletions src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ export type * from "./BoardSection.Options";
export type * from "./Board.Sections";
export type * from "./Board.Section.Pins.Options";
export type * from "./Board.Pins.Result";
export type * from "./Search.Boards";
export type * from "./Board.Data.Pins";
5 changes: 2 additions & 3 deletions src/parser/parser.boards.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { IBoards, SearchResults } from "../interfaces/index";
import type { BoardResponse } from "../interfaces/index";
import type { IBoardPinsResponse } from "../interfaces/index";

export default function parseBoards(data: any): BoardResponse {
export default function parseBoards(data: any): IBoardPinsResponse {
const root = data.resource_response;
const bookmark = root?.bookmark;
const results = root?.data;
Expand Down
43 changes: 43 additions & 0 deletions src/parser/search.boards.parser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import type { ISearchBoardsResponse } from "../interfaces/index";

export default function searchBoardsParser(data: any): ISearchBoardsResponse {
const root = data.resource_response;
const bookmark = root?.bookmark;
const results = root?.data?.results;

const res = results?.map((response: any, index?: number, _?: any) => {
const name = response?.name;
const id = response?.id;
const type = response?.type;
const thumbnailURL = response?.image_thumbnail_url;
const thumbnailImagesURL = response?.pin_thumbnail_urls;
const coverURL = response?.image_cover_hd_url;
const slashURL = response?.url;
const pinCount = response?.pin_count;
const pinner = response?.owner;
const user = {
name: pinner?.full_name,
username: pinner?.username,
image: pinner?.image_large_url,
id: pinner?.id,
nodeId: pinner?.node_id,
type: pinner?.type,
};

return {
name,
id,
type,
thumbnailURL,
thumbnailImagesURL,
coverURL,
slashURL,
pinCount,
user,
};
});
return {
bookmark,
response: res,
};
}

0 comments on commit 61280af

Please sign in to comment.