<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

class Users_model extends CI_Model {

    public $userId;
    public $nickname;
    public $accessToken;
    public $refreshToken;
    public $expires_in;
    

    public function __construct() {
        $this->load->database();
    }

    public function get_me($data) {
        $this->load->library('Mercadolibre');
        $meli = new Mercadolibre();
        $result = $meli->get('/users/me', array('access_token' => $data["access_token"]));

        return $result;
    }

    public function insert_entry($token,$usr) {
        
        $this->userId = $usr["body"]->id;
        $this->nickname= $usr["body"]->nickname;
        $this->accessToken = $token['access_token'];
        $this->refreshToken = $token['refresh_token'];
        $this->expires_in = $token['expires_in'];

        $this->db->insert('users', $this);
    }

    public function update_entry() {
        $this->title = $_POST['title'];
        $this->content = $_POST['content'];
        $this->date = time();

        $this->db->update('users', $this, array('id' => $_POST['id']));
    }

}
