<?php
/**
 * Created by PhpStorm.
 * User: sunil
 * Date: 9/6/18
 * Time: 5:38 PM
 */

namespace App;


use Illuminate\Http\Request;

class Trello
{
    private $key = 'fcd6e762375e6d599667e41cc06232e2';
    private $token = 'd9c8d286fa3220b042e7b6cf32c05c6df3b2a4348044bbdfce9eac6ea8cc2b7a';
    private $api = 'https://api.trello.com/1/cards/';
    private $idList = '5b7f9fb868f75443a0fec00d';
    private $requestData;
    private $request;

    public function __construct(Request $request){
        $this->request = $request;
    }

    public function insertInTrello(){
        $this->requestData = array('name'=>$this->request->get('title'));
        $this->connect();
    }

    public function connect(){
        try {
            $curl = curl_init();
            $auth = ['key'=>$this->key,'token'=>$this->token,'idList'=>$this->idList,'pos'=>'top'];
            $this->requestData = array_merge($this->requestData,$auth);
            curl_setopt($curl, CURLOPT_URL, $this->api);
            curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($this->requestData));
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
            curl_setopt($curl, CURLOPT_VERBOSE, 1);
            curl_setopt($curl, CURLOPT_POST, 1);

            curl_exec($curl);
            curl_getinfo($curl);
        }catch(\Exception $e){
            return $e->getMessage().$e->getLine().$e->getFile();
        }
    }
}