rasclatt / soundconcepts
SoundConcepts API 的类库
1.0.6
2023-03-06 01:21 UTC
Requires
- php: >=5.6.0
- rasclatt/nubersoft: *
README
这是一个处理 SoundConcepts API 请求的小型库。它目前处于开发阶段,因此请自行承担风险!实际上并没有多少风险,它只是还没有完全构建出来。
此类库确实需要 Nubersoft 类库(rasclatt/nubersoft),但不需要其他任何类库。如果需要,您可以安装 src
作为 SoundConcepts
,以便类库在您的自动加载器中正确解析命名空间。同样,这也适用于 nubersoft 类库。
示例 1) 创建新用户
<?php
use SoundConcepts\User\Controller as SoundConcepts;
# These would be provide by SoundConcepts
$username = 'whateverusername';
$password = 'whateverpassword';
$subdomain = 'companysubdomain';
# Create instance, user your provided user, pass, and subdomain
$SoundConcepts = new SoundConcepts($username, $password, $subdomain);
# Create required attributes (more are available, reffer to API Docs)
$data['distributor_id'] = '123';
$data['email'] = 'test@example.com';
$data['password'] = 'pas857#@!#$sword';
$data['username'] = 'myusername';
$data['first_name'] = 'Jane';
$data['last_name'] = 'Doe';
$data['country'] = 'US';
# Create User
$success = $SoundConcepts->createUser($data);
if($success == 1) {
echo "User created!";
}
else {
echo "Something went wrong...";
}
示例 2) 删除用户
$success = $SoundConcepts->deleteUser($distributor_id);
示例 3) 多个 SoundConcepts 实例
<?php
use SoundConcepts\User\Controller as User;
use SoundConcepts\Credits\Controller as Credits;
# Create User instance
$User = new User(SC_USERNAME, SC_PASSWORD, SC_SUBDOMAIN);
# If you create a different instance of a SoundConcepts object,
# you don't need to add $username, $password, $subdomain
$Credits = new Credits();
示例 4) 信用概述
<?php
use SoundConcepts\Credits\Controller as Credits;
# Asset id for the sample program
$asset_id = 123;
# Credit Quantity
$qty = 1;
# Description (not required)
$description = 'Added for advancing to new rank';
# Set Id
$distributor_id = 1234;
# Create instance
$Credits = new Credits(SC_USERNAME, SC_PASSWORD, SC_SUBDOMAIN);
# Add some credits to an asset id
# The last parameter is for expiration date. See manual for format
$Credits->addCredits($distributor_id, $asset_id, $qty, $description);
# Fetch the user summary
$summary = $Credits->getCreditSummary($distributor_id);
# Output the array
print_r($summary);
全局凭证
确保您的凭证始终加载的一种简单方法,您无需在类实例化时重复添加凭证。您可以创建一个扩展 API/Model
的观察者,并在页面加载时初始化它。在 WordPress 实现(WordPress)中,这可能是一个在 init
钩子内部加载的函数。
<?php
class MyObserver extends \SoundConcepts\API\Model
{
public function __construct()
{
# Set your credentials
$username = 'myprovidedusername';
$password = 'myprovidedpassword';
$subdomain = 'myprovideddomain';
# Create a parent construct
return parent::__construct($username, $password, $subdomain);
}
}
在 WordPress 中,您可以在函数中这样做:
function start_soundconcepts()
{
new MyObserver();
}
add_action('init', 'start_soundconcepts');