001/*
002 * Copyright (c) 2010-2024 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
024/**
025 * Interface for accessing the Facebook Endpoints.
026 * <p>
027 * Facebook provides several endpoints that are used for working with the Graph API and working with Facebook in
028 * general. This interface provides methods to access the different urls.
029 * <p>
030 * The default implementation is {@link FacebookEndpoints}. That class provides the access to Facebook and should be
031 * used in productive environments.
032 * <p>
033 * This interface provides some fields with the default URLs so custom implementation can directly use these or modify
034 * the url or provide a completely custom one. This is possible without extending our default implementation.
035 * <p>
036 * In tests, a custom implementation can be used to mock the Facebook service. The implementing class only needs to
037 * provide urls to the mock service and the custom class is set in the {@link DefaultFacebookClient}.
038 */
039public interface FacebookEndpoints {
040
041  /**
042   * returns the Facebook URL
043   * 
044   * @return the Facebook URL
045   */
046  default String getFacebookEndpoint() {
047    return Endpoint.SERVER.getUrl();
048  }
049
050  /**
051   * returns the Facebook Graph API endpoint URL
052   * 
053   * @return the Facebook Graph API endpoint URL
054   */
055  default String getGraphEndpoint() {
056    return Endpoint.GRAPH.getUrl();
057  }
058
059  /**
060   * returns the Facebook Graph API Video endpoint URL
061   * 
062   * @return the Facebook Graph API Video endpoint URL
063   */
064  default String getGraphVideoEndpoint() {
065    return Endpoint.GRAPH_VIDEO.getUrl();
066  }
067
068  /**
069   * returns the Facebook Reel Upload endpoint URL
070   *
071   * @return the Facebook Reel Upload endpoint URL
072   */
073  default String getReelUploadEndpoint() {
074    return Endpoint.RUPLOAD.getUrl();
075  }
076
077  default String getInstagramEndpoint() {
078    return Endpoint.INSTAGRAM_GRAPH.getUrl();
079  }
080
081  default String getInstagramApiEndpoint() {
082    return Endpoint.INSTAGRAM_API.getUrl();
083  }
084
085  default String getInstagramOAuthEndpoint() {
086    return Endpoint.INSTAGRAM_OAUTH.getUrl();
087  }
088
089  default String getThreadsBaseEndpoint() {
090    return Endpoint.THREADS_OAUTH.getUrl();
091  }
092
093  default String getThreadsApiEndpoint() {
094    return Endpoint.THREADS_GRAPH.getUrl();
095  }
096
097  enum Endpoint {
098    /**
099     * General Facebook endpoint URL.
100     */
101    SERVER("https://www.facebook.com"),
102
103    /**
104     * Graph API endpoint URL.
105     */
106    GRAPH("https://graph.facebook.com"),
107
108    /**
109     * Video Upload API endpoint URL.
110     */
111    GRAPH_VIDEO("https://graph-video.facebook.com"),
112
113    /**
114     * Reels Upload endpont URL.
115     */
116    RUPLOAD("https://rupload.facebook.com/video-upload"),
117
118    /**
119     * Instagram Graph API endpoint URL.
120     */
121    INSTAGRAM_GRAPH("https://graph.instagram.com"),
122
123    /**
124     * Instagram API endpoint URL.
125     */
126    INSTAGRAM_API("https://api.instagram.com"),
127
128    /**
129     * Instagram website URL.
130     */
131    INSTAGRAM_OAUTH("https://www.instagram.com"),
132
133    /**
134     * Threads OAuth endpoint URL.
135     */
136    THREADS_OAUTH("https://www.threads.net"),
137
138    /**
139     * Threads Graph API endpoint URL.
140     */
141    THREADS_GRAPH("https://graph.threads.net");
142
143    private final String url;
144
145    Endpoint(String url) {
146      this.url = url;
147    }
148
149    public String getUrl() {
150      return url;
151    }
152  }
153}