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

Implement Pager#take #562

Merged
merged 4 commits into from
Nov 12, 2020
Merged

Implement Pager#take #562

merged 4 commits into from
Nov 12, 2020

Conversation

joannasese
Copy link
Contributor

$params = [
    "order" => "desc",
];
$accounts = Recurly_AccountList::take(2, $params);

@joannasese joannasese added the V2 V2 Client label Oct 23, 2020
@joannasese joannasese marked this pull request as ready for review October 23, 2020 23:50
@joannasese joannasese marked this pull request as draft October 26, 2020 14:10
Copy link
Contributor Author

@joannasese joannasese left a comment

Choose a reason for hiding this comment

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

Alternatively, we can place take() in the Pager class and do something like below, but not sure it's better:

  public function take($n, $client = null) {
    $uri = $this->_href;
    $parsed_uri = parse_url($uri);
    // if $uri contains params
    if (isset($parsed_uri["query"])) {
      parse_str($parsed_uri['query'], $params);
      // if uri contains per_page param, replace with per_page=$n
      if (isset($params["per_page"])) {
        $pattern = '/per_page=\b([1-9]|[1-9][0-9]|1[0-9][0-9]|200)\b/';
        $replacement = 'per_page=' . $n;
        $uri = preg_replace($pattern, $replacement, $uri);
      // otherwise, append the per_page param
      } else {
        $uri = $uri . '&per_page=' . $n;
      }
    } else {
      $uri = $uri . '?per_page=' . $n;
    }
    $pager =$this->_get($uri, $client);
    return $pager->get_first_page();
  }

@joannasese joannasese marked this pull request as ready for review October 26, 2020 15:50
Copy link
Contributor

@douglasmiller douglasmiller left a comment

Choose a reason for hiding this comment

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

👍

@douglasmiller douglasmiller merged commit a47f6dc into v2 Nov 12, 2020
@joannasese joannasese deleted the dx-1915-take-method-on-pager branch November 12, 2020 22:18
@joannasese joannasese mentioned this pull request Nov 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
V2 V2 Client
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants