// Path: reactivefb/src/main/java/com/beltaief/reactivefb/util/Utils.java
// public final class Utils {
//     private Utils() {
//     }
// 
//     public static Bundle getBundle(String mFields, int limit) {
//         Bundle bundle = new Bundle();
//         if (mFields != null) {
//             bundle.putString("fields", mFields);
//         }
//         if (limit > 0) {
//             bundle.putString("limit", String.valueOf(limit));
//         }
//         return bundle;
//     }
// 
//     @SuppressWarnings("resource")
//     public static String encode(String key, String data) {
//         try {
//             Mac mac = Mac.getInstance("HmacSHA256");
//             SecretKeySpec secretKey = new SecretKeySpec(key.getBytes(), "HmacSHA256");
//             mac.init(secretKey);
//             byte[] bytes = mac.doFinal(data.getBytes());
//             StringBuilder sb = new StringBuilder(bytes.length * 2);
//             Formatter formatter = new Formatter(sb);
//             for (byte b : bytes) {
//                 formatter.format("%02x", b);
//             }
//             return sb.toString();
//         } catch (Exception e) {
//             Logger.logError(Utils.class, "Failed to create sha256", e);
//             return null;
//         }
//     }
// }


import android.support.annotation.Nullable;
import com.beltaief.reactivefb.util.Utils;
import com.facebook.GraphResponse;
import io.reactivex.SingleEmitter;
import io.reactivex.SingleOnSubscribe;
package com.beltaief.reactivefb.requests;




/**
 * A custom class that extends SingleOnSubscribe.
 *
 * Created by wassim on 10/7/16.
 */
class RequestOnSubscribe implements SingleOnSubscribe<GraphResponse> {

    private final String mEdge;
    private final String mTarget;
    private final String mFields;
    private final int mLimit;

    /**
     * The constructor used to instantiate the SingleOnSubscribe from Single.create().
     * @param target the target in GraphAPI
     *               example : /v2.7/TARGET/albums
     * @param edge the edge in GraphAPI
     *             example : /v2.7/me/EDGE
     * @param fields the fields to get from the graphAPI
     *               example : /v2.7/me?FIELDS=id,name
     * @param limit the limit of the number of elements returned by the graphAPI
     *              example : /v2.7/me/albums?fields=count&limit=10
     */
    RequestOnSubscribe(@Nullable String target, @Nullable String edge,
                       @Nullable String fields, int limit) {
        this.mTarget = target;
        this.mEdge = edge;
        this.mFields = fields;
        this.mLimit = limit;
    }

    @Override
    public void subscribe(SingleEmitter<GraphResponse> emitter) throws Exception {
        RequestAction action = new RequestAction();
        action.setSingleEmitter(emitter);
        action.setTarget(mTarget);
        action.setEdge(mEdge);
// Path: reactivefb/src/main/java/com/beltaief/reactivefb/util/Utils.java
// public final class Utils {
//     private Utils() {
//     }
// 
//     public static Bundle getBundle(String mFields, int limit) {
//         Bundle bundle = new Bundle();
//         if (mFields != null) {
//             bundle.putString("fields", mFields);
//         }
//         if (limit > 0) {
//             bundle.putString("limit", String.valueOf(limit));
//         }
//         return bundle;
//     }
// 
//     @SuppressWarnings("resource")
//     public static String encode(String key, String data) {
//         try {
//             Mac mac = Mac.getInstance("HmacSHA256");
//             SecretKeySpec secretKey = new SecretKeySpec(key.getBytes(), "HmacSHA256");
//             mac.init(secretKey);
//             byte[] bytes = mac.doFinal(data.getBytes());
//             StringBuilder sb = new StringBuilder(bytes.length * 2);
//             Formatter formatter = new Formatter(sb);
//             for (byte b : bytes) {
//                 formatter.format("%02x", b);
//             }
//             return sb.toString();
//         } catch (Exception e) {
//             Logger.logError(Utils.class, "Failed to create sha256", e);
//             return null;
//         }
//     }
// }


// Path: reactivefb/src/main/java/com/beltaief/reactivefb/requests/RequestOnSubscribe.java
import android.support.annotation.Nullable;
import com.beltaief.reactivefb.util.Utils;
import com.facebook.GraphResponse;
import io.reactivex.SingleEmitter;
import io.reactivex.SingleOnSubscribe;

package com.beltaief.reactivefb.requests;




/**
 * A custom class that extends SingleOnSubscribe.
 *
 * Created by wassim on 10/7/16.
 */
class RequestOnSubscribe implements SingleOnSubscribe<GraphResponse> {

    private final String mEdge;
    private final String mTarget;
    private final String mFields;
    private final int mLimit;

    /**
     * The constructor used to instantiate the SingleOnSubscribe from Single.create().
     * @param target the target in GraphAPI
     *               example : /v2.7/TARGET/albums
     * @param edge the edge in GraphAPI
     *             example : /v2.7/me/EDGE
     * @param fields the fields to get from the graphAPI
     *               example : /v2.7/me?FIELDS=id,name
     * @param limit the limit of the number of elements returned by the graphAPI
     *              example : /v2.7/me/albums?fields=count&limit=10
     */
    RequestOnSubscribe(@Nullable String target, @Nullable String edge,
                       @Nullable String fields, int limit) {
        this.mTarget = target;
        this.mEdge = edge;
        this.mFields = fields;
        this.mLimit = limit;
    }

    @Override
    public void subscribe(SingleEmitter<GraphResponse> emitter) throws Exception {
        RequestAction action = new RequestAction();
        action.setSingleEmitter(emitter);
        action.setTarget(mTarget);
        action.setEdge(mEdge);
        action.setBundle(Utils.getBundle(mFields, mLimit));