001/*
002 * Copyright 2010-2014 Ning, Inc.
003 * Copyright 2014-2015 The Billing Project, LLC
004 *
005 * The Billing Project licenses this file to you under the Apache License, version 2.0
006 * (the "License"); you may not use this file except in compliance with the
007 * License.  You may obtain a copy of the License at:
008 *
009 *    http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
013 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
014 * License for the specific language governing permissions and limitations
015 * under the License.
016 */
017
018package com.ning.billing.recurly;
019
020import java.util.regex.Matcher;
021import java.util.regex.Pattern;
022
023public abstract class PaginationUtils {
024
025    public static String[] getLinks(final String linkHeader) {
026        String start = null;
027        String next = null;
028
029        final Pattern pattern = Pattern.compile("\\<([^>]+)\\>; rel=\\\"([^\"]+)\\\"");
030        final Matcher matcher = pattern.matcher(linkHeader);
031        while (matcher.find()) {
032            if ("start".equals(matcher.group(2))) {
033                start = matcher.group(1);
034            } else if ("next".equals(matcher.group(2))) {
035                next = matcher.group(1);
036            }
037        }
038
039        return new String[]{start, next};
040    }
041}