Skip to content

Commit

Permalink
Add support for ai-generated photos (#55)
Browse files Browse the repository at this point in the history
* add support for ai-generated photos

* add tests and example

* fix intendation

* fix intendation
  • Loading branch information
tsolakoua committed Mar 13, 2020
1 parent 8ed52c6 commit 9e6cf0e
Show file tree
Hide file tree
Showing 9 changed files with 240 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,10 @@ SeatMap[] seatmap = amadeus.shopping.seatMaps.get(Params
// What is the the seat map of a given flight?
// The body can be a String version of your JSON or a JsonObject
SeatMap[] seatmap = amadeus.shopping.seatMaps.post(body);

// AI-Generated Photos
GeneratedPhoto photo = amadeus.media.files.generatedPhotos.get(Params
.with("category", "BEACH"));
```

## Development & Contributing
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/amadeus/Amadeus.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ public class Amadeus extends HTTPClient {
*/
public Booking booking;

/**
* <p>
* A namespaced client for the <code>/v2/media</code> endpoints.
* </p>
*/
public Media media;

protected Amadeus(Configuration configuration) {
super(configuration);
this.referenceData = new ReferenceData(this);
Expand All @@ -77,6 +84,8 @@ protected Amadeus(Configuration configuration) {
this.ereputation = new EReputation(this);
this.airport = new Airport(this);
this.booking = new Booking(this);
this.media = new Media(this);

}

/**
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/com/amadeus/Media.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.amadeus;

import com.amadeus.media.Files;

/**
* <p>
* A namespaced client for the
* <code>/v2/media</code> endpoints.
* </p>
*
* <p>
* Access via the Amadeus client object.
* </p>
*
* <pre>
* Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
* amadeus.media;</pre>
*
* @hide
*/
public class Media {
/**
* <p>
* A namespaced client for the
* <code>/v2/media/files</code> endpoints.
* </p>
*/
public Files files;

/**
* Constructor.
* @hide
*/
public Media(Amadeus client) {
this.files = new Files(client);
}
}
39 changes: 39 additions & 0 deletions src/main/java/com/amadeus/media/Files.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.amadeus.media;

import com.amadeus.Amadeus;
import com.amadeus.media.files.GeneratedPhotos;

/**
* <p>
* A namespaced client for the
* <code>/v2/media/files</code> endpoints.
* </p>
*
* <p>
* Access via the Amadeus client object.
* </p>
*
* <pre>
* Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
* amadeus.media.files;</pre>
*
* @hide
*/
public class Files {
/**
* <p>
* A namespaced client for the
* <code>/v2/media/files/generated-photos</code> endpoints.
* </p>
*/
public GeneratedPhotos generatedPhotos;

/**
* Constructor.
*
* @hide
*/
public Files(Amadeus client) {
this.generatedPhotos = new GeneratedPhotos(client);
}
}
60 changes: 60 additions & 0 deletions src/main/java/com/amadeus/media/files/GeneratedPhotos.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.amadeus.media.files;

import com.amadeus.Amadeus;
import com.amadeus.Params;
import com.amadeus.Response;
import com.amadeus.exceptions.ResponseException;
import com.amadeus.resources.GeneratedPhoto;
import com.amadeus.resources.Resource;

/**
* <p>
* A namespaced client for the
* <code>/v2/media/files/generated-photos</code> endpoints.
* </p>
*
* <p>
* Access via the Amadeus client object.
* </p>
*
* <pre>
* Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
* amadeus.media.files.generatedPhotos;</pre>
*/
public class GeneratedPhotos {
private Amadeus client;

/**
* Constructor.
* @hide
*/
public GeneratedPhotos(Amadeus client) {
this.client = client;
}

/**
* <p>
* Returns a link to download a rendered image of a landscape.
* </p>
*
* <pre>
* amadeus.media.files.generatedPhotos.get(Params
* .with("category", "BEACH"));</pre>
*
* @param params the parameters to send to the API
* @return an API response object
* @throws ResponseException when an exception occurs
*/
public GeneratedPhoto get(Params params) throws ResponseException {
Response response = client.get("/v2/media/files/generated-photos", params);
return (GeneratedPhoto) Resource.fromObject(response, GeneratedPhoto.class);
}

/**
* Convenience method for calling <code>get</code> without any parameters.
* @see GeneratedPhotos#get()
*/
public GeneratedPhoto get() throws ResponseException {
return get(null);
}
}
45 changes: 45 additions & 0 deletions src/main/java/com/amadeus/resources/GeneratedPhoto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.amadeus.resources;

import lombok.Getter;
import lombok.ToString;

/**
* An GeneratedPhoto object as returned by the AI-Generated Photos API.
* @see Traveled#get()
*/
@ToString
public class GeneratedPhoto extends Resource {
protected GeneratedPhoto() {}

private @Getter String type;
private @Getter String owner;
private @Getter String attachmentUri;
private @Getter String description;
private @Getter String fileKbSize;
private @Getter String expirationDateTime;
private @Getter MediaMetadata mediaMetadata;

/**
* A MediaMetadata-related object as returned by the AI-Generated Photos API.
* @see GeneratedPhotos#get()
*/
@ToString
public class MediaMetadata {
protected MediaMetadata() {}

private @Getter Dimension dimensions;

/**
* A MediaMetadata-related object as returned by the AI-Generated Photos API.
* @see GeneratedPhotos#get()
*/
@ToString
public class Dimension {
protected Dimension() {}

private @Getter String height;
private @Getter String width;

}
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/amadeus/resources/PointOfInterest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import lombok.ToString;

/**
* An PointOfInterest object as returned by the Locaion API.
* An PointOfInterest object as returned by the Location API.
* @see com.amadeus.referenceData.locations.PointOfInterest#get()
*/
@ToString
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/examples/media/AIGeneratedPhotos.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package examples.media.files;

import com.amadeus.Amadeus;
import com.amadeus.Params;
import com.amadeus.exceptions.ResponseException;
import com.amadeus.resources.GeneratedPhoto;

public class AIGeneratedPhotos {
/**
* <p>
* An example to call the AI-Generated Photos API
* <code>/v2/media/files/generated-photos</code> endpoints.
* </p>
*
* <p>
* Access via the Amadeus client object.
* </p>
*
* <pre>
* Amadeus amadeus = Amadeus.builder("clientId", "secret").build();
* amadeus.media.files.generatedPhotos;</pre>
*/
public static void main(String[] args) throws ResponseException {


Amadeus amadeus = Amadeus
.builder("YOUR_API_ID","YOUR_API_SECRET")
.build();

GeneratedPhoto photo = amadeus.media.files.generatedPhotos.get(Params
.with("category", "BEACH"));
System.out.println(photo);
}
}
11 changes: 11 additions & 0 deletions src/test/java/com/amadeus/NamespaceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.amadeus.booking.FlightOrders;
import com.amadeus.ereputation.HotelSentiments;
import com.amadeus.exceptions.ResponseException;
import com.amadeus.media.files.GeneratedPhotos;
import com.amadeus.referenceData.Airlines;
import com.amadeus.referenceData.Location;
import com.amadeus.referenceData.Locations;
Expand Down Expand Up @@ -64,6 +65,7 @@ public void testAllNamespacesExist() {
TestCase.assertNotNull(client.shopping.hotelOffer("XXX"));
TestCase.assertNotNull(client.airport.predictions.onTime);
TestCase.assertNotNull(client.booking.flightOrder("XXX"));
TestCase.assertNotNull(client.media.files.generatedPhotos);
}

@Before
Expand Down Expand Up @@ -298,6 +300,15 @@ public void testGetMethods() throws ResponseException {
FlightOrder flightOrder = new FlightOrder(client, "XXX");
TestCase.assertNotNull(flightOrder.get());
TestCase.assertNotNull(flightOrder.get(params));

// Testing AI-generated photos
Mockito.when(client.get("/v2/media/files/generated-photos", null))
.thenReturn(singleResponse);
Mockito.when(client.get("/v2/media/files/generated-photos", params))
.thenReturn(singleResponse);
GeneratedPhotos photo = new GeneratedPhotos(client);
TestCase.assertNotNull(photo.get());
TestCase.assertNotNull(photo.get(params));
}

@Test
Expand Down

0 comments on commit 9e6cf0e

Please sign in to comment.