tumblr / jumblr

Tumblr API v2 Java Client
Apache License 2.0
278 stars 105 forks source link

Error when reblog a post #45

Closed Ark4ne closed 9 years ago

Ark4ne commented 10 years ago

I just start with Jumblr and i got an error ( NullPointer ) when i reblog a post.

The problem happens because we try to parse the json object "post" while one recovers only the new post id.

I made two changes:

JumblrClient.java : Edit postReblog()

    public Post postReblog(String blogName, Long postId, String reblogKey, Map<String, ?> options) {
        if (options == null) {
            options = new HashMap<String, String>();
        }
        Map<String, Object> soptions = JumblrClient.safeOptionMap(options);
        soptions.put("id", postId.toString());
        soptions.put("reblog_key", reblogKey);

        // Edit here
        Long id = requestBuilder.post(JumblrClient.blogPath(blogName, "/post/reblog"), soptions).getIdFromReblog();
        return this.blogPost(blogName, id);
    }

ResponseWrapper.java : Add getIdFromReblog()


    public Long getIdFromReblog() {
        Gson gson = gsonParser();
        JsonObject object = (JsonObject) response;

        return gson.fromJson(object.get("id").toString(), Long.class);
    }

And the probleme has been solved ;)

codingjester commented 10 years ago

Would you be willing to do a patch and some tests to get this pulled into the client? We're happy to take a PR!

vivekvinodh commented 7 years ago

This error is still within the current version of jumblr.