RapidSoftwareSolutions / rapidapi-android-sdk

Find, try and connect to APIs easily with the RapidAPI marketplace
http://rapidapi.com
2 stars 4 forks source link

Endpoint taking no parameters throws Exception #5

Open psh opened 7 years ago

psh commented 7 years ago

Using code that matches the snippet on your website:

RapidApiConnect connect = new RapidApiConnect(<project>, <api_key>);
Map<String, Argument> body = new HashMap<>();

try {
    Map<String, Object> response = connect.call("HackerNews", "getTopStories", body);
    Object success = response.get("success");
    if (success != null) {
        Log.e("Example", "Success is a " + success.getClass().getName());
        Log.e("Example", "Success is: \"" + success+"\"");
    } else {
        Log.e("Example", "Oops: "+response);
    }
} catch (Exception e) {
    Log.e("Example", "Oops", e);
}

Result: fails with java.lang.IllegalStateException: Multipart body must have at least one part.

iddogino commented 7 years ago

@Bukati

Bukati commented 7 years ago

The exception you get for a zero part request comes from OkHttp. We will update the code snippet on the marketplace. Thanks.

psh commented 7 years ago

How will updating the code snippet help? This is a legitimate API that takes no parameters. The exception is telling me that the code in RapidApiConnect needs to add an empty request body (skip lines 63-84 if we are given an empty map).

I have a pull request ready if you're open to it, with associated unit test that exercises the bug.

Bukati commented 7 years ago

Of course, shoot