001/*
002 * Copyright (c) 2010-2021 Mark Allen, Norbert Bartels.
003 *
004 * Permission is hereby granted, free of charge, to any person obtaining a copy
005 * of this software and associated documentation files (the "Software"), to deal
006 * in the Software without restriction, including without limitation the rights
007 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008 * copies of the Software, and to permit persons to whom the Software is
009 * furnished to do so, subject to the following conditions:
010 *
011 * The above copyright notice and this permission notice shall be included in
012 * all copies or substantial portions of the Software.
013 *
014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
020 * THE SOFTWARE.
021 */
022package com.restfb;
023
024import java.util.stream.Stream;
025
026public enum Version {
027
028  /**
029   * unversiond api
030   */
031  UNVERSIONED(null),
032
033  /**
034   * <tt>Graph API 3.1</tt>, available until October 23, 2020
035   *
036   * @since July 26, 2018
037   * @deprecated use {@link Version#VERSION_4_0} or newer
038   */
039  @Deprecated
040  VERSION_3_1("v3.1"),
041
042  /**
043   * <tt>Graph API 3.2</tt>, available until April 30, 2021
044   *
045   * @since October 23, 2018
046   * @deprecated use {@link Version#VERSION_4_0} or newer
047   */
048  @Deprecated
049  VERSION_3_2("v3.2"),
050
051  /**
052   * <tt>Graph API 3.3</tt>, available until July 29, 2021
053   *
054   * @since April 30, 2019
055   * @deprecated use {@link Version#VERSION_4_0} or newer
056   */
057  @Deprecated
058  VERSION_3_3("v3.3"),
059
060  /**
061   * <tt>Graph API 4.0</tt>, available until October 29, 2021
062   *
063   * @since July 29, 2019
064   */
065  VERSION_4_0("v4.0"),
066
067  /**
068   * <tt>Graph API 5.0</tt>, available until February 3rd, 2022
069   *
070   * @since October 29, 2019
071   */
072  VERSION_5_0("v5.0"),
073
074  /**
075   * <tt>Graph API 6.0</tt>, available until May 5th, 2022
076   *
077   * @since February 3rd, 2020
078   */
079  VERSION_6_0("v6.0"),
080
081  /**
082   * <tt>Graph API 7.0</tt>, available until August 4th, 2022
083   *
084   * @since May 5th, 2020
085   */
086  VERSION_7_0("v7.0"),
087
088  /**
089   * <tt>Graph API 8.0</tt>, available until November 10th, 2022
090   *
091   * @since August 4th, 2020
092   */
093  VERSION_8_0("v8.0"),
094
095  /**
096   * <tt>Graph API 9.0</tt>, available until February 23, 2023
097   *
098   * @since November 10th, 2020
099   */
100  VERSION_9_0("v9.0"),
101
102  /**
103   * <tt>Graph API 10.0</tt>, available until June 8th, 2023
104   *
105   * @since February 23th, 2021
106   */
107  VERSION_10_0("v10.0"),
108
109  /**
110   * <tt>Graph API 11.0</tt>, available at least until September 14, 2023
111   *
112   * @since June 8th, 2021
113   */
114  VERSION_11_0("v11.0"),
115
116  /**
117   * <tt>Graph API 12.0</tt>, available at least until September 2023
118   *
119   * @since September 14th, 2021
120   */
121  VERSION_12_0("v12.0"),
122
123  /**
124   * convenience enum to provide simple access to the latest supported Graph API Version.
125   * <p>
126   * the current version is <tt>Graph API 12.0</tt>
127   * </p>
128   */
129  LATEST("v12.0");
130
131  private final String urlElement;
132
133  Version(String urlElement) {
134    this.urlElement = urlElement;
135  }
136
137  public String getUrlElement() {
138    return this.urlElement;
139  }
140
141  public boolean isUrlElementRequired() {
142    return null != this.urlElement;
143  }
144
145  /**
146   * converts a String (for example the url parameter) into a Version object
147   * 
148   * @param urlElementStr
149   *          String that should
150   * @return the generated version
151   */
152  public static Version getVersionFromString(String urlElementStr) {
153    if (urlElementStr != null) {
154      return Stream.of(Version.values()).filter(v -> urlElementStr.equals(v.getUrlElement())).findFirst()
155              .orElse(UNVERSIONED);
156    }
157
158    return UNVERSIONED;
159  }
160}