-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Stefan Niedermann <[email protected]>
- Loading branch information
1 parent
c0fed8f
commit 75f2489
Showing
4 changed files
with
147 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
sample/src/main/java/com/nextcloud/android/sso/sample/OcsAPI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.nextcloud.android.sso.sample; | ||
|
||
|
||
import com.google.gson.annotations.SerializedName; | ||
|
||
import retrofit2.Call; | ||
import retrofit2.http.GET; | ||
import retrofit2.http.Path; | ||
|
||
|
||
/** | ||
* @see <a href="https://deck.readthedocs.io/en/latest/API-Nextcloud/">Nextcloud REST API</a> | ||
*/ | ||
public interface OcsAPI { | ||
|
||
@GET("capabilities?format=json") | ||
Call<OcsResponse<OcsCapabilities>> getCapabilities(); | ||
|
||
@GET("users/{search}?format=json") | ||
Call<OcsResponse<OcsUser>> getUser(@Path("search") String userId); | ||
|
||
/** | ||
* <p>A generic wrapper for <a href="https://www.open-collaboration-services.org/">OpenCollaborationServices</a> calls.</p> | ||
* <p>This is needed for API endpoints located at <code>/ocs/...</code>. It is usually not used for APIs of 3rd party server apps like <a href="https://deck.readthedocs.io/en/latest/API/">Deck</a> or <a href="https://github.com/nextcloud/notes/blob/master/docs/api/README.md">Notes</a></p> | ||
* | ||
* @param <T> defines the payload of this {@link OcsResponse}. | ||
*/ | ||
class OcsResponse<T> { | ||
public OcsWrapper<T> ocs; | ||
|
||
public static class OcsWrapper<T> { | ||
public OcsMeta meta; | ||
public T data; | ||
} | ||
|
||
public static class OcsMeta { | ||
public String status; | ||
public int statuscode; | ||
public String message; | ||
} | ||
} | ||
|
||
/* | ||
* Extend the classes by the attributes you are actually using, for example:</p> | ||
* <ul> | ||
* <li><code>version</code></li> | ||
* <li><code>theming</code></li> | ||
* <li><code>server_status</code></li> | ||
* <li><code>deck</code></li> | ||
* <li>…</li> | ||
* </ul> | ||
*/ | ||
class OcsCapabilities { | ||
public Theming theming; | ||
|
||
static class Theming { | ||
public String name; | ||
} | ||
} | ||
|
||
/** | ||
* You can map the node names to other variable names using {@link SerializedName}. | ||
* See <a href="https://github.com/google/gson">Gson-</a> and <a href="https://square.github.io/retrofit/">Retrofit-</a>Documentation for all possibilities. | ||
*/ | ||
class OcsUser { | ||
@SerializedName("id") | ||
public String userId; | ||
@SerializedName("displayname") | ||
public String displayName; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters