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

Paginator does not appear to work #48

Open
smoyte opened this issue Jul 17, 2020 · 3 comments
Open

Paginator does not appear to work #48

smoyte opened this issue Jul 17, 2020 · 3 comments

Comments

@smoyte
Copy link

smoyte commented Jul 17, 2020

It just seems to call the same endpoint again, copying the limit param from the first request, but not including the nonce or token params given in the next or prev properties of the returned JSON. Any other optional params to the original request (e.g. arguments to the people search endpoint like updated_since) are also dropped. I ended up having to write my own pagination code. Am I missing something?

@swalberg
Copy link
Contributor

Here's how I did it for tags:

  def nation_builder_tags
    return [] unless nation_builder_linked?

    response = nb.call(:people_tags, :index, limit: TAGS_PER_PAGE)
    paginated = NationBuilder::Paginator.new(nb, response)

    list = []

    loop do
      list += paginated.body['results']
      break unless paginated.next?

      paginated = paginated.next
    end

    list
  end

nb is the NationBuilder::Client object.

@smoyte
Copy link
Author

smoyte commented Jul 20, 2020

I can see how that could work because you don't have any query params other than limit. Try doing this for a people search where you are passing other query params. I don't think it will work.

@swalberg
Copy link
Contributor

Interesting. Do you have a code sample to reproduce this? Looking at the code it relies on what comes back from the API to return the parameters, and a simple test works for me:

irb(main):001:0> c = Campaign.find(4) # Campaign is a Nation
irb(main):003:0> response = c.nb.call(:people, :search, limit: 1, first_name: 'Sean')

irb(main):005:0> p = NationBuilder::Paginator.new(c.nb, response)
irb(main):007:0> p.next?
=> "/api/v1/people/search?__nonce=SOMENONCE&__token=ATOKEN&first_name=Sean&limit=1"
irb(main):009:0> p.body['results'][0]['last_name']
=> "Walberg"
irb(main):010:0> p = p.next
irb(main):011:0> p.body['results'][0]['last_name']
=> "Walberg"
irb(main):012:0> p.body['results'][0]['id']
=> 6
irb(main):013:0> p = p.prev
irb(main):014:0> p.body['results'][0]['id']
=> 90

I don't filter the way you mention, so I'm just going on my observations here.

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

No branches or pull requests

2 participants