# -*- coding: utf-8 -*-
"""

SQLpie License (MIT License)
Copyright (c) 2011-2016 André Lessa, http://sqlpie.com
See LICENSE file.

"""

import os, sys
sys.path.append(os.getcwd())
import sqlpie
import codecs

header = u"""==============================================================
SQLpie License (MIT License)
Copyright (c) 2011-2016 André Lessa, http://sqlpie.com
See LICENSE file.
==============================================================

[this file was auto-generated by `scripts/update_docs.py`]
"""

section_delimiter = u"\n#\n# API ENDPOINT\n#\n\n"

def update_doc(params):
    services = params["services"]
    target_doc = params["target_doc_file"]

    section_header = u"\n== %s\n" % target_doc.split("-")[1].upper()

    writer = codecs.open("docs/%s.txt" % target_doc, "w", encoding="utf-8")
    writer.write(header)
    writer.write(section_header)
    o = sqlpie.sqlpie_client.SQLpieClient("localhost")
    for s in services:
        method = s.replace("/","_")
        contents = getattr(o,method).__doc__
        writer.write(section_delimiter)
        writer.write(contents)
    writer.close()

update_doc({"services":["ping","stats"], \
    "target_doc_file":"05a. API Endpoints - Health Checks"})
update_doc({"services":["document_put","document_get","document_remove","document_reset"], \
    "target_doc_file":"05b. API Endpoints - Documents"})
update_doc({"services":["observation_put","observation_get","observation_remove","observation_reset"], \
    "target_doc_file":"05c. API Endpoints - Observations"})
update_doc({"services":["service_index","service_search"], \
    "target_doc_file":"05d. API Endpoints - Search Service"})
update_doc({"services":["service_matching"], \
    "target_doc_file":"05e. API Endpoints - Document Matching Service"})
update_doc({"services":["service_classifier","service_classifier_train","service_classifier_clear",\
    "service_classifier_reset","service_classifier_predict","service_classifier_predictions"],\
    "target_doc_file":"05f. API Endpoints - Classification Service"})
update_doc({"services":["service_recommend","service_similarity"], \
    "target_doc_file":"05g. API Endpoints - Collaborative Filtering Service"})
update_doc({"services":["service_summarization"], \
    "target_doc_file":"05h. API Endpoints - Summarization Service"})
update_doc({"services":["caching_initialize","caching_add","caching_put", "caching_get", "caching_remove", \
    "caching_flush","caching_reset","caching_destroy"], \
    "target_doc_file":"05i. API Endpoints - Caching Service"})

print "The API Endpoint documentation has been updated in the /docs directory."
print "The contents came from the docstrings found in the `sqlpie/clients/python/sqlpie_client.py` file.\n"


