如何扩展CKAN API?

Kap*_*cko 4 python ckan

我想问一下如何通过为CKAN编写自己的扩展来扩展CKAN的API.我在文档中找不到任何内容.你能举个简单的例子吗?

kni*_*irr 8

在OP的辩护中,文档看起来确实有点不透明.我一直在寻找这个,试图获得一个自定义的API动作来提供工作的JSON新闻源,最后想出了这个:

import ckan.plugins as plugins
import ckan.plugins.toolkit as toolkit

# Required so that GET requests work
@toolkit.side_effect_free
def get_news(context,data_dict=None):
  # The actual custom API method
  return {"hello":"world"}


class CustomAPIPlugin(plugins.SingletonPlugin):
  plugins.implements(plugins.interfaces.IActions)

  def get_actions(self):
    # Registers the custom API method defined above
    return {'get_news': get_news}
Run Code Online (Sandbox Code Playgroud)

描述创建身份验证插件的教程如下:

http://docs.ckan.org/en/latest/extensions/tutorial.html#creating-a-new-extension

我所做的是抄袭,但使用IActions而不是IAuthFunctions:

http://docs.ckan.org/en/latest/extensions/plugin-interfaces.html

它正在安装CKAN 2.2.1.