<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class JsonExample extends CI_Controller {
	 
	public function index()
	{
		$this->load->view('welcome_message');
	}

	public function response() { 
		header('Content-Type: application/json');
		$productArray = ['id'=>9898, 'name'=>'Mobile'];
		echo json_encode($productArray);
	  } 

	  public function token() { 
		header('Content-Type: application/json');
		$this->load->library('Token');
		$productArray = $this->token->token_get();
		echo json_encode($productArray);
	  } 

	  public function validate_token() { 
		$headers = $this->input->request_headers();
		
		$this->load->library('Token');
		$productArray = [];

		if($this->token->token_post($headers))
			$productArray = ['code'=>'00', 'msg'=>'Valid Token'];
		else
			$productArray = ['code'=>'99', 'msg'=>'Invalid/Expired Token'];
		
		header('Content-Type: application/json');
		echo json_encode($productArray);
	  } 
}
