Skip to content

Commit e9e384a

Browse files
committed
v2.12.0
1 parent c7bb4ba commit e9e384a

File tree

12 files changed

+261
-513
lines changed

12 files changed

+261
-513
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# swarmapp-api
22

3+
## 2.12.0
4+
5+
### Minor Changes
6+
7+
- fix: add friends
8+
39
## 2.11.3
410

511
### Patch Changes

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@flowdegree/swarmapp-api",
3-
"version": "2.11.3",
3+
"version": "2.12.0",
44
"description": "A javascript wrapper for swarmapp (foursquare) API",
55
"main": "dist/index.js",
66
"types": "./dist/index.d.ts",
@@ -10,7 +10,7 @@
1010
"clean": "shx rm -rf lib && shx rm -rf dist",
1111
"lint": "tsc",
1212
"build": "pnpm run clean && tsup src/index.ts --format cjs,esm --dts",
13-
"test:example": "ts-node examples/example.ts"
13+
"test:example": "ts-node test/example.ts"
1414
},
1515
"publishConfig": {
1616
"access": "public"

src/api/checkins.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,15 @@ export async function getRecent(this:any, limit: number = 100, ll?: string) {
4848
this.error(error)
4949
return;
5050
}
51+
}
52+
53+
export async function likeCheckin(this:any, checkin_id: string) {
54+
try {
55+
const result = await axios.post(this.basePath + 'checkins/' + checkin_id + '/like', querystring.stringify(this.config));
56+
return result;
57+
}
58+
catch (error: any) {
59+
this.error(error.response.data)
60+
return;
61+
}
5162
}

src/api/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ export * from './main';
22
export * from './users';
33
export * from './checkins';
44
export * from './venues';
5-
export * from './authentication'
5+
export * from './authentication'
6+
export * from './private'

src/api/private.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import axios from 'axios';
2+
import querystring from 'querystring';
3+
4+
export async function private_log(this:any) {
5+
const FormData = require('form-data');
6+
7+
const formData = new FormData();
8+
formData.append('altAcc', this.config.altAcc);
9+
formData.append('llAcc', this.config.llAcc);
10+
formData.append('floorLevel', this.config.floorLevel);
11+
formData.append('alt', this.config.alt);
12+
formData.append('csid', '1243');
13+
formData.append('v', this.config.v);
14+
formData.append('oauth_token', this.config.oauth_token);
15+
formData.append('m', this.config.m);
16+
formData.append('ll', this.config.ll);
17+
formData.append('background', 'true');
18+
19+
const script = [{ "name": "ios-metrics", "csid": 1243, "ctc": 4, "metrics": [{ "rid": "642a1e4371f95f2eb16b8eda", "n": "SwarmTimelineFeedViewController", "im": "3-3", "vc": 1 }], "event": "background", "cts": 1680481860.378182 }];
20+
const stringified = JSON.stringify(script);
21+
22+
formData.append('loglines', stringified, { filename: 'loglines', contentType: 'application/json' });
23+
24+
try {
25+
const result = await axios.post(this.basePath + 'private/log', formData, {
26+
headers: {
27+
...formData.getHeaders()
28+
}
29+
});
30+
return result;
31+
} catch (error: any) {
32+
console.log(`error occured while private logging`)
33+
this.error(error)
34+
return;
35+
}
36+
}
37+
38+
export async function register_device(this: any) {
39+
const params = {
40+
limitAdsTracking: '1',
41+
carrier: 'stc',
42+
hasWatch: '1',
43+
csid: '1242',
44+
alt: '11.791945',
45+
llAcc: '14.825392',
46+
otherDeviceIds: '6054750ee01fbc1e3492a745,61187d1fceb2110097a0fc02',
47+
ll: '21.530136,39.172863',
48+
altAcc: '17.547791',
49+
locationAuthorizationStatus: 'authorizedwheninuse',
50+
token: 'ec0718c5d042b63587c14d461bb077d1262811456c4799558e1df2616f02cc9a',
51+
oauth_token: 'DW233H4JWJZ0E14QU01LFWUZL4RDQPLAF10BAJEI2FTWNOKH',
52+
iosSettings: '0',
53+
m: 'swarm',
54+
floorLevel: '2146959360',
55+
measurementSystem: 'metric',
56+
uniqueDevice: '6054750ee01fbc1e3492a745',
57+
v: '20221101',
58+
backgroundRefreshStatus: 'available',
59+
}
60+
61+
try {
62+
const result = await axios.post(this.basePath + '/private/registerdevice ', querystring.stringify(params));
63+
const registeration = result.data.response?.checkin;
64+
return registeration;
65+
} catch (error: any) {
66+
console.log(`error occured while registering device`)
67+
this.error(error)
68+
return;
69+
}
70+
}

