<?php
defined('BASEPATH') OR exit('No direct script access allowed');
header("Access-Control-Allow-Origin: *");
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');  


ini_set('display_errors', 1);
// New Shopify Api
use Osiset\BasicShopifyAPI\BasicShopifyAPI;
use Osiset\BasicShopifyAPI\Options;
use Osiset\BasicShopifyAPI\Session;


class Test extends CI_Controller {
        /**
         * Index Page for this controller.
         *
         * Maps to the following URL
         *              http://example.com/index.php/welcome
         *      - or -
         *              http://example.com/index.php/welcome/index
         *      - or -
         * Since this controller is set as the default controller in
         * config/routes.php, it's displayed at http://example.com/
         *
         * So any other public methods not prefixed with an underscore will
         * map to /index.php/welcome/<method_name>
         * @see https://codeigniter.com/user_guide/general/urls.html
         */

        public  $api,$shopData;
        public $shop;
        public function __construct()
        {
                parent::__construct();// you have missed this line.
                $options = new Options();
                $options->setVersion(SHOPIYF_VERSION);
                $options->setApiKey(SHOPIFY_API_KEY);
                $options->setApiSecret(SHOPIFY_SECRET_KEY);
                // Create the client and session
                $this->api = new BasicShopifyAPI($options);
                $this->shop = $this->input->get('shop')??$this->input->cookie('shop'); 
                $this->shopData =$this->adminModel->get_row("app_record",array("shop_address"=>$this->shop));
                if(!$this->shop || !$this->shopData){
                        echo "404 not found";
                        die();
                }
        }

        
        public function setUrl(){
                 $token = $this->shopData->shop_token??'';
                $this->api->setSession(new Session($this->shop, $token));
                $getScriptTags= $this->api->rest("get","/admin/api/script_tags.json");
                print_r($getScriptTags["body"]);
                die();
                // $token = $this->shopData->shop_token??'';
                // $this->api->setSession(new Session($this->shop, $token));
                // $getScriptTags= $this->api->rest("get","/admin/api/2021-10/script_tags.json");
                // echo "<pre>";
                // print_r($getScriptTags["body"]);
                // $array=array("script_tag"=>array("src"=>base_url("frontend/js/reconvert.min.js")));
                // $getScript=$this->api->rest("put","/admin/api/2021-10/script_tags/185485492285.json",$array);
                // print_r($getScript["body"]);
        }

        
}    