/*
 * comunicator.h
 *
 *  Created on: 25.5.2011
 *      Author: petr
 */

#ifndef COMUNICATOR_H_
#define COMUNICATOR_H_

#include <curlpp/cURLpp.hpp>
#include <curlpp/Easy.hpp>
#include <curlpp/Options.hpp>
#include <json/json.h>
#include <string>
#include <iostream>
#include <map>
#include <vector>

using namespace std;
using namespace curlpp;

typedef map<string,string> ParamMap;

class Comunicator {
private:
	//jedina instance komunikatoru
	static Comunicator *instance;

	//adresa ciloveho serveru
	string host;

	//prihlasovaci cookie
	static string cookie;

	//cleanup
	Cleanup cleanup;

	//request
	Easy request;

	//parser JSON dat
	Json::Reader decoder;

	//premosteni konstruktoru
	Comunicator();
public:
	static Comunicator* getInstance();

	Comunicator setUrl(string url);

	Json::Value login(string username, string password, int &isOk);

	Json::Value sendJsonRequest(string object, string method, string id, string &status, int &statusCode, ParamMap params);
};

void writeStatus(string status, int statusCode);

#endif /* COMUNICATOR_H_ */
