Skip to content

Commit

Permalink
Add Content Type header when creating entries
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Reznik committed Nov 22, 2014
1 parent 14e4ad3 commit f5d3085
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
14 changes: 8 additions & 6 deletions src/main/java/com/contentful/java/cma/ModuleEntries.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@ public CMAEntry archive(CMAEntry entry) {
* success.
*
* @param spaceId Space ID
* @param contentTypeId Content Type ID
* @param entry Entry
* @return {@link CMAEntry} result instance
*/
@SuppressWarnings("unchecked")
public CMAEntry create(String spaceId, CMAEntry entry) {
public CMAEntry create(String spaceId, String contentTypeId, CMAEntry entry) {
assertNotNull(spaceId, "spaceId");
assertNotNull(entry, "entry");

Expand All @@ -73,9 +74,9 @@ public CMAEntry create(String spaceId, CMAEntry entry) {
try {
CMAEntry result;
if (entryId == null) {
result = service.create(spaceId, entry);
result = service.create(spaceId, contentTypeId, entry);
} else {
result = service.create(spaceId, entryId, entry);
result = service.create(spaceId, contentTypeId, entryId, entry);
}
entry.setSys(sys);
return result;
Expand Down Expand Up @@ -210,15 +211,16 @@ public CMACallback<CMAEntry> archive(final CMAEntry entry, CMACallback<CMAEntry>
* success.
*
* @param spaceId Space ID
* @param contentTypeId Content Type ID
* @param entry Entry
* @param callback Callback
* @return the given {@code CMACallback} instance
*/
public CMACallback<CMAEntry> create(final String spaceId, final CMAEntry entry,
CMACallback<CMAEntry> callback) {
public CMACallback<CMAEntry> create(final String spaceId, final String contentTypeId,
final CMAEntry entry, CMACallback<CMAEntry> callback) {
return defer(new RxExtensions.DefFunc<CMAEntry>() {
@Override CMAEntry method() {
return ModuleEntries.this.create(spaceId, entry);
return ModuleEntries.this.create(spaceId, contentTypeId, entry);
}
}, callback);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/contentful/java/cma/ServiceEntries.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ CMAEntry archive(
@POST("/spaces/{space}/entries")
CMAEntry create(
@Path("space") String spaceId,
@Header("X-Contentful-Content-Type") String contentType,
@Body CMAEntry entry);

@PUT("/spaces/{space}/entries/{entry}")
CMAEntry create(
@Path("space") String spaceId,
@Header("X-Contentful-Content-Type") String contentType,
@Path("entry") String entryId,
@Body CMAEntry entry);

Expand Down
8 changes: 5 additions & 3 deletions src/test/kotlin/com/contentful/java/cma/EntryTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class EntryTests : BaseTest() {

val result = assertTestCallback(client!!.entries()
.async()
.create("spaceid", entry, TestCallback()) as TestCallback)
.create("spaceid", "ctid", entry, TestCallback()) as TestCallback)

assertEquals(2, result.getFields().size)

Expand All @@ -76,6 +76,7 @@ class EntryTests : BaseTest() {
assertEquals("POST", recordedRequest.getMethod())
assertEquals("/spaces/spaceid/entries", recordedRequest.getPath())
assertEquals(requestBody, recordedRequest.getBodyAsString())
assertEquals("ctid", recordedRequest.getHeader("X-Contentful-Content-Type"))
}

test fun testCreateWithId() {
Expand All @@ -89,13 +90,14 @@ class EntryTests : BaseTest() {
.setField("fid2", "value2", "en-US")

assertTestCallback(client!!.entries().async().create(
"spaceid", entry, TestCallback()) as TestCallback)
"spaceid", "ctid", entry, TestCallback()) as TestCallback)

// Request
val recordedRequest = server!!.takeRequest()
assertEquals("PUT", recordedRequest.getMethod())
assertEquals("/spaces/spaceid/entries/entryid", recordedRequest.getPath())
assertEquals(requestBody, recordedRequest.getBodyAsString())
assertEquals("ctid", recordedRequest.getHeader("X-Contentful-Content-Type"))
}

test fun testDelete() {
Expand Down Expand Up @@ -240,7 +242,7 @@ class EntryTests : BaseTest() {

val entry = CMAEntry().setVersion(31337.0)
try {
badClient.entries().create("spaceid", entry)
badClient.entries().create("spaceid", "ctid", entry)
} catch (e: RetrofitError) {
assertEquals(31337, entry.getVersion())
throw e
Expand Down

0 comments on commit f5d3085

Please sign in to comment.