Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Looping through all rapidpro contacts #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ashaban
Copy link
Collaborator

@ashaban ashaban commented Oct 11, 2016

No description provided.


rapidpro.getContacts(groupUUID, getContactsCallback([]))

let url = rapidpro.contactsURL(groupUUID)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contactsURL is not a public function so you can't use it like this. Is there a reason you need to do it like this rather than how it was before?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to add in paging parameters?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes,because i will now be looping through the getContacts(),so i just want it to accept a url other than groupUUID

@@ -53,10 +53,9 @@ module.exports = function (config) {
})
}

const getContacts = function (groupUUID, callback) {
let url = contactsURL(groupUUID)
const getContacts = function (url, callback) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think rather than passing in a URL here we should rather keep it how it was before and rather add the paging parameters as a parameter to this call. We could make the parameter optional by doing something like this:

const getContacts = function (url, page, callback) {
  if (typeof page === 'function') {
    callback = page
    page = null
  }

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

let before = new Date()

let options = {
url: url,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should then add the query parameter for pagination to the url here.

let next = JSON.parse(body).next
if(next) {
winston.error(next)
getContacts(next)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This recursive call will then just pass the correct page parameter.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so we dont pass the call back function on this call?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants