Skip to content

Can we get endpoints that list companies? basically to match what the website has #6

@filipef101

Description

@filipef101

Looking to make a third party mobile app, but that is a blocker

I've typed a client in TS for existing endpoints if anyone is curious

type OverallRatingResponse = {
    company_id: string;
    company_name: string;
    rating: string;
    url: string;
    ratingMetric: {
       color: string;
       stars: string;
    }; // Formatted rating metric with stars and color
}

type DetailedRatingResponse = {
    career_opportunity: string;
    company_id: string;
    company_name: string;
    interview_difficulty: string;
    management_quality: string;
    recognition_and_reward: string;
    salary: string;
    url: string;
    work_life_balance: string;
}

type JobReview = {
    company: string;
    company_id: string;
    industry: string;
    rating: string;
    review_title: string;
    size: string;
    tags: { [key: string]: string };
    ts: string;
    url: string;
    views: string;
    votes: string;
    ratingMetric: {
       color: string;
       stars: string;
    }; // Formatted rating metric with stars and color}

type TotalReviewResponse = {
    company_id: string;
    company_name: string;
    company_total_reviews: string;
    url: string;
}

class TeamlyzerApiClient {
    private baseUrl: string;

    constructor(baseUrl: string) {
        this.baseUrl = baseUrl;
    }

    public async getOverallRating(companyId: number): Promise<OverallRatingResponse | { error: string }> {
        const url = `${this.baseUrl}/api/rating/${companyId}`;
        try {
            const response = await this.makeRequest(url);
            if (response.status === 404) {
                return { error: "Company not found" };
            }
            const ratingMetric = this.calculateRatingMetric(response.rating);
            return { ...response, ratingMetric };
        } catch (error) {
            console.error('Request Error:', error);
            return { error: "Request failed" };
        }
    }

    public async getDetailedRating(companyId: number): Promise<DetailedRatingResponse | { error: string }> {
        const url = `${this.baseUrl}/api/detailed-rating/${companyId}`;
        try {
            const response = await this.makeRequest(url);
            if (response.status === 404) {
                return { error: "Company not found" };
            }
            return response;
        } catch (error) {
            console.error('Request Error:', error);
            return { error: "Request failed" };
        }
    }

    public async getTotalJobReviews(page: number, numberOfItems: number): Promise<TotalReviewResponse[] | { error: string }> {
        const url = `${this.baseUrl}/api/total-job-reviews/${page}/${numberOfItems}`;
        try {
            const response = await this.makeRequest(url);
            if (response.status === 404) {
                return { error: "No job reviews found" };
            }
            return response;
        } catch (error) {
            console.error('Request Error:', error);
            return { error: "Request failed" };
        }
    }

    public async getTotalInterviewReviews(page: number, numberOfItems: number): Promise<TotalReviewResponse[] | { error: string }> {
        const url = `${this.baseUrl}/api/total-interview-reviews/${page}/${numberOfItems}`;
        try {
            const response = await this.makeRequest(url);
            if (response.status === 404) {
                return { error: "No interview reviews found" };
            }
            return response;
        } catch (error) {
            console.error('Request Error:', error);
            return { error: "Request failed" };
        }
    }

    public async getJobReviews(companyId: number, page: number, numberOfItems: number): Promise<JobReview[] | { error: string }> {
        const url = `${this.baseUrl}/api/job-reviews/${companyId}/${page}/${numberOfItems}`;
        try {
            const response = await this.makeRequest(url);
            if (response.status === 404) {
                return { error: "No job reviews found" };
            }
            for (let review of response) {
                review.ratingMetric = this.calculateRatingMetric(review.rating);
            }
            return response;
        } catch (error) {
            console.error('Request Error:', error);
            return { error: "Request failed" };
        }
    }

    public async getInterviewReviews(companyId: number, page: number, numberOfItems: number): Promise<JobReview[] | { error: string }> {
        const url = `${this.baseUrl}/api/interview-reviews/${companyId}/${page}/${numberOfItems}`;
        try {
            const response = await this.makeRequest(url);
            if (response.status === 404) {
                return { error: "No interview reviews found" };
            }
            for (let review of response) {
                review.ratingMetric = this.calculateRatingMetric(review.rating);
            }
            return response;
        } catch (error) {
            console.error('Request Error:', error);
            return { error: "Request failed" };
        }
    }

    private calculateRatingMetric(rating: string): string {
        let color = '#FF7800'; // Orange color
        let stars = 'F';
        if (parseFloat(rating) < 2.0) {
            color = '#FFBA00'; // Yellow color
            stars = 'D';
        } else if (parseFloat(rating) < 2.5) {
            color = '#9ACD32'; // Green color
            stars = 'C';
        } else if (parseFloat(rating) < 3.0) {
            color = '#5BA829'; // Light green color
            stars = 'B';
        } else if (parseFloat(rating) < 3.5) {
            color = '#3F7E00'; // Dark green color
            stars = 'A';
        } else if (parseFloat(rating) <= 4.0) {
            color = '#257C00'; // Very dark green color
            stars = 'AA';
        }
        return {color, stars};
    }

    private async makeRequest(url: string): Promise<any> {
        const response = await fetch(url, {
            method: 'GET',
            headers: {
                'Authorization': 'Basic ' + btoa('user:pass')
            }
        });

        if (response.status === 404) {
            return { status: 404, error: "Not found" };
        }

        if (!response.ok) {
            throw new Error('Request failed');
        }

        const data = await response.json();
        return data;
    }
}

// Usage example
const baseUrl = 'https://pt.teamlyzer.com';
const teamlyzerApiClient = new TeamlyzerApiClient(baseUrl);

// Example response for detailed rating
/* {
     "career_opportunity": "75.0",
     "company_id": "67",
     "company_name": "CWI Software",
     "interview_difficulty": "25.0",
     "management_quality": "75.0",
     "recognition_and_reward": "50.0",
     "salary": "25.0",
     "url": "https://br.teamlyzer.com/companies/cwi-software",
     "work_life_balance": "50.0"
   }
*/
teamlyzerApiClient.getDetailedRating(67).then(response => {
    console.log(response);
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions