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

[Question] Considering making a PR for exposing pagination #45

Open
balthatrix opened this issue Nov 4, 2021 · 0 comments
Open

[Question] Considering making a PR for exposing pagination #45

balthatrix opened this issue Nov 4, 2021 · 0 comments

Comments

@balthatrix
Copy link

balthatrix commented Nov 4, 2021

Hi there! First off, really appreciate this project. It's shaved days off my timelines.

I'm considering doing a PR against this project for exposing pagination in an easier way. I extended the oktakit client quick and dirty like this for my project, and thought it might be a nice method for this gem (I skimmed open PRs and issues and didn't see anything already in the pipes).

I'd want to clean this up more, but wanted to ask here first to see if some better approach already exists, or if you think this would help:

class OktaClient < Oktakit::Client

 # This is copied from https://github.com/Shopify/oktakit/blob/master/lib/oktakit/client.rb#L65, but this just fetches a single page, instead of recursing to fetch every page
  def alt_get(url, options = {})
    should_paginate = options.delete(:paginate)
    request_options = {
      query: options.delete(:query),
      headers: options.delete(:headers),
      accept: options.delete(:accept),
      content_type: options.delete(:content_type),
      paginate: should_paginate,
      data: options
    }

    resp, status, next_page = request(:get, url, **request_options)

    [resp, status, next_page]
  end

  def get_each_page(url, options = {})
    next_page = url
    while next_page
      resp, status, next_page = alt_get(next_page, options.merge(paginate: true))
      raise RequestError, "Error fetching okta #{url}, status=#{status}, response=#{resp}" unless status == 200

      yield(resp, status, next_page)
    end
  end

end

I'm just trying to help though! I'm happy to just keep my extension, so feel free to ignore and close with or without comment :)

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

1 participant