src/api/users.ts

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export async function getFollowers(this: any, user_id: string = 'self'): Promise
4646
}
4747
}
4848

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

61-
export async function getCheckins(this:any, user_id: string = 'self', limit: number = 100, afterTimestamp?: string) {
61+
export async function getUserProfile(this: any, user_id: string = 'self') {
62+
try {
63+
const result = await axios.get(`${this.basePath}users/${user_id}/profile`, { 'params': this.config });
64+
return result;
65+
} catch (error: any) {
66+
console.log(`error occured while getting user`)
67+
this.error(error)
68+
throw new Error("Error getting user data, maybe an authentication error ?");
69+
}
70+
}
71+
72+
export async function getCheckins(this: any, user_id: string = 'self', limit: number = 100, afterTimestamp?: string) {
6273

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

79-
export async function addFriendByID(this:any, user_id: number): Promise<string | boolean | void> {
90+
export async function addFriendByID(this: any, user_id: number): Promise<any | void> {
8091
try {
8192
const userIdStr = user_id.toString();
93+
8294
const parameters = {
8395
oauth_token: this.config.oauth_token,
8496
v: this.config.v,
8597
}
86-
const result = await this.getUser(userIdStr);
98+
const result = await this.getUserProfile(userIdStr);
8799
const newFriend = result?.data?.response?.user;
88-
//console.log(newFriend);
89-
//process.exit();
90-
91-
// seems like relationship field removed, proceed adding anyway
92-
//if (newFriend?.relationship === 'none') {
93-
if(true) {
100+
101+
102+
if (newFriend?.relationship === 'none') {
94103
const postUrl = `${this.basePath}users/${userIdStr}/request`;
95104
console.log(`Adding friend by id ${newFriend.handle}...`)
96-
//console.log(querystring.stringify(this.config));
105+
97106
// add querystring params to the url
98107
const result = await axios.post(`${postUrl}?${querystring.stringify(parameters)}`);
99108
return result.data.response.user;
100109
}
101-
102-
return false;
110+
else{
111+
return false;
112+
}
103113
}
104114
catch (error: any) {
105115
// skip the error as a workaround
106116
console.log(`error occured while adding friend by id ${user_id}`)
107117
//console.log(error.response);
108118
//this.error(error);
109-
return;
119+
return false;
120+
}
121+
}
122+
123+
// TODO: should get user, then get checkins and location of last check-in
124+
125+
export async function getLastSeen(this: any, user_id: string = 'self', limit: number = 100) {
126+
this.config.user_id = user_id;
127+
this.config.limit = limit;
128+
129+
try {
130+
return getUser(user_id);
131+
} catch (error: any) {
132+
console.log(`error occured while getting last seen`)
133+
this.error(error)
134+
}
135+
}
136+
137+
export async function getGeos(this: any, user_id: string = 'self') {
138+
this.config.user_id = user_id;
139+
140+
delete this.config.afterTimeStamp;
141+
142+
try {
143+
const response = await axios.get(this.basePath + '/users/' + user_id + '/map', { 'params': this.config });
144+
return response.data.response;
145+
} catch (error: any) {
146+
console.log(`error occured while getting geos`)
147+
this.error(error)
110148
}
111149
}

0 commit comments

Comments
 (0)