-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from GuoXiCheng/dev-c
update request-lib
- Loading branch information
Showing
10 changed files
with
68 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,3 @@ | ||
test('example', ()=>{ | ||
expect(1).toBe(1); | ||
}); | ||
// import { TinyCRUD } from "../index"; | ||
// import 'dotenv/config'; | ||
// import axios from "axios"; | ||
// test("index gitee", async ()=>{ | ||
// const tinyCRUD = new TinyCRUD({ | ||
// owner: "guoxicheng", | ||
// repo: "tiny-crud", | ||
// issue_number: "I8H4X2", | ||
// base_url: "https://gitee.com", | ||
// request_lib: "axios", | ||
// access_token: process.env.GITEE_TOKEN as string, | ||
// git_platform: "gitee", | ||
// request_object: axios | ||
// }); | ||
|
||
// const detail = await tinyCRUD.createOne("测试"); | ||
// expect(detail).toHaveProperty("body", "测试"); | ||
// }, 30000); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import 'dotenv/config'; | ||
import { TinyRequestInstance } from '../request-lib'; | ||
import { RequestLib } from '..'; | ||
import axios from 'axios'; | ||
|
||
|
||
test('Test TinyRequestInstance', async () => { | ||
const instance = TinyRequestInstance(RequestLib.axios, axios, process.env.GITEE_TOKEN as string); | ||
const detail = await instance.get(process.env.GITEE_GET_ALL_URL as string); | ||
expect(detail.length).toBeGreaterThan(0); | ||
}, 30000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { AxiosInstance } from "axios"; | ||
import { RequestLib, RequestLibType } from ".."; | ||
import { AxiosRequestFactory, RequestInstance, WxRequestFactory } from "./request-factories"; | ||
import { WxInstance } from "./interfaces"; | ||
|
||
export function TinyRequestInstance(requestLibType: RequestLibType, instance: RequestInstance, accessToken: string) { | ||
switch (requestLibType) { | ||
case RequestLib.axios: | ||
return new AxiosRequestFactory().createRequest(instance as AxiosInstance, accessToken); | ||
case RequestLib.wx: | ||
return new WxRequestFactory().createRequest(instance as WxInstance, accessToken); | ||
default: | ||
throw new Error('invalid request lib type'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,27 @@ | ||
import { WxInstance, TinyRequest } from './interfaces'; | ||
|
||
export class WxRequest implements TinyRequest { | ||
constructor(private wx: WxInstance) { } | ||
constructor(private wx: WxInstance, private accessToken: string) { } | ||
|
||
get(url: string) { | ||
this.wx.request({ | ||
async get(url: string) { | ||
return this.wx.request({ | ||
url, | ||
method: 'GET' | ||
method: 'GET', | ||
header: { | ||
'Authorization': this.accessToken, | ||
'PRIVATE-TOKEN': this.accessToken | ||
} | ||
}); | ||
} | ||
|
||
post(url: string) { | ||
this.wx.request({ | ||
url, | ||
method: 'POST' | ||
method: 'POST', | ||
header: { | ||
'Authorization': this.accessToken, | ||
'PRIVATE-TOKEN': this.accessToken | ||
} | ||
}); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.