LetGo API php 客户端

1.0.3 2018-02-07 22:00 UTC

This package is not auto-updated.

Last update: 2024-09-23 07:59:15 UTC


README

这是一个用于与 Guzzele v5.3.0(因为 php 5.4)一起使用以使用 LetGo REST API 的包。因此,请自行使用。

注意:它使用 open_ssl 生成随机字节

安装

composer require med-ezzairi/letgo "1.0.*"

配置

$config=array(
	//this is for dev
	'API_URL'	=>'https://providers.stg.letgo.com',
	//API key provided by letgo.com
	'API_KEY'	=>'your_api_key',
	//api secret is also provided by them
	'API_SECRET'=>'your_api_secret',
	//to avoid ssl host verificatio
	'verify'	=>false,
	//connection timeout
	'timeout'	=>10.0,
);

实例

//We are using psr-4 autoloading
use LetGo\LetGo;
$letgo=new LetGo($config);

身份验证

/**
* letgo API uses a JWT Bearer which expires in 20 minutes
* so, the $letgo object will check every call, 
* if the token have been expired it will renew it auto
* 
*/
$token=$letgo->getToken();

生成一个 GUID v4

/**
* letgo API requires guid v4 for each ressource your creating
* so, I added a function to let you get a random guid v4
* it uses open_ssl, please check the code if you need deep details
* 
*/
$guid=$letgo->getGuid();

获取所有汽车属性

/**
* I work for v12software.com, which is a Dealership Management System 
* So, posting cars on letgo requires to specify makeId & modelId
* for each car, and those are guids, you can get them easily
* 
*/

$carsAttribs=$letgo->getCarsAttributes();

var_dump($carsAttribs);

用户

创建

//generate a guid for our user
$genGuid=$letgo->getGuid();

$userData=array(
	"userId"	=> $genGuid,
	"name"		=> "User Name",
	"email"		=> "user@email.com",
	"password"	=> "VeryScurePassword",
	"countryCode"=> "US",
	"address"	=> "Here is my address",
	"city"		=> "City",
	"zip"		=> "96058",
);
$data=$letgo->User->create($userData);

var_dump($genGuid,$data);

更新

$userData=array(
	"name"		=> "User Name",
	"email"		=> "user@email.com",
	"countryCode"=> "US",
	"address"	=> "Here is my address",
	"city"		=> "City",
	"zip"		=> "74065",
);
$data=$letgo->User->update($userID,$userData);

var_dump($data);

获取

//to retreive user's information
$data=$letgo->User->get($userID);

var_dump($data);

列出所有用户

//to retreive all users created by your application
$data=$letgo->User->all();

var_dump($data);

汽车

目前我在汽车创建上遇到了问题,请稍等,问题解决后我将发布该包的其余文档。

exit(1);