Skip to content

Commit

Permalink
Add support for fetching app resources.
Browse files Browse the repository at this point in the history
  • Loading branch information
arturdryomov committed Jul 19, 2014
1 parent f27c9c2 commit 1538280
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/main/java/org/amahi/anywhere/server/ApiResource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2014 Amahi
*
* This file is part of Amahi.
*
* Amahi is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Amahi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Amahi. If not, see <http ://www.gnu.org/licenses/>.
*/

package org.amahi.anywhere.server;

import java.io.InputStream;

public class ApiResource
{
private static final class Encodings
{
private Encodings() {
}

public static final String UTF_8 = "UTF-8";
}

private final InputStream content;
private final String mime;
private final String encoding;

public ApiResource(InputStream content, String mime) {
this.content = content;
this.mime = mime;
this.encoding = Encodings.UTF_8;
}

public InputStream getContent() {
return content;
}

public String getMime() {
return mime;
}

public String getEncoding() {
return encoding;
}
}
5 changes: 5 additions & 0 deletions src/main/java/org/amahi/anywhere/server/api/ServerApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.List;

import retrofit.Callback;
import retrofit.client.Response;
import retrofit.http.GET;
import retrofit.http.Header;
import retrofit.http.Query;
Expand All @@ -48,4 +49,8 @@ public void getFiles(
public void getApps(
@Header("Session") String session,
Callback<List<ServerApp>> callback);

public Response getAppResource(
@Header("Session") String session,
@Header("Vhost") String host);
}
16 changes: 16 additions & 0 deletions src/main/java/org/amahi/anywhere/server/client/ServerClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@
import org.amahi.anywhere.server.Api;
import org.amahi.anywhere.server.ApiAdapter;
import org.amahi.anywhere.server.ApiConnection;
import org.amahi.anywhere.server.ApiResource;
import org.amahi.anywhere.server.api.ProxyApi;
import org.amahi.anywhere.server.api.ServerApi;
import org.amahi.anywhere.server.model.Server;
import org.amahi.anywhere.server.model.ServerApp;
import org.amahi.anywhere.server.model.ServerFile;
import org.amahi.anywhere.server.model.ServerRoute;
import org.amahi.anywhere.server.model.ServerShare;
Expand All @@ -44,9 +46,13 @@
import org.amahi.anywhere.server.response.ServerSharesResponse;
import org.amahi.anywhere.task.ServerConnectionDetectingTask;

import java.io.IOException;

import javax.inject.Inject;
import javax.inject.Singleton;

import retrofit.client.Response;

@Singleton
public class ServerClient
{
Expand Down Expand Up @@ -189,4 +195,14 @@ public Uri getFileUri(ServerShare share, ServerFile file) {
public void getApps() {
serverApi.getApps(server.getSession(), new ServerAppsResponse());
}

public ApiResource getAppResource(ServerApp app) {
try {
Response appResponse = serverApi.getAppResource(server.getSession(), app.getHost());

return new ApiResource(appResponse.getBody().in(), appResponse.getBody().mimeType());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
10 changes: 10 additions & 0 deletions src/main/java/org/amahi/anywhere/server/model/ServerApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public class ServerApp implements Parcelable
@SerializedName("logo")
private String logoUrl;

@SerializedName("vhost")
private String host;

public String getName() {
return name;
}
Expand All @@ -40,6 +43,10 @@ public String getLogoUrl() {
return logoUrl;
}

public String getHost() {
return host;
}

public static final Creator<ServerApp> CREATOR = new Creator<ServerApp>()
{
@Override
Expand All @@ -56,11 +63,14 @@ public ServerApp[] newArray(int size) {
private ServerApp(Parcel parcel) {
this.name = parcel.readString();
this.logoUrl = parcel.readString();
this.host = parcel.readString();
}

@Override
public void writeToParcel(Parcel parcel, int flags) {
parcel.writeString(name);
parcel.writeString(logoUrl);
parcel.writeString(host);
}

@Override
Expand Down

0 comments on commit 1538280

Please sign in to comment.