imsamurai/http-source 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

imsamurai/http-source

Composer 安装命令:

composer require imsamurai/http-source

包简介

Provides base class for datasorses with Http protocol

README 文档

README

Build Status Coverage Status Latest Stable Version Total Downloads Latest Unstable Version License

Plugin with HttpSource to provide base class for datasorses with Http protocol. Based on ProLoser implementation. I make some refactoring to make HttpSource more similar to DboSource and removed OAuth component, because i think for login better use Opauth.

For existing plugins check ProLoser readme. But they will not work with HttpSource. I will adapt these plugins later.

Notes

HttpSource is an abstract class and must be extended by the Api you wish to support. Open a bug ticket if you'd like some help making your own or just want me to do it. It's very easy to add new ones - check out the list

Installation

Step 1: Clone or download to Plugin/HttpSource

cd my_cake_app/app
git clone git://github.com/imsamurai/cakephp-httpsource-datasource.git Plugin/HttpSource

or if you use git add as submodule:

cd my_cake_app
git submodule add "git://github.com/imsamurai/cakephp-httpsource-datasource.git" "app/Plugin/HttpSource"

then update submodules:

git submodule init
git submodule update

Step 2: Add your configuration to database.php and set it to the model

:: database.php ::
var $myapi = array(
	'datasource' => 'MyPlugin.Http/MyPlugin', // Example: 'Github.Http/Github'
        'host' => 'api.myplugin.com/v1',
        'port' => 80,
        'persistent' => false,
		'auth' => array(
			'name' => 'oauth',
			'version' => '1.0', //version 2 not tested, maybe don't work
			'oauth_consumer_key' => '--Your API Key--',
			'oauth_consumer_secret' => '--Your API Secret--'
		),
        //all other parameters that passed to config of http socket
        //...
);
:: MyModel.php ::
public $useDbConfig = 'myapi';
public $useTable = 'myapi_table';

Step 3: Load main plugin and your plugin

:: bootstrap.php ::
CakePlugin::load('HttpSource', array('bootstrap' => true, 'routes' => true));
CakePlugin::load('MyPlugin');

Step 4: Querying the API

Best to just give an example. I switch the datasource on the fly because the model is actually a projects table in the DB. I tend to query from my API and then switch to default and save the results.

App::uses('HttpSourceModel', 'HttpSource.Model');

class Project extends HttpSourceModel {
	function findAuthedUserRepos() {
		$this->setDataSource('github');
		$projects = $this->find('all', array(
                        //used as repo name if useTable is empty, otherwise used as standart fields parameter
			'fields' => 'repos'
		));
		$this->setDataSource('default'); // if more queries are done later
		return $projects;
	}
}

Configuration

See wiki.

统计信息

  • 总下载量: 1.52k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 4
  • 依赖项目数: 4
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 3
  • Forks: 22
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-02-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固