package com.minano.themovielibrary.helpers;

import com.minano.themovielibrary.models.DetailItem;

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

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

/**
 * Created by Admin on 25/09/2016.
 */
public class LiveStreamParser implements IJSONParser {
    @Override
    public List<DetailItem> parseResponse(String response) {
        List<DetailItem> filmList = new ArrayList<DetailItem>();
        try {
            JSONObject jsonObject = new JSONObject(response);

            JSONArray jsonArray = (JSONArray) jsonObject.get("stations");
            for (int i = 0; i<jsonArray.length(); i++)
            {
                JSONObject object = jsonArray.getJSONObject(i);
                DetailItem detailItem = new DetailItem();
                detailItem.setTitle(object.getString("name"));
                detailItem.setReleaseDate(object.getString("url"));
                detailItem.setImageString(object.getString("image"));
                filmList.add(detailItem);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return filmList;
    }
}
