davalb/php-openbazaar-api

该软件包最新版本(0.4)没有可用的许可信息。

OpenBazaar API 使开发者能够轻松与 OpenBazaar 市场通信

0.4 2016-05-15 15:07 UTC

This package is not auto-updated.

Last update: 2024-09-23 12:15:39 UTC


README

这个库是 PHP 5.x 的 OpenBazaar REST API 文档 POST 调用的实现,OpenBazaar REST API 文档 GET 调用。OpenBazaar API 是一个基于 REST 的接口。通过使用这个库,你不必担心与 API 通信:所有困难的工作都已经完成。

这个 API 是建立在巨人肩膀上的:Guzzle 5.0。这是一个绝对优秀的库。

安装

首先 安装 composer。然后执行

$ composer require davalb/php-openbazaar-api

需求

PHP >=5.4.0

使用

创建一个新实例非常简单

<?php
$service = OpenBazaar\ClientFactory::factory([
		'base_url' => 'http://your_ip_or_domain_here:18469/',
	]
);
$response = $service->login([
	'username' => 'your_username_here',
	'password' => 'your_password_here',
]);
// get Profile will return your profile info
$result = $service->getProfile();
// get Listings for the store with the given guid
$result = $service->getListings([
	'guid' => 'a06aa22a38f0e62221ab74464c311bd88305f88c'
]);
// follow another page
$result = $service->follow(
	['guid' => 'a06aa22a38f0e62221ab74464c311bd88305f88c']
);
// change your username
$result = $service->changeProfile(
	['name' => 'New Name']
);
// set social account
$result = $service->createSocialAccount([
    'account_type' => 'twitter',
    'username' => 'user',
]);

// upload an image
$imageurl = "https://placekitten.com/200/300";
$imagedata = file_get_contents($imageurl);
$base64 = base64_encode($imagedata);
$image = [
	'image' => $base64
];
$imageResult = $this->service->uploadImage($image);

// create a new contract (i.e. a new product offering)
$contract = [
	'expiration_date' => '',
	'metadata_category' => 'physical good',
	'title' => 'Product Title',
	'currency_code' => 'EUR',
	'description' => 'A Description about the product',
	'price' => '9.90',
	'process_time' => '1',
	'nsfw' => 'false',
	'terms_conditions' => '',
	'shipping_origin' => 'GERMANY',
	'ships_to' => 'ALL',
	'est_delivery_domestic' => '2 Business Days',
	'est_delivery_international' => '7-21 Business Days',
	'returns' => '',
	'shipping_currency_code' => 'EUR',
	'shipping_domestic' => 6,
	'shipping_international' => 12,
	'keywords' => 'vinyl',
	'category' => '',
	'condition' => 'New',
	'sku' => '',
	'free_shipping' => 'false',
	'images' => $imageResult['image_hashes'][0],
	'moderators' => 'e85ac56a60d01fa5ad20b3194bfc1c593db17cba',
	'contract_id' => '',
];
$result = $this->service->createContract($contract);
?>

首先需要运行登录。之后,你可以运行更多的 API 调用,无需担心身份验证,因为 cookie 已经保存。

更多信息与插件

有关 Guzzle 及其插件的更多信息,请查看 文档

贡献

实现了缺失的调用?欢迎 PR!项目遵循 cakephp 编码标准。请在发送 pull request 之前安装并使用 php 代码检查器

phpcs --standard=cakephp php-openbazaar-api/

另外,请为所编写的代码提供测试。可以像这样运行测试

bin/phpunit davalb/php-openbazaar-api/tests/