Search in sources :

Example 11 with NewsRobHttpClient

use of com.newsrob.download.NewsRobHttpClient in project newsrob by marianokamp.

the class GRAnsweredBadRequestException method remotelyAlterState.

private int remotelyAlterState(Collection<Entry> entries, final String column, String desiredState) throws ReaderAPIException {
    NewsRobHttpClient httpClient = NewsRobHttpClient.newInstance(false, context);
    try {
        HttpPost editApiRequest = new HttpPost(getGoogleHost() + "/reader/api/0/edit-tag?client=" + CLIENT_NAME);
        submitPostRequest(httpClient, editApiRequest, createNVPForAlterRemoteState(entries, column, desiredState), false);
        // At this point the submitPost is already done without errors
        // otherwise an exception would have been raised
        List<String> atomIds = new ArrayList<String>(entries.size());
        for (Entry entry : entries) atomIds.add(entry.getAtomId());
        getEntryManager().removePendingStateMarkers(atomIds, column);
        return entries.size();
    } catch (Exception e) {
        String message = "Problem during marking entry as un-/read: " + e.getMessage();
        Log.e(TAG, message, e);
        throw new ReaderAPIException(message, e);
    } finally {
        httpClient.close();
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) NewsRobHttpClient(com.newsrob.download.NewsRobHttpClient) ArrayList(java.util.ArrayList) ClientProtocolException(org.apache.http.client.ClientProtocolException) ParseException(java.text.ParseException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 12 with NewsRobHttpClient

use of com.newsrob.download.NewsRobHttpClient in project newsrob by marianokamp.

the class GRAnsweredBadRequestException method fetchStreamIds.

private long[] fetchStreamIds(final EntryManager entryManager, String tag, final String googleStateToExclude) throws SAXException, IOException, ParserConfigurationException, GRTokenExpiredException, GRAnsweredBadRequestException {
    Timing t = new Timing("ER.fetchStreamIds for " + tag + " xt=" + googleStateToExclude, context);
    PL.log("ER.fetchStreamIds for " + tag + " xt=" + googleStateToExclude + " (1)", context);
    NewsRobHttpClient httpClient = NewsRobHttpClient.newInstance(false, context);
    try {
        List<String> tags = new ArrayList<String>(2);
        // tags.add(GOOGLE_STATE_READING_LIST);
        if (tag != null)
            tags.add(tag);
        long[] unreadIds = getStreamIDsFromGR(httpClient, tags, googleStateToExclude, MAX_ARTICLES_ON_GOOGLE_READER_ACCOUNT);
        PL.log("EntriesRetriever.getUnreadIDsFromGR done.", context);
        return unreadIds;
    } finally {
        httpClient.close();
        t.stop();
        PL.log("ER.fetchStreamIds for " + tag + " xt=" + googleStateToExclude + " (2)", context);
    }
}
Also used : NewsRobHttpClient(com.newsrob.download.NewsRobHttpClient) ArrayList(java.util.ArrayList) Timing(com.newsrob.util.Timing)

Aggregations

NewsRobHttpClient (com.newsrob.download.NewsRobHttpClient)12 Timing (com.newsrob.util.Timing)9 ArrayList (java.util.ArrayList)8 HttpResponse (org.apache.http.HttpResponse)7 IOException (java.io.IOException)6 HttpPost (org.apache.http.client.methods.HttpPost)6 NameValuePair (org.apache.http.NameValuePair)5 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)5 SAXException (org.xml.sax.SAXException)4 SimpleStringExtractorHandler (com.newsrob.util.SimpleStringExtractorHandler)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 MalformedURLException (java.net.MalformedURLException)3 ParseException (java.text.ParseException)3 ExecutionException (java.util.concurrent.ExecutionException)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 SAXParser (javax.xml.parsers.SAXParser)3 SAXParserFactory (javax.xml.parsers.SAXParserFactory)3 ClientProtocolException (org.apache.http.client.ClientProtocolException)3 HttpRequestBase (org.apache.http.client.methods.HttpRequestBase)3 DefaultHandler (org.xml.sax.helpers.DefaultHandler)3