Skip to content

Commit

Permalink
v2.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mo9a7i committed Oct 14, 2023
1 parent c7bb4ba commit e9e384a
Show file tree
Hide file tree
Showing 12 changed files with 261 additions and 513 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# swarmapp-api

## 2.12.0

### Minor Changes

- fix: add friends

## 2.11.3

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@flowdegree/swarmapp-api",
"version": "2.11.3",
"version": "2.12.0",
"description": "A javascript wrapper for swarmapp (foursquare) API",
"main": "dist/index.js",
"types": "./dist/index.d.ts",
Expand All @@ -10,7 +10,7 @@
"clean": "shx rm -rf lib && shx rm -rf dist",
"lint": "tsc",
"build": "pnpm run clean && tsup src/index.ts --format cjs,esm --dts",
"test:example": "ts-node examples/example.ts"
"test:example": "ts-node test/example.ts"
},
"publishConfig": {
"access": "public"
Expand Down
11 changes: 11 additions & 0 deletions src/api/checkins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,15 @@ export async function getRecent(this:any, limit: number = 100, ll?: string) {
this.error(error)
return;
}
}

export async function likeCheckin(this:any, checkin_id: string) {
try {
const result = await axios.post(this.basePath + 'checkins/' + checkin_id + '/like', querystring.stringify(this.config));
return result;
}
catch (error: any) {
this.error(error.response.data)
return;
}
}
3 changes: 2 additions & 1 deletion src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export * from './main';
export * from './users';
export * from './checkins';
export * from './venues';
export * from './authentication'
export * from './authentication'
export * from './private'
70 changes: 70 additions & 0 deletions src/api/private.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import axios from 'axios';
import querystring from 'querystring';

export async function private_log(this:any) {
const FormData = require('form-data');

const formData = new FormData();
formData.append('altAcc', this.config.altAcc);
formData.append('llAcc', this.config.llAcc);
formData.append('floorLevel', this.config.floorLevel);
formData.append('alt', this.config.alt);
formData.append('csid', '1243');
formData.append('v', this.config.v);
formData.append('oauth_token', this.config.oauth_token);
formData.append('m', this.config.m);
formData.append('ll', this.config.ll);
formData.append('background', 'true');

const script = [{ "name": "ios-metrics", "csid": 1243, "ctc": 4, "metrics": [{ "rid": "642a1e4371f95f2eb16b8eda", "n": "SwarmTimelineFeedViewController", "im": "3-3", "vc": 1 }], "event": "background", "cts": 1680481860.378182 }];
const stringified = JSON.stringify(script);

formData.append('loglines', stringified, { filename: 'loglines', contentType: 'application/json' });

try {
const result = await axios.post(this.basePath + 'private/log', formData, {
headers: {
...formData.getHeaders()
}
});
return result;
} catch (error: any) {
console.log(`error occured while private logging`)
this.error(error)
return;
}
}

export async function register_device(this: any) {
const params = {
limitAdsTracking: '1',
carrier: 'stc',
hasWatch: '1',
csid: '1242',
alt: '11.791945',
llAcc: '14.825392',
otherDeviceIds: '6054750ee01fbc1e3492a745,61187d1fceb2110097a0fc02',
ll: '21.530136,39.172863',
altAcc: '17.547791',
locationAuthorizationStatus: 'authorizedwheninuse',
token: 'ec0718c5d042b63587c14d461bb077d1262811456c4799558e1df2616f02cc9a',
oauth_token: 'DW233H4JWJZ0E14QU01LFWUZL4RDQPLAF10BAJEI2FTWNOKH',
iosSettings: '0',
m: 'swarm',
floorLevel: '2146959360',
measurementSystem: 'metric',
uniqueDevice: '6054750ee01fbc1e3492a745',
v: '20221101',
backgroundRefreshStatus: 'available',
}

try {
const result = await axios.post(this.basePath + '/private/registerdevice ', querystring.stringify(params));
const registeration = result.data.response?.checkin;
return registeration;
} catch (error: any) {
console.log(`error occured while registering device`)
this.error(error)
return;
}
}
66 changes: 52 additions & 14 deletions src/api/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export async function getFollowers(this: any, user_id: string = 'self'): Promise
}
}

export async function getUser(this:any, user_id: string = 'self') {
export async function getUser(this: any, user_id: string = 'self') {
try {
const result = await axios.get(`${this.basePath}users/${user_id}`, { 'params': this.config });
return result;
Expand All @@ -58,7 +58,18 @@ export async function getUser(this:any, user_id: string = 'self') {
}
}

export async function getCheckins(this:any, user_id: string = 'self', limit: number = 100, afterTimestamp?: string) {
export async function getUserProfile(this: any, user_id: string = 'self') {
try {
const result = await axios.get(`${this.basePath}users/${user_id}/profile`, { 'params': this.config });
return result;
} catch (error: any) {
console.log(`error occured while getting user`)
this.error(error)
throw new Error("Error getting user data, maybe an authentication error ?");
}
}

export async function getCheckins(this: any, user_id: string = 'self', limit: number = 100, afterTimestamp?: string) {

if (typeof afterTimestamp !== 'undefined') {
this.config.afterTimeStamp = afterTimestamp;
Expand All @@ -76,36 +87,63 @@ export async function getCheckins(this:any, user_id: string = 'self', limit: num
}
}

export async function addFriendByID(this:any, user_id: number): Promise<string | boolean | void> {
export async function addFriendByID(this: any, user_id: number): Promise<any | void> {
try {
const userIdStr = user_id.toString();

const parameters = {
oauth_token: this.config.oauth_token,
v: this.config.v,
}
const result = await this.getUser(userIdStr);
const result = await this.getUserProfile(userIdStr);
const newFriend = result?.data?.response?.user;
//console.log(newFriend);
//process.exit();

// seems like relationship field removed, proceed adding anyway
//if (newFriend?.relationship === 'none') {
if(true) {


if (newFriend?.relationship === 'none') {
const postUrl = `${this.basePath}users/${userIdStr}/request`;
console.log(`Adding friend by id ${newFriend.handle}...`)
//console.log(querystring.stringify(this.config));

// add querystring params to the url
const result = await axios.post(`${postUrl}?${querystring.stringify(parameters)}`);
return result.data.response.user;
}

return false;
else{
return false;
}
}
catch (error: any) {
// skip the error as a workaround
console.log(`error occured while adding friend by id ${user_id}`)
//console.log(error.response);
//this.error(error);
return;
return false;
}
}

// TODO: should get user, then get checkins and location of last check-in

export async function getLastSeen(this: any, user_id: string = 'self', limit: number = 100) {
this.config.user_id = user_id;
this.config.limit = limit;

try {
return getUser(user_id);
} catch (error: any) {
console.log(`error occured while getting last seen`)
this.error(error)
}
}

export async function getGeos(this: any, user_id: string = 'self') {
this.config.user_id = user_id;

delete this.config.afterTimeStamp;

try {
const response = await axios.get(this.basePath + '/users/' + user_id + '/map', { 'params': this.config });
return response.data.response;
} catch (error: any) {
console.log(`error occured while getting geos`)
this.error(error)
}
}
Loading

0 comments on commit e9e384a

Please sign in to comment.