origamiduck.com.polarbear.MyDatabase.AsyncRecipe.java Source code

Java tutorial

Introduction

Here is the source code for origamiduck.com.polarbear.MyDatabase.AsyncRecipe.java

Source

package origamiduck.com.polarbear.MyDatabase;

import android.app.Activity;
import android.content.Context;
import android.os.AsyncTask;
import android.support.v7.widget.RecyclerView;
import android.util.Log;

import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class AsyncRecipe extends AsyncTask<String, Void, String> {

    String s;

    public AsyncRecipe(Context context, RecyclerView recyclerView) {

    }

    @Override
    protected String doInBackground(String... strings) {
        /*
        try{
        HttpResponse<JsonNode> response = Unirest.get("https://spoonacular-recipe-food-nutrition-v1.p.mashape.com/recipes/findByIngredients?fillIngredients=false&ingredients=apples%2Cflour%2Csugar&limitLicense=false&number=5&ranking=1")
                .header("X-Mashape-Key","z9ajPi1c8ImshLh8xIzTU2hUCNmxp1e27VUjsndjkg2I9U9q1U")
                .header("Accept", "application/json")
                .asJson();
        s = response.getBody().toString();
            
        }catch (Exception e){
            
        }
        */
        return null;
    }

    @Override
    protected void onPostExecute(String s) {
        super.onPostExecute(s);
        Log.wtf("RESULT", s);
    }

    private String readStream(InputStream in) {
        BufferedReader reader = null;
        StringBuffer response = new StringBuffer();
        try {
            reader = new BufferedReader(new InputStreamReader(in));
            String line = "";
            while ((line = reader.readLine()) != null)
                response.append(line);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return response.toString();
    }

}