@boelensman1/tinderclient
Advanced tools
Comparing version 0.0.6 to 0.0.7
export { TinderClient } from './tinderClient'; | ||
export { Suggestion } from './suggestion'; | ||
export { Photo } from './photo'; | ||
export { HttpClient } from './httpClient'; |
@@ -9,1 +9,3 @@ "use strict"; | ||
exports.Photo = photo_1.Photo; | ||
var httpClient_1 = require("./httpClient"); | ||
exports.HttpClient = httpClient_1.HttpClient; |
@@ -31,5 +31,5 @@ "use strict"; | ||
const options = { baseURL: null, responseType: 'stream' }; | ||
return this.tinderClient.doGetRequest(this.url, false, options); | ||
return this.tinderClient.http.get(this.url, false, options); | ||
} | ||
} | ||
exports.Photo = Photo; |
@@ -47,3 +47,3 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const match = yield this.tinderClient.doGetRequest(`/like/${this.id}`, false); | ||
const match = yield this.tinderClient.http.get(`/like/${this.id}`, false); | ||
return { isMatch: match.match, likesRemaining: match.likes_remaining }; | ||
@@ -57,3 +57,3 @@ }); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const match = yield this.tinderClient.doPostRequest(`/like/${this.id}/super`); | ||
const match = yield this.tinderClient.http.post(`/like/${this.id}/super`); | ||
return { isMatch: match.match, superLikes: match.super_likes }; | ||
@@ -67,3 +67,3 @@ }); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield this.tinderClient.doGetRequest(`/pass/${this.id}`); | ||
yield this.tinderClient.http.get(`/pass/${this.id}`); | ||
return true; | ||
@@ -70,0 +70,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
import { Suggestion } from '../classes'; | ||
import { Suggestion, HttpClient } from '../classes'; | ||
import { UserMetaData } from '../interfaces'; | ||
@@ -8,9 +8,5 @@ /** | ||
/** | ||
* Handle to the axios client | ||
* Handle to the http http | ||
*/ | ||
private client; | ||
/** | ||
* Tinder auth token | ||
*/ | ||
private authToken; | ||
http: HttpClient; | ||
constructor(); | ||
@@ -20,3 +16,3 @@ /** | ||
*/ | ||
auth(facebookToken: string, facebookId: string): Promise<any>; | ||
auth(facebookToken: string, facebookId: string): Promise<true>; | ||
/** | ||
@@ -30,11 +26,3 @@ * get recommendations | ||
getMeta(): Promise<UserMetaData>; | ||
/** | ||
* Do a get request using the axios client | ||
*/ | ||
doGetRequest(url: string, checkStatus?: boolean, options?: object): Promise<any>; | ||
/** | ||
* Do a get request using the axios client | ||
*/ | ||
doPostRequest(url: string, data?: {}, checkStatus?: boolean, options?: object): Promise<any>; | ||
} | ||
export { TinderClient }; |
@@ -11,15 +11,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const axios_1 = require("axios"); | ||
const classes_1 = require("../classes"); | ||
const clientConfig = { | ||
baseURL: 'https://api.gotinder.com', | ||
timeout: 16000, | ||
headers: { | ||
'User-Agent': 'Tinder Android Version 4.5.5', | ||
os_version: '23', | ||
platform: 'android', | ||
'app-version': '854', | ||
'Accept-Language': 'en', | ||
}, | ||
}; | ||
/** | ||
@@ -30,3 +18,3 @@ * The main class containing all the functions | ||
constructor() { | ||
this.client = axios_1.default.create(clientConfig); | ||
this.http = new classes_1.HttpClient(); | ||
} | ||
@@ -38,9 +26,3 @@ /** | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// send an authentication request to tinder | ||
const body = { facebook_token: facebookToken, facebook_id: facebookId }; | ||
const result = yield this.client.post('/auth', body); | ||
this.authToken = result.data.user.api_token; | ||
// add x-auth token to the client settings | ||
this.client = axios_1.default.create(Object.assign({}, clientConfig, { headers: Object.assign({}, clientConfig.headers, { 'X-Auth-Token': this.authToken }) })); | ||
return true; | ||
return yield this.http.auth(facebookToken, facebookId); | ||
}); | ||
@@ -53,3 +35,3 @@ } | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const result = yield this.doGetRequest('/user/recs'); | ||
const result = yield this.http.get('/user/recs'); | ||
return result.results.map((result) => (new classes_1.Suggestion(this, result))); | ||
@@ -63,3 +45,3 @@ }); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const result = yield this.doGetRequest('/meta'); | ||
const result = yield this.http.get('/meta'); | ||
delete result.status; | ||
@@ -69,35 +51,3 @@ return result; | ||
} | ||
/** | ||
* Do a get request using the axios client | ||
*/ | ||
doGetRequest(url, checkStatus = true, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!this.authToken) { | ||
throw new Error('Authenticate first!'); | ||
} | ||
const result = yield this.client.get(url, options); | ||
if (checkStatus && result.data.status !== 200) { | ||
console.log(result); | ||
throw new Error('Error while getting results'); | ||
} | ||
return result.data; | ||
}); | ||
} | ||
/** | ||
* Do a get request using the axios client | ||
*/ | ||
doPostRequest(url, data = {}, checkStatus = true, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!this.authToken) { | ||
throw new Error('Authenticate first!'); | ||
} | ||
const result = yield this.client.post(url, data, options); | ||
if (checkStatus && result.data.status !== 200) { | ||
console.log(result); | ||
throw new Error('Error while getting results'); | ||
} | ||
return result.data; | ||
}); | ||
} | ||
} | ||
exports.TinderClient = TinderClient; |
{ | ||
"name": "@boelensman1/tinderclient", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "Wrapper for the tinder api", | ||
@@ -11,3 +11,3 @@ "main": "lib/index.js", | ||
"test:watch": "jest --watch", | ||
"lint": "tslint './src/**/*.ts' --project tsconfig.json --type-check", | ||
"lint": "tslint './src/**/*.ts' --project tsconfig.json", | ||
"clean": "rimraf lib", | ||
@@ -14,0 +14,0 @@ "prepare": "npm run lint && npm run clean && npm run compile" |
export { TinderClient } from './tinderClient'; | ||
export { Suggestion } from './suggestion'; | ||
export { Photo } from './photo'; | ||
export { HttpClient } from './httpClient'; |
@@ -67,3 +67,3 @@ import { IncomingMessage } from 'http'; | ||
const options = { baseURL: null, responseType: 'stream' }; | ||
return this.tinderClient.doGetRequest(this.url, false, options); | ||
return this.tinderClient.http.get(this.url, false, options); | ||
} | ||
@@ -70,0 +70,0 @@ } |
@@ -137,3 +137,3 @@ import { | ||
public async like(): Promise<{isMatch: boolean; likesRemaining: number}> { | ||
const match = await this.tinderClient.doGetRequest(`/like/${this.id}`, false); | ||
const match = await this.tinderClient.http.get(`/like/${this.id}`, false); | ||
return { isMatch: match.match, likesRemaining: match.likes_remaining }; | ||
@@ -145,4 +145,4 @@ } | ||
*/ | ||
public async superLike(): Promise<{isMatch: boolean; superLikes: SuperLikes}> { | ||
const match = await this.tinderClient.doPostRequest(`/like/${this.id}/super`); | ||
public async superLike(): Promise<{isMatch:boolean; superLikes:SuperLikes}> { | ||
const match = await this.tinderClient.http.post(`/like/${this.id}/super`); | ||
return { isMatch: match.match, superLikes: match.super_likes }; | ||
@@ -155,3 +155,3 @@ } | ||
public async pass(): Promise<true> { | ||
await this.tinderClient.doGetRequest(`/pass/${this.id}`); | ||
await this.tinderClient.http.get(`/pass/${this.id}`); | ||
return true; | ||
@@ -158,0 +158,0 @@ } |
@@ -1,19 +0,4 @@ | ||
import axios from 'axios'; | ||
import { IncomingMessage } from 'http'; | ||
import { Suggestion, Photo } from '../classes'; | ||
import { Suggestion, Photo, HttpClient } from '../classes'; | ||
import { UserMetaData } from '../interfaces'; | ||
const clientConfig = { | ||
baseURL: 'https://api.gotinder.com', | ||
timeout: 16000, | ||
headers: { | ||
'User-Agent': 'Tinder Android Version 4.5.5', | ||
os_version: '23', | ||
platform: 'android', | ||
'app-version': '854', | ||
'Accept-Language': 'en', | ||
}, | ||
}; | ||
/** | ||
@@ -24,12 +9,9 @@ * The main class containing all the functions | ||
/** | ||
* Handle to the axios client | ||
* Handle to the http http | ||
*/ | ||
private client: any; | ||
/** | ||
* Tinder auth token | ||
*/ | ||
private authToken: string; | ||
public http: HttpClient; | ||
constructor() { | ||
this.client = axios.create(clientConfig); | ||
this.http = new HttpClient(); | ||
} | ||
@@ -40,19 +22,4 @@ | ||
*/ | ||
public async auth(facebookToken: string, facebookId: string): Promise<any> { | ||
// send an authentication request to tinder | ||
const body = { facebook_token: facebookToken, facebook_id: facebookId }; | ||
const result = await this.client.post('/auth', body); | ||
this.authToken = result.data.user.api_token; | ||
// add x-auth token to the client settings | ||
this.client = axios.create({ | ||
...clientConfig, | ||
headers: { | ||
...clientConfig.headers, | ||
'X-Auth-Token': this.authToken, | ||
}, | ||
}); | ||
return true; | ||
public async auth(facebookToken: string, facebookId: string): Promise<true> { | ||
return await this.http.auth(facebookToken, facebookId); | ||
} | ||
@@ -64,3 +31,3 @@ | ||
public async getSuggestions(): Promise<Suggestion[]> { | ||
const result = await this.doGetRequest('/user/recs'); | ||
const result = await this.http.get('/user/recs'); | ||
return result.results.map((result) => (new Suggestion(this, result))); | ||
@@ -73,41 +40,8 @@ } | ||
public async getMeta(): Promise<UserMetaData> { | ||
const result = await this.doGetRequest('/meta'); | ||
const result = await this.http.get('/meta'); | ||
delete result.status; | ||
return result; | ||
} | ||
/** | ||
* Do a get request using the axios client | ||
*/ | ||
public async doGetRequest(url: string, checkStatus = true, options?: object): Promise<any> { | ||
if (!this.authToken) { throw new Error('Authenticate first!'); } | ||
const result = await this.client.get(url, options); | ||
if (checkStatus && result.data.status !== 200) { | ||
console.log(result); | ||
throw new Error('Error while getting results'); | ||
} | ||
return result.data; | ||
} | ||
/** | ||
* Do a get request using the axios client | ||
*/ | ||
public async doPostRequest( | ||
url: string, | ||
data = {}, | ||
checkStatus = true, | ||
options?: object, | ||
): Promise<any> { | ||
if (!this.authToken) { throw new Error('Authenticate first!'); } | ||
const result = await this.client.post(url, data, options); | ||
if (checkStatus && result.data.status !== 200) { | ||
console.log(result); | ||
throw new Error('Error while getting results'); | ||
} | ||
return result.data; | ||
} | ||
} | ||
export { TinderClient }; |
@@ -106,3 +106,3 @@ import { User, SuperLikes } from '../interfaces'; | ||
rating: Rating; | ||
travel: { is_traveling: boolean }; // probably some extra props when you are traveling | ||
travel: { is_traveling: boolean }; // prob. some extra props when traveling | ||
purchases: any[]; // TODO: figure out the format of this | ||
@@ -109,0 +109,0 @@ versions: Version[]; |
@@ -8,4 +8,5 @@ { | ||
"jsdoc-format": true, | ||
"max-line-length": [true, 80], | ||
"ter-arrow-parens": [true, "always"] | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
789584
79
16389