#!/usr/bin/python

# EVRYTHNG API Python Wrapper v0.92 - Vlad Trifa
# Engine 1.17

# Import all basic libs needed
import simplejson as json
import httplib, urllib
import csv
import logging

# Import some tools to measure execution time
import time
import corestats


# Set to 1 to force HTTPS 
SECURE=1

# Which API Endpoint
hostname="api.evrythng.com"

# The Various API Keys
apiKey="YOUR_OPERATOR_KEY_HERE"
appId="YOUR_APP_ID"
userId="YOUR_USER_ID"

inApp=0
logLevel=0


# FIXME: add other log levels here - 0 is debug, 1 is info, 2 is warning, 3 is errors
def setLogLevel(level):
	global logLevel
	if level:
		logging.basicConfig(level=logging.INFO,
    		format='%(levelname)-8s: %(message)s'
    		)
		logging.info("Simple Log mode")
	else:
		logging.basicConfig(level=logging.DEBUG,
    		format='%(asctime)s %(levelname)-8s %(filename)s:%(lineno)-4d: %(message)s',
    		datefmt='%m-%d %H:%M',
    		)	
		logging.info("Full log mode")
	logLevel=level
	

### This is to setup the environments / app / user contexts

def setDomain(domain):
	global hostname 
	hostname = domain
	logging.info("API Endpoint: " + hostname)

def setOperator(key):
	global apiKey 
	apiKey = key
	logging.info("Scope: OPERATOR key: " + apiKey)
	headProducts()
	# FIXME: add testing right here if works, otherwise return error

def setApp(key,id):
	global apiKey,appId 
	apiKey = key