Skip to content

Commit

Permalink
refactor: cg constructor w dep inyection
Browse files Browse the repository at this point in the history
  • Loading branch information
0xjjojo committed May 24, 2024
1 parent 8308e08 commit cdc21b4
Showing 1 changed file with 9 additions and 25 deletions.
34 changes: 9 additions & 25 deletions packages/lib/coingecko/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,17 @@ import axios from "axios";

export default class CoingeckoService {
private instance: AxiosInstance;
private baseURL: string;
private apiKey: string;

constructor() {
const baseURL = process.env.COINGECKO_API_URL;
const apiKey = process.env.COINGECKO_API_KEY;

if (!baseURL) {
throw new Error("Missing Coingecko baseUrl");
}

if (!apiKey) {
throw new Error("Missing coingecko api key");
}

this.apiKey = apiKey;
this.baseURL = baseURL;

constructor(private url: string, private apiKey:string){
const config: CreateAxiosDefaults = {
baseURL: this.baseURL,
headers: {
"x-cg-demo-api-key": this.apiKey,
},
};

this.instance = axios.create(config);
}
baseURL: url,
headers: {
"x-cg-demo-api-key": this.apiKey,
},
};
this.instance = axios.create(config);
}

get(): AxiosInstance {
if (!this.instance) {
Expand Down

0 comments on commit cdc21b4

Please sign in to comment.