@@ -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