Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,10 @@
<finalName>${project.artifactId}-${project.version}</finalName>
</build>
<dependencies>
<dependency>
<groupId>com.google.api.client</groupId>
<artifactId>google-api-client</artifactId>
<version>1.4.1-beta</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.api.client</groupId>
<artifactId>google-api-client-googleapis</artifactId>
<version>1.4.1-beta</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>1.8.0-beta</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
import com.google.api.client.http.HttpRequestFactory;
import com.google.api.client.http.HttpResponse;
import com.google.api.client.http.xml.atom.AtomContent;
import com.google.api.client.http.xml.atom.AtomFeedContent;
import com.google.api.client.http.xml.atom.AtomParser;
import com.google.api.client.xml.XmlNamespaceDictionary;
import com.google.common.collect.Lists;
import com.iubiquity.spreadsheets.model.CellEntry;
import com.iubiquity.spreadsheets.model.CellFeed;
import com.iubiquity.spreadsheets.model.Feed;
import com.iubiquity.spreadsheets.model.Link;
import com.iubiquity.spreadsheets.model.ListFeed;
import com.iubiquity.spreadsheets.model.SpreadsheetFeed;
import com.iubiquity.spreadsheets.model.SpreadsheetUrl;
import com.iubiquity.spreadsheets.model.WorksheetData;
Expand All @@ -38,44 +38,39 @@ abstract public class SpreadsheetClient {
public HttpRequestFactory requestFactory;

public void initializeParser(HttpRequest request) {
AtomParser parser = new AtomParser();
parser.namespaceDictionary = DICTIONARY;
AtomParser parser = new AtomParser(DICTIONARY);
request.addParser(parser);
}

public void executeDelete(CellEntry cellEntry) throws IOException {
HttpRequest request = requestFactory.buildDeleteRequest(new GenericUrl(
cellEntry.getEditLink()));
request.headers.ifMatch = cellEntry.etag;
request.getHeaders().setIfMatch(cellEntry.etag);
request.execute().ignore();
}

public CellEntry executeInsert(CellEntry entry, boolean matchTag)
throws IOException {
AtomContent content = new AtomContent();
content.namespaceDictionary = DICTIONARY;
content.entry = entry;
AtomContent content = AtomContent.forEntry(DICTIONARY, entry);
HttpRequest request = requestFactory.buildPutRequest(
new SpreadsheetUrl(entry.getEditLink()), content);

if (matchTag) {
// this will only insert if there has been no modification.
request.headers.ifMatch = ((CellEntry) entry).etag;
request.getHeaders().setIfMatch(((CellEntry) entry).etag);
} else {
// this will only insert if there has been a modification
request.headers.ifNoneMatch = ((CellEntry) entry).etag;
request.getHeaders().setIfNoneMatch(((CellEntry) entry).etag);
}
return request.execute().parseAs(entry.getClass());
}

public CellEntry addCellEntry(CellEntry cellEntry,
SpreadsheetUrl cellfeedUrl) throws IOException {
AtomContent content = new AtomContent();
content.namespaceDictionary = DICTIONARY;
content.entry = cellEntry;
AtomContent content = AtomContent.forEntry(DICTIONARY, cellEntry);
HttpRequest request = requestFactory.buildPostRequest(cellfeedUrl,
content);
request.headers.ifNoneMatch = ((CellEntry) cellEntry).etag;
request.getHeaders().setIfNoneMatch(((CellEntry) cellEntry).etag);
return request.execute().parseAs(cellEntry.getClass());
}

Expand All @@ -97,11 +92,12 @@ public CellFeed batchUpdate(CellFeed feed) throws IOException {
}
feed.cells = updatedCells;
SpreadsheetUrl url = new SpreadsheetUrl(feed.getBatchLink());
AtomFeedContent content = new AtomFeedContent();
content.namespaceDictionary = DICTIONARY;
content.feed = feed;
// AtomFeedContent content = new AtomFeedContent();
AtomContent content = AtomContent.forFeed(DICTIONARY, feed);
// content.namespaceDictionary = DICTIONARY;
// content.feed = feed;
HttpRequest request = requestFactory.buildPostRequest(url, content);
request.headers.ifNoneMatch = "whatever";
request.getHeaders().setIfNoneMatch("whatever");
return request.execute().parseAs(CellFeed.class);
}

Expand Down Expand Up @@ -140,6 +136,15 @@ public CellFeed executeGetCellFeed(SpreadsheetUrl url) throws IOException {
public CellFeed executeGetCellFeed(String url) throws IOException {
return executeGetCellFeed(new SpreadsheetUrl(url));
}


public ListFeed executeGetListFeed(SpreadsheetUrl url) throws IOException {
return executeGetFeed(url, ListFeed.class);
}

public ListFeed executeGetListFeed(String url) throws IOException {
return executeGetListFeed(new SpreadsheetUrl(url));
}

public WorksheetFeed executeGetWorksheetFeed(SpreadsheetUrl url)
throws IOException {
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/com/iubiquity/spreadsheets/model/CellFeed.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.iubiquity.spreadsheets.model;

import com.google.api.client.http.HttpResponse;
import com.google.api.client.util.Key;

import java.util.ArrayList;
import java.util.List;

import com.google.api.client.http.HttpStatusCodes;
import com.google.api.client.util.Key;

public class CellFeed extends Feed {

@Key("title")
Expand All @@ -25,7 +25,8 @@ public String getBatchError() {
for (CellEntry ce : cells) {
BatchStatus batchStatus = ce.batchStatus;
if (batchStatus != null
&& !HttpResponse.isSuccessStatusCode(batchStatus.code)) {
&& !HttpStatusCodes.isSuccess(batchStatus.code)) {
// && !HttpResponse.isSuccessStatusCode(batchStatus.code)) {
return batchStatus.reason;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@

import java.util.ArrayList;
import java.util.List;

public class SpreadsheetFeed extends Feed {

@Key("entry")
public List<SpreadsheetEntry> spreadsheets = new ArrayList<SpreadsheetEntry>();

/**
* Returns a list of SpreadsheetEntries from the feed
* @return list of spread sheet entries in the feed
*/
public List<SpreadsheetEntry> getEntries() {
return spreadsheets;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ private static SpreadsheetUrl forRoot() {

public static SpreadsheetUrl forSpreadSheetMetafeed() {
SpreadsheetUrl result = forRoot();
result.pathParts.add("private");
result.pathParts.add("full");
// result.pathParts.add("private");
// result.pathParts.add("full");
result.getPathParts().add("private");
result.getPathParts().add("full");
return result;
}

Expand Down