       return cb(null, data) if data
       return @_api path, option, cb
 
+  # Generates cache key
+  #
+  # @param {String} path
+  # @param {Object} option
   key: (path, option)->
     "#{path}?#{Query.stringify option}"
 
+  # Moshimo API request and stores to cache
+  #
+  # @param {String} path
+  # @param {Object} option
+  # @param {Function} cb
   _api: (path, option, cb)->
     params = merge {}, option,
       authorization_code: config.moshimo.token

{ merge } = require 'app/lib/util'
host = config.moshimo.host

module.exports =
  categories: (opts, cb)->
    q = { article_category_code: opts.category }
    @api '/category/list2', q, (err, data)->
      cb err, data.CategoryList2

  api: (path, option, cb)->
    # try to get cache
    cache.get @key(path, option), (err, json)=>

#
# Module dependencies
#
http = require 'http'
URL = require 'url'
Query = require 'querystring'
