Skip to content
This repository has been archived by the owner on Jan 14, 2020. It is now read-only.

Commit

Permalink
TODO: test implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
dcanon-rb committed Apr 23, 2019
1 parent de029fd commit 096cb8a
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 8 deletions.
7 changes: 5 additions & 2 deletions src/igservice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ export class IGService {
return data.map(e => { return { 'parent': parent, 'child': e.id } });
}

public dataStorage(keyMap: any, data: Array<any>, collectionName: string) {
public dataStorage(keyMap: any = {}, data: Array<any>, collectionName: string) {
return IGService.dataStorage(keyMap, data, collectionName);
}
public static dataStorage(keyMap: any = {}, data: Array<any>, collectionName: string) {
return collection(collectionName)
.then(collection => collection.insertMany(
[...removeKey(data.map(e => Object.assign(e._params, keyMap)), "_session", "account")])
Expand All @@ -65,7 +68,7 @@ export class IGService {
public login() {
return Promise.resolve(IG.Session.create(device, storage, credentials.email, credentials.password))
}
public static login(){
public static login() {
return Promise.resolve(IG.Session.create(device, storage, credentials.email, credentials.password))
}
}
76 changes: 70 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,57 @@ function handleWithDelay<T>(delayProcess: number = 500, dataSet: Array<any>, han
return outData.values
}

// let userMedia = user.search('luna2d').then(tempUser => user.userMedia(tempUser.id))
// userMedia.then(tempMedia => console.log(tempMedia[0]))
// let account = user
// user.account().then((account:any) => user.getAccount(account.id)).then(console.log)
let userMedia = user.search('luna2d').then(tempUser => user.userMedia(tempUser.id))
userMedia.then(tempMedia => tempMedia.forEach((media: any) => IGService.getEventEmiter().emit("media", media)))
let account = user.account().then((account: any) =>
user.getAccount(account.id).then(account => IGService.getEventEmiter().emit("media", account))
)


let followers = user.search("luna2d")
.then((account: any) => user.getUserFollowers(account.id))

followers.then((accounts: Array<any>) =>
accounts.forEach(account => IGService.getEventEmiter().emit("user", account))
)




let fullFollwers = followers
.then((accounts: Array<any>) => handleWithDelay(2000, accounts.map(_ => _.id), user.getAccount))

fullFollwers.then(array => array.forEach(element => {
element.then((account: any) => account._params).then((value: any) => IGService.getEventEmiter().emit("user", value))

}))


// let fullFollwers = followers
// .then((accounts: Array<any>) => Promise.all(accounts.map(account => user.getAccount(account.id))))
// followers.then(_ => console.log(_.length))
// console.log(user.getAccount)

// fullFollwers.then(value => console.log("all has been Processed" + value.length))



let following = user.account()
.then((account: any) => user.getUserFollowing(account.id))

following.then((accounts: Array<any>) =>
accounts.forEach(account => IGService.getEventEmiter().emit("user", account))
)




let fullFollowin = following
.then((accounts: Array<any>) => handleWithDelay(2000, accounts.map(_ => _.id), user.getAccount))

fullFollowin.then(array => array.forEach(element => {
element.then((account: any) => account._params).then((value: any) => IGService.getEventEmiter().emit("user", value))

}))
// let fullFollowin = following
// .then((accounts: Array<any>) => Promise.all(accounts.map(account => user.getAccount(account.id))))

Expand All @@ -47,4 +79,36 @@ let following = user.account()
// let mediaLikers = userMedia.map((_: any) => _.id)
// .then((ids: Array<any>) => Promise.all(ids.map(id => media.getMediaLikersHandler(id))))

// followers.then((dataSet => dataSet.slice(2))).then(console.log)
// followers.then((dataSet => dataSet.slice(2))).then(console.log)






let mediaComments = userMedia.map((_: any) => _.id)
.then((ids: Array<any>) => Promise.all(ids.map(id => media.getMediaCommentsHandler(id))))

let mediaLikers = userMedia.map((_: any) => _.id)
.then((ids: Array<any>) => Promise.all(ids.map(id => media.getMediaLikersHandler(id))))

followers.then((dataSet => dataSet.slice(2))).then(console.log)
let keyMedia = "media"
IGService.getEventEmiter().on(keyMedia, (data:any)=>{
IGService.dataStorage({}, data, keyMedia)
})
let keyUser = "user"
IGService.getEventEmiter().on(keyUser, (data:any)=>{
IGService.dataStorage({}, data, keyUser)

})
let keyFollowing = "following"
IGService.getEventEmiter().on(keyFollowing, (data:any)=>{
IGService.dataStorage({}, data, keyFollowing)

})
let keyFollower = "follower"
IGService.getEventEmiter().on(keyFollowing, (data:any)=>{
IGService.dataStorage({}, data, keyFollower)

})

0 comments on commit 096cb8a

Please sign in to comment